Skip to content

Added new test cases#813

Merged
DanaSunal merged 18 commits into
openBackhaul:developfrom
at00825957:AmanTyagi/issue648
Sep 8, 2023
Merged

Added new test cases#813
DanaSunal merged 18 commits into
openBackhaul:developfrom
at00825957:AmanTyagi/issue648

Conversation

@at00825957
Copy link
Copy Markdown
Contributor

Fixes #648

Reviewer @DanaSunal

@DanaSunal DanaSunal self-assigned this Jul 12, 2023
Copy link
Copy Markdown
Contributor

@DanaSunal DanaSunal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments apply to all three test files.

},
{
forwardingName: 'ServiceRequestCausesLtpUpdateRequest',
attributeList: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you put expect only in catch block and no error is caught, the test will again test nothing.

@DanaSunal
Copy link
Copy Markdown
Contributor

Please go through existing comments, a lot of them were not addressed yet.

@at00825957
Copy link
Copy Markdown
Contributor Author

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 () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)=> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue I wrote above is still present.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue I wrote above is still present.

})
});

test("automateForwardingConstructWithoutInputAsync - if ForwardingConstructForTheForwardingNameAsync returns undefined when FC Port is subscription", async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as "automateForwardingConstructWithoutInputAsync - if ForwardingConstructForTheForwardingNameAsync returns undefined".

})
});

test("automateForwardingConstructAsync - if LogicalTerminationPointListAsync returns undefined", async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails. Please run the tests before pushing the code.

})
});

test("automateForwardingConstructAsync - if LogicalTerminationPointListAsync returns undefined when FC Port is subscription", async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test also fails.

'1.3.1', 'Unknown value');

return res.then()
.catch((err)=> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue I wrote above is still present.


const res = await ForwardingConstructConfigurationServices.configureForwardingConstructAsync(
operationServerName, forwardingConfigurationInputList);
expect(res).toBeInstanceOf(ForwardingConstructConfigurationStatus);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instanceof is not enough. You should expect exact values.

@@ -0,0 +1,241 @@
const ForwardingConstructConfigurationServices = require('./ForwardingConstructConfigurationServices');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleteFcPortAsync is still not being tested at all.

'1.3.1', 'Unknown value');

return res.then()
.catch((err)=> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue I wrote above is still present.


const res = ForwardingConstructConfigurationServices.configureForwardingConstructAsync(
operationServerName, forwardingConfigurationInputList);
return res.then()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleteFcPortAsync is still not being tested at all.

afterEach(() => {
jest.resetAllMocks();
});
}); No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')",
);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DanaSunal DanaSunal merged commit dc79692 into openBackhaul:develop Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for this project

2 participants