Skip to content

Commit

Permalink
fix: broken unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkparti committed Oct 11, 2023
1 parent c59923c commit 40ea9ad
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
20 changes: 13 additions & 7 deletions server/models/Trust.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,13 @@ describe('Trust Model', () => {
walletId: walletId3,
});
expect(getTrustRelationshipsStub).calledThrice;
expect(getAllWalletStub).calledOnceWithExactly(walletId1);
expect(getAllWalletStub).calledOnceWithExactly(
walletId1,
undefined,
undefined,
'created_at',
'desc',
);
});

it('updateTrustState', async () => {
Expand Down Expand Up @@ -913,7 +919,7 @@ describe('Trust Model', () => {

describe('getTrustRelationshipById', () => {
const walletId = uuid();
const trustRelationshipId = uuid()
const trustRelationshipId = uuid();
const filter = {
and: [
{
Expand All @@ -933,12 +939,12 @@ describe('Trust Model', () => {
trustRepositoryStub.getByFilter.resolves(['trustRelationship']);
const result = await trustModel.getTrustRelationshipById({
walletId,
trustRelationshipId
trustRelationshipId,
});
expect(result).eql('trustRelationship');
expect(trustRepositoryStub.getByFilter).calledOnceWithExactly(
{...filter}
);
expect(trustRepositoryStub.getByFilter).calledOnceWithExactly({
...filter,
});
});
})
});
});
8 changes: 4 additions & 4 deletions server/services/TokenService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ describe('Token', () => {
'walletLoginId',
undefined,
undefined,
false,
false,
'created_at',
'desc',
),
).eql(true);
});
Expand All @@ -223,8 +223,8 @@ describe('Token', () => {
'walletLoginId',
undefined,
undefined,
false,
false,
'created_at',
'desc',
),
).eql(true);
});
Expand Down
52 changes: 31 additions & 21 deletions server/services/TrustService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ describe('TrustService', () => {
.resolves(['trustRelationships']);

const getWalletStub = sinon
.stub(WalletService.prototype, 'getWallet')
.resolves({id: 'walletId'})
.stub(WalletService.prototype, 'getWallet')
.resolves({ id: 'walletId' });

const trustRelationship = await trustService.getTrustRelationships({
walletId: 'walletId',
state: 'state',
type: 'type',
request_type: 'request_type',
limit: 1,
offset: 0
offset: 0,
});

expect(trustRelationship).eql(['trustRelationships']);
expect(getWalletStub.calledOnceWithExactly({
expect(
getWalletStub.calledOnceWithExactly({
walletId: 'walletId',
}))
}),
);
expect(
getTrustRelationshipsStub.calledOnceWithExactly({
walletId: 'walletId',
Expand Down Expand Up @@ -145,7 +147,15 @@ describe('TrustService', () => {
{ id: 'trustId5' },
{ id: 'trustId6' },
]);
expect(getAllWalletsStub.calledOnceWithExactly('walletId')).eql(true);
expect(
getAllWalletsStub.calledOnceWithExactly(
'walletId',
undefined,
undefined,
'created_at',
'desc',
),
).eql(true);
expect(
getTrustRelationshipsStub.getCall(0).calledWithExactly({
walletId: 'id1',
Expand Down Expand Up @@ -228,21 +238,21 @@ describe('TrustService', () => {
});

describe('trustRelationshipGetById', async () => {
const trustRelationshipGetByIdStub = sinon
.stub(Trust.prototype, 'trustRelationshipGetById')
.resolves('trustRelationship');
const trustRelationshipGetByIdStub = sinon
.stub(Trust.prototype, 'trustRelationshipGetById')
.resolves('trustRelationship');

const trustRelationship = await trustService.trustRelationshipGetById({
walletId: 'walletId',
trustRelationshipId: 'id'
});
const trustRelationship = await trustService.trustRelationshipGetById({
walletId: 'walletId',
trustRelationshipId: 'id',
});

expect(trustRelationship).eql('trustRelationship');
expect(
trustRelationshipGetByIdStub.calledOnceWithExactly({
walletId: 'walletId',
trustRelationshipId: 'id'
}),
).eql(true);
})
expect(trustRelationship).eql('trustRelationship');
expect(
trustRelationshipGetByIdStub.calledOnceWithExactly({
walletId: 'walletId',
trustRelationshipId: 'id',
}),
).eql(true);
});
});

0 comments on commit 40ea9ad

Please sign in to comment.