Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samwel141 committed Jul 22, 2024
1 parent 2cf1009 commit 82bfd74
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion server/handlers/walletHandler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ describe('walletRouter', () => {
const res = await request(app).get(
`/wallets/${walletId}/trust_relationships?state=${TrustRelationshipEnums.ENTITY_TRUST_STATE_TYPE.requested}`,
);
const managedWallets = [];
expect(res).property('statusCode').eq(200);
expect(res.body.trust_relationships).lengthOf(1);
expect(res.body.total).eql(1);
expect(res.body.trust_relationships[0].id).eql(trustRelationshipId);
expect(
getTrustRelationshipsStub.calledOnceWithExactly(authenticatedWalletId, {
getTrustRelationshipsStub.calledOnceWithExactly(authenticatedWalletId, managedWallets, {
walletId,
state: TrustRelationshipEnums.ENTITY_TRUST_STATE_TYPE.requested,
type: undefined,
Expand Down
25 changes: 20 additions & 5 deletions server/models/Trust.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,32 @@ describe('Trust Model', () => {

describe('getTrustRelationships', () => {
const walletId = uuid();
const managedWallets = [{id: '90f8b2ab-c101-405d-922a-0a64dbe64ab6'}];
const managedWalletIds = managedWallets.map(wallet => wallet.id);
const orConditions = [
{ actor_wallet_id: walletId },
{ target_wallet_id: walletId },
{ originator_wallet_id: walletId },
];

managedWalletIds.forEach((managedWalletId) => {
orConditions.push({ actor_wallet_id: managedWalletId });
orConditions.push({ target_wallet_id: managedWalletId });
orConditions.push({ originator_wallet_id: managedWalletId });
});
const filter = {
and: [
{
or: [
{ actor_wallet_id: walletId },
{ target_wallet_id: walletId },
{ originator_wallet_id: walletId },
],
or: orConditions,
},
],
};

it('should get relationships', async () => {
trustRepositoryStub.getByFilter.resolves(['relationship1']);

const result = await trustModel.getTrustRelationships({
managedWallets,
walletId,
limit: 10,
offset: 1,
Expand All @@ -59,6 +70,7 @@ describe('Trust Model', () => {
trustRepositoryStub.getByFilter.resolves(['relationship2']);
const result = await trustModel.getTrustRelationships({
walletId,
managedWallets,
limit: 10,
offset: 1,
state: 'state',
Expand All @@ -81,6 +93,7 @@ describe('Trust Model', () => {
trustRepositoryStub.getByFilter.resolves(['relationship3']);
const result = await trustModel.getTrustRelationships({
walletId,
managedWallets,
limit: 10,
offset: 11,
type: 'type',
Expand All @@ -103,6 +116,7 @@ describe('Trust Model', () => {
trustRepositoryStub.getByFilter.resolves(['relationship4']);
const result = await trustModel.getTrustRelationships({
walletId,
managedWallets,
limit: 101,
offset: 1,
request_type: 'request_type',
Expand All @@ -125,6 +139,7 @@ describe('Trust Model', () => {
trustRepositoryStub.getByFilter.resolves(['relationship1']);
const result = await trustModel.getTrustRelationships({
walletId,
managedWallets,
limit: 100,
offset: 0,
state: 'state',
Expand Down
4 changes: 2 additions & 2 deletions server/services/TrustService.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class TrustService {
);

const alltrustRelationships = [];

const managedWallets = [];
await Promise.all(
wallets.map(async (w) => {
const trustRelationships = await this.getTrustRelationships(walletId, {
const trustRelationships = await this.getTrustRelationships(walletId, managedWallets,{
walletId: w.id,
state,
type,
Expand Down
3 changes: 3 additions & 0 deletions server/services/TrustService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('TrustService', () => {
const getTrustRelationshipsStub = sinon
.stub(Trust.prototype, 'getTrustRelationships')
.resolves(['trustRelationships']);
const managedWallets = [{id: '90f8b2ab-c101-405d-922a-0a64dbe64ab6'}];

const getTrustRelationshipsCountStub = sinon
.stub(Trust.prototype, 'getTrustRelationshipsCount')
Expand All @@ -40,6 +41,7 @@ describe('TrustService', () => {

const trustRelationship = await trustService.getTrustRelationships(
authenticatedWalletId,
managedWallets,
{
walletId: 'walletId',
state: 'state',
Expand All @@ -62,6 +64,7 @@ describe('TrustService', () => {
expect(
getTrustRelationshipsStub.calledOnceWithExactly({
walletId: 'walletId',
managedWallets,
state: 'state',
type: 'type',
request_type: 'request_type',
Expand Down

0 comments on commit 82bfd74

Please sign in to comment.