Skip to content

Commit

Permalink
feat: add tests for wallet service
Browse files Browse the repository at this point in the history
  • Loading branch information
OlhaD committed Jul 7, 2023
1 parent d2543a2 commit 932005d
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions server/services/WalletService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ describe('WalletService', () => {
const allWallets = await walletService.getAllWallets(
id,
limitOptions,
'',
false,
);

expect(getAllWalletsStub.calledOnceWithExactly(id, limitOptions)).eql(
true,
);
Expand All @@ -232,10 +234,14 @@ describe('WalletService', () => {
);
countTokenByWalletStub.onFirstCall().resolves(2);
countTokenByWalletStub.onSecondCall().resolves(4);
const allWallets = await walletService.getAllWallets(id, {
limit: 10,
offet: 0,
});
const allWallets = await walletService.getAllWallets(
id,
{
limit: 10,
offet: 0,
},
'',
);
expect(countTokenByWalletStub.calledTwice).eql(true);
expect(
countTokenByWalletStub.getCall(0).calledWithExactly(walletId1),
Expand All @@ -257,4 +263,51 @@ describe('WalletService', () => {
]);
});
});

describe('getAllWalletsCount', () => {
const walletId1 = uuid.v4();
const walletId2 = uuid.v4();
let getAllWalletsCountStub;

const result = [
{
id: walletId1,
name: 'walletName',
},
{
id: walletId2,
name: 'walletName2',
},
];

beforeEach(() => {
getAllWalletsCountStub = sinon
.stub(WalletService.prototype, 'getAllWalletsCount')
.resolves(result);
});

it('sending an id as a parameter', async () => {
expect(walletService).instanceOf(WalletService);

const allWallets = await walletService.getAllWalletsCount(walletId1);

expect(getAllWalletsCountStub.calledOnceWithExactly(walletId1)).eql(true);
expect(allWallets).eql(result);
});

it('sending an id and name as parameters', async () => {
const filterName = 'walletName';
expect(walletService).instanceOf(WalletService);

const allWallets = await walletService.getAllWalletsCount(
walletId1,
filterName,
);

expect(
getAllWalletsCountStub.calledOnceWithExactly(walletId1, filterName),
).eql(true);
expect(allWallets).eql(result);
});
});
});

0 comments on commit 932005d

Please sign in to comment.