Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for node/getStatus function - Closes #2312 #2327

Merged
merged 4 commits into from Aug 25, 2018

Conversation

yatki
Copy link
Contributor

@yatki yatki commented Aug 22, 2018

Review checklist

@yatki yatki self-assigned this Aug 22, 2018
done();
});

it('should call modules.peers.networkHeight and call callback with result containing networkHeight = network.height', done => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like 2 separate tests for me - "call callback" and "call modules.peers.networkHeight"

});
});

it('should call callback with result containing networkHeight = null if modules.peers.networkHeight returns networkHeight as null', done => {
Copy link
Contributor

Choose a reason for hiding this comment

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

"if modules.peers.networkHeight returns networkHeight as null" condition can be extracted into describe block

);
describe('modules.loader.getNetwork', () => {
beforeEach(done => {
stubs.networkHeight = sinonSandbox
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this stub get restored after test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SargeKhan Not at the moment. I just made sure in beforeEach hooks they are being reassigned. Actually i was hoping to get a direction on this. This discussion #1417 suggests to use a _global_hooks.js file but it doesn't exist yet and I followed the structure in test/unit/modules/multisignatures.js since it's written recently by @4miners.

So please feel free to guide me here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's always better to restore spy/stubs in afterEach if they were created in a beforeEach block.

@@ -169,7 +169,7 @@ Node.prototype.shared = {
modules.peers.networkHeight({ normalized: false }, (err, networkHeight) => {
setImmediate(cb, null, {
broadhash: modules.system.getBroadhash(),
consensus: modules.peers.getLastConsensus() || null,
consensus: modules.peers.getLastConsensus(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you find the reason as to why || null was there earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SargeKhan No, actually consensus property is used here https://github.com/LiskHQ/lisk/blob/2312-unit-tests-for-node-getStatus/api/controllers/node.js#L101 in a weird way because if it's null we are converting it back to 0. So || null was totally useless in my opinion. If you think it's better to fix it in a separate issue I can create one for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was just asking. I think modules.peers.getLastConsensus() might return undefined. And it makes sense to set the default values in the controller as opposed to modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right! We don't need that check. I thought maybe on application start getLastConsensus may have undefined value.

@diego-G diego-G requested a review from MaciejBaj August 23, 2018 14:54
@MaciejBaj MaciejBaj merged commit 1c58fea into 1.2.0 Aug 25, 2018
@MaciejBaj MaciejBaj deleted the 2312-unit-tests-for-node-getStatus branch August 25, 2018 15:37
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.

None yet

5 participants