Added new test cases#813
Conversation
DanaSunal
left a comment
There was a problem hiding this comment.
Same comments apply to all three test files.
| }, | ||
| { | ||
| forwardingName: 'ServiceRequestCausesLtpUpdateRequest', | ||
| attributeList: { |
There was a problem hiding this comment.
AttributeList has 0 information, the parameter is passed from automateForwardingConstruct to eventDispatcher without any alternation, it can safely be an empty array.
| '550e8400-e29b-11d4-a716-446655440000', '1.3.1', 'Unknown value'); | ||
| return res.then(() => fail()) | ||
| .catch((err)=> { | ||
| expect(err).toEqual(mockError); |
There was a problem hiding this comment.
Also if you put expect only in catch block and no error is caught, the test will again test nothing.
|
Please go through existing comments, a lot of them were not addressed yet. |
@DanaSunal made changes for every comment already. |
| }; | ||
|
|
||
| describe("configureForwardingConstructAsync", () => { | ||
| test("automateForwardingConstructAsync - failed to get LogicalTerminationPointListAsync", async () => { |
There was a problem hiding this comment.
This test and "automateForwardingConstructAsync - failed to get LogicalTerminationPointListAsync when FC Port is subscription" are identical. It does not matter that they have different attributeList, because the mocked error is thrown before the decision "isOperationOfFcPortType" is even made.
| '1.3.1', 'Unknown value'); | ||
|
|
||
| return res.then() | ||
| .catch((err)=> { |
There was a problem hiding this comment.
This test never reaches the catch block. As I wrote before, if you put expect in catch block and the catch block is not reached, test will pass without ever reaching the expect.
There was a problem hiding this comment.
Issue I wrote above is still present.
There was a problem hiding this comment.
Issue I wrote above is still present.
| }) | ||
| }); | ||
|
|
||
| test("automateForwardingConstructWithoutInputAsync - if ForwardingConstructForTheForwardingNameAsync returns undefined when FC Port is subscription", async () => { |
There was a problem hiding this comment.
Same as "automateForwardingConstructWithoutInputAsync - if ForwardingConstructForTheForwardingNameAsync returns undefined".
| }) | ||
| }); | ||
|
|
||
| test("automateForwardingConstructAsync - if LogicalTerminationPointListAsync returns undefined", async () => { |
There was a problem hiding this comment.
This test fails. Please run the tests before pushing the code.
| }) | ||
| }); | ||
|
|
||
| test("automateForwardingConstructAsync - if LogicalTerminationPointListAsync returns undefined when FC Port is subscription", async () => { |
| '1.3.1', 'Unknown value'); | ||
|
|
||
| return res.then() | ||
| .catch((err)=> { |
There was a problem hiding this comment.
Issue I wrote above is still present.
|
|
||
| const res = await ForwardingConstructConfigurationServices.configureForwardingConstructAsync( | ||
| operationServerName, forwardingConfigurationInputList); | ||
| expect(res).toBeInstanceOf(ForwardingConstructConfigurationStatus); |
There was a problem hiding this comment.
Instanceof is not enough. You should expect exact values.
| @@ -0,0 +1,241 @@ | |||
| const ForwardingConstructConfigurationServices = require('./ForwardingConstructConfigurationServices'); | |||
There was a problem hiding this comment.
This file only tests about half of the class. The tests do not touch methods eg. updateFcPortAsync, deleteFcPortAsync, addFcPortAsync... (run jest command with '--coverage' to see details).
There was a problem hiding this comment.
deleteFcPortAsync is still not being tested at all.
| '1.3.1', 'Unknown value'); | ||
|
|
||
| return res.then() | ||
| .catch((err)=> { |
There was a problem hiding this comment.
Issue I wrote above is still present.
|
|
||
| const res = ForwardingConstructConfigurationServices.configureForwardingConstructAsync( | ||
| operationServerName, forwardingConfigurationInputList); | ||
| return res.then() |
There was a problem hiding this comment.
the '.then()' part is useless. Also although it works, this is not the way it should be tested using jest. Take a look at: https://jestjs.io/docs/expect#rejects
test('rejects to octopus', async () => { await expect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus'); });
| const res = ForwardingConstructConfigurationServices.configureForwardingConstructAsync( | ||
| operationServerName, forwardingConfigurationInputList); | ||
| return res.then(() => { | ||
| return Promise.reject(mockError); |
There was a problem hiding this comment.
Here the '.then()' part is not only useless but misleading, because you are throwing the error you are expecting, which means the test will ALWAYS pass, no matter what 'res' contains.
| jest.spyOn(HttpClientInterface, 'getReleaseNumberAsync').mockReturnValueOnce('2.0.1'); | ||
| jest.spyOn(LogicalTerminationPoint, 'getServerLtpListAsync').mockReturnValue(["ro-2-0-1-op-c-im-ol-1-0-0-003"]); | ||
| jest.spyOn(HttpClientInterface, 'getApplicationNameAsync').mockReturnValue('RegistryOffice') | ||
| jest.spyOn(HttpClientInterface, 'getReleaseNumberAsync').mockReturnValue('2.0.2'); |
There was a problem hiding this comment.
To return different values from the same mocked method use chaining: https://jestjs.io/docs/mock-function-api#mockfnmockreturnvalueoncevalue
| @@ -0,0 +1,241 @@ | |||
| const ForwardingConstructConfigurationServices = require('./ForwardingConstructConfigurationServices'); | |||
There was a problem hiding this comment.
deleteFcPortAsync is still not being tested at all.
| afterEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
| }); No newline at end of file |
There was a problem hiding this comment.
Do not push changes to this file.
| await expect(Promise.reject(new Error("Cannot read properties of undefined (reading 'fc-port')d"))).rejects.toThrow( | ||
| "Cannot read properties of undefined (reading 'fc-port')", | ||
| ); | ||
| }); |
There was a problem hiding this comment.
This test does not test absolutely anything. You could have written expect('true').toBeTruthy() and it would have the same value. Same for the "automateForwardingConstructWithoutInputAsync - if ForwardingConstructForTheForwardingNameAsync returns undefined" and others in the following file, since the "tests" are identical.
Just remove them.
Fixes #648
Reviewer @DanaSunal