Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
updates tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Griffin <[email protected]>
  • Loading branch information
m00sey committed Oct 3, 2023
1 parent 1701349 commit f954b9f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 44 deletions.
48 changes: 19 additions & 29 deletions src/operations.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
import { SignifyClient, Dict } from 'signify-ts';
import { SignifyClient } from 'signify-ts';

const DONE = 'done';
const NAME = 'name';
const RESPONSE = 'response';

export const getAgentOperationResult = async (
client: SignifyClient,
op: any,
log: boolean = false,
time: number = 1000
) => {
const ops = client.operations();
while (!op[DONE]) {
op = await ops.get(op[NAME]);
if (log) {
console.log(op);
export interface OperationsArgs {
client: SignifyClient;
op: any;
time?: number;
}

namespace operations {
export async function getResult({
client,
op,
time = 1000,
}: OperationsArgs) {
while (!op[DONE]) {
op = await client.operations().get(op[NAME]);
await new Promise((resolve) => setTimeout(resolve, time));
}
await new Promise((resolve) => setTimeout(resolve, time));
return op[RESPONSE];
}
return op[RESPONSE];
};
}

export const sendAgentMessage = async (
client: SignifyClient,
name: string,
topic: string,
sender: Dict<any>,
route: string,
payload: Dict<any>,
embeds: Dict<any>,
recipients: string[]
) => {
return await client
.exchanges()
.send(name, topic, sender, route, payload, embeds, recipients);
};
export { operations };
30 changes: 16 additions & 14 deletions src/qvi/qvi.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { SignifyClient, Siger, messagize, d } from 'signify-ts';
import { getAgentOperationResult, sendAgentMessage } from '../operations';
import { Schema } from '../schema';
import { Rules } from '../rules';
import { LEvLEICredentialData, LEvLEICredentialEdge } from './credentials/le';
import { ECRAuthvLEIEdgeData, ECRvLEICredentialData } from './credentials/ecr';
import { OORvLEICredentialData } from './credentials/oor';
import { OORAuthvLEICredentialData } from '../le/credentials/oor-auth';
import { AID } from '..';
import { operations } from '../operations';

type qb64 = string;

Expand Down Expand Up @@ -42,7 +42,7 @@ export class QVI {
*
* @param {AID} issuee
* @param {LEvLEICredentialData} data
* @param {LEvLEICredentialEdge} edge}
* @param {LEvLEICredentialEdge} edge
* @returns
*/
public async createLegalEntityCredential(
Expand Down Expand Up @@ -95,7 +95,7 @@ export class QVI {
* Create Official Organizational Role Credential
*
* @param {AID} issuee
* @param {OORvLEICredentialData}data``
* @param {OORvLEICredentialData} data
* @param {OORAuthvLEICredentialData} edge
* @returns
*/
Expand Down Expand Up @@ -125,7 +125,7 @@ export class QVI {
credential?: any //result for createLegalEntityCredential
) {
let sender = await this.client.identifiers().get('');
sender = await getAgentOperationResult(this.client, sender);
sender = await operations.getResult({client: this.client, op: sender});

if (getFromAgent) {
let msgSaid = '';
Expand Down Expand Up @@ -157,16 +157,18 @@ export class QVI {
let embeds = {
cred: [serder, atc],
};
return await sendAgentMessage(
this.client,
alias,
'multisig_issuance',
sender,
'/multisig/iss',
{}, //TODO:payload
embeds,
[recipient]
);

return await this.client
.exchanges()
.send(
alias,
'multisig_issuance',
sender,
'/multisig/iss',
{},
embeds,
[recipient]
);
}
}

Expand Down
37 changes: 37 additions & 0 deletions test/operations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { SignifyClient, Credentials, Operations } from 'signify-ts';
import { describe, expect, it } from '@jest/globals';
import { instance, mock, when } from 'ts-mockito';
import { operations } from '../src/operations';

describe('operations', () => {
it('should complete', async () => {
let mockedClient: SignifyClient = mock(SignifyClient);

let c: Credentials = mock(Credentials);
when(mockedClient.credentials()).thenReturn(instance(c));

let client = instance(mockedClient);

let op = { done: true, name: 'my_op', response: 'yay'};

let resp = await operations.getResult({client: client, op: op});
expect(resp).toEqual('yay');
});

it('should retry', async () => {
let mockedClient: SignifyClient = mock(SignifyClient);

let c: Credentials = mock(Credentials);
when(mockedClient.credentials()).thenReturn(instance(c));

let mockedOps: Operations = mock(Operations);
when(mockedOps.get('my_op')).thenResolve({done: true, name: 'my_op', response: 'yay'});
when(mockedClient.operations()).thenReturn(instance(mockedOps));

let client = instance(mockedClient);

let op = { done: false, name: 'my_op' };
let resp = await operations.getResult({ client: client, op: op });
expect(resp).toEqual('yay');
});
});
6 changes: 5 additions & 1 deletion test/qvi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ describe('a qvi', () => {

let client = instance(mockedClient);
let qvi = new QVI(client, 'qvi_name', 'qvi_registry_aid');
let data = new LEvLEICredentialData({LEI: 'an LEI', issuee: 'issuee', timestamp: 'timestamp'});
let data = new LEvLEICredentialData({
LEI: 'an LEI',
issuee: 'issuee',
timestamp: 'timestamp',
});
let edge = new LEvLEICredentialEdge('qvi_aid');

qvi.createLegalEntityCredential('issuee aid', data, edge);
Expand Down

0 comments on commit f954b9f

Please sign in to comment.