Skip to content

Commit

Permalink
Unit test changes due to service logic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola Mlinaric committed Mar 26, 2020
1 parent 246842d commit def4000
Showing 1 changed file with 10 additions and 39 deletions.
49 changes: 10 additions & 39 deletions test/unit/Services/NodeBalance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,39 @@ describe("NodeBalanceService", function () {

let sandbox: SinonSandbox;
let nodeBalanceService: NodeBalanceService;
let nodeBalanceFindAllStub: SinonStub<any>;
let nodeBalanceFindOneStub: SinonStub<any>;
let nodeBalanceFindAStub: SinonStub<any>;

beforeEach(function () {
sandbox = createSandbox();
nodeBalanceService = new NodeBalanceService();
nodeBalanceFindAllStub = sinon.stub(NodeBalance, "findAll");
nodeBalanceFindOneStub = sinon.stub(NodeBalance, "findOne");
nodeBalanceFindAStub = sinon.stub(NodeBalance, "findAll");
});

afterEach(function () {
sandbox.restore();
logger.silent = false;
nodeBalanceFindAllStub.restore();
nodeBalanceFindOneStub.restore();
nodeBalanceFindAStub.restore();
});

it("should return node balance with balance changes in the last 24 hours", async () => {
nodeBalanceFindAllStub.returns([
{
"currentBalance": "8537124947501041",
"updatedAt": "2020-03-26T06:41:48.000Z",
"balanceChange": "0",
"balanceChangePerc": "0.00%"
}
]);
nodeBalanceFindAStub.returns({
"currentBalance": "8537124947501041",
"updatedAt": "2020-03-26T06:41:48.000Z",
"balanceChange": "2353252",
"balanceChangePerc": "+23.00%"
} as unknown as NodeBalance);
try {
const balances = await nodeBalanceService.fetchNodeBalance(1);

expect(balances).to.exist;
expect(balances).to.haveOwnProperty('currentBalance');
expect(balances).to.haveOwnProperty('updatedAt');
expect(balances).to.haveOwnProperty('balanceChange');
expect(balances).to.haveOwnProperty('balanceChangePerc');

} catch (err) {
logger.error(`Unexpected error occured: ${err.message}`);
expect.fail(err);
}
});

it("should return latest node balance outside the last 24 hours", async () => {
nodeBalanceFindAllStub.returns([]);
nodeBalanceFindOneStub.returns(
{
"id": 2,
"balance": "8537124947501041",
"createdAt": "2020-01-13T06:41:48.000Z",
"updatedAt": "2020-02-17T06:41:48.000Z",
"nodeId": 5
} as unknown as NodeBalance);
try {
const balances = await nodeBalanceService.fetchNodeBalance(5);

expect(balances).to.exist;
expect(balances).to.haveOwnProperty('balance');
expect(balances).to.haveOwnProperty('createdAt');
expect(balances).to.haveOwnProperty('updatedAt');
expect(balances).to.haveOwnProperty('nodeId');

} catch (err) {
logger.error(`Unexpected error occured: ${err.message}`);
expect.fail(err);
}
});
});

0 comments on commit def4000

Please sign in to comment.