Skip to content

Commit

Permalink
feat: added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkparti committed Aug 20, 2023
1 parent 2d62c4c commit 3a2c596
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
31 changes: 31 additions & 0 deletions server/handlers/trustHandler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,35 @@ describe('trustRouter', () => {
});
});
});

describe('get /trust_relationships/:id', () => {
it('missed parameters -- relationshipId must be a guid', async () => {
const res = await request(app).get(
`/trust_relationships/trustRelationshipId`,
);
expect(res).property('statusCode').eq(422);
expect(res.body.message).match(/trustRelationshipId.*GUID/);
});

it('successfully', async () => {
const trustRelationshipId = uuid.v4();

const trustRelationshipGetByIdStub = sinon
.stub(TrustService.prototype, 'trustRelationshipGetById')
.resolves({id: trustRelationshipId});

const res = await request(app).get(
`/trust_relationships/${trustRelationshipId}`,
);

expect(res).property('statusCode').eq(200);
expect(
trustRelationshipGetByIdStub.calledOnceWithExactly({
walletLoginId: authenticatedWalletId,
trustRelationshipId,
}),
).eql(true);
});

})
});
31 changes: 31 additions & 0 deletions server/models/Trust.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,4 +906,35 @@ describe('Trust Model', () => {
expect(getTrustRelationshipsTrustedStub).not.called;
});
});

describe('getTrustRelationshipById', () => {
const walletId = uuid();
const trustRelationshipId = uuid()
const filter = {
and: [
{
or: [
{ actor_wallet_id: walletId },
{ target_wallet_id: walletId },
{ originator_wallet_id: walletId },
],
},
{
'wallet_trust.id': trustRelationshipId,
},
],
};

it('should get relationship', async () => {
trustRepositoryStub.getByFilter.resolves(['trustRelationship']);
const result = await trustModel.getTrustRelationshipById({
walletId,
trustRelationshipId
});
expect(result).eql('trustRelationship');
expect(trustRepositoryStub.getByFilter).calledOnceWithExactly(
{...filter}
);
});
})
});
19 changes: 19 additions & 0 deletions server/services/TrustService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,23 @@ describe('TrustService', () => {
).eql(true);
});
});

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

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

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

0 comments on commit 3a2c596

Please sign in to comment.