diff --git a/src/operations.ts b/src/operations.ts index 5e773b1..4ab2570 100644 --- a/src/operations.ts +++ b/src/operations.ts @@ -16,14 +16,10 @@ namespace operations { op, time = 1000, }: OperationsArgs) { - console.log('pre while', op, op[DONE]); while (!op[DONE]) { - console.log('done', op, op[DONE]); op = await client.operations().get(op[NAME]); - console.log('get', op); await new Promise((resolve) => setTimeout(resolve, time)); } - console.log('poop', op); return op[RESPONSE]; } } diff --git a/src/qvi/qvi.ts b/src/qvi/qvi.ts index d600163..371c69c 100644 --- a/src/qvi/qvi.ts +++ b/src/qvi/qvi.ts @@ -125,7 +125,7 @@ export class QVI { credential?: any //result for createLegalEntityCredential ) { let sender = await this.client.identifiers().get(''); - sender = await operations.getResult(this.client, sender); + sender = await operations.getResult({client: this.client, op: sender}); if (getFromAgent) { let msgSaid = ''; diff --git a/test/operations.test.ts b/test/operations.test.ts index 3bbd158..c2a591d 100644 --- a/test/operations.test.ts +++ b/test/operations.test.ts @@ -4,33 +4,34 @@ import { instance, mock, when } from 'ts-mockito'; import { operations } from '../src/operations'; describe('operations', () => { - // it('should complete', () => { - // let mockedClient: SignifyClient = mock(SignifyClient); + it('should complete', async () => { + let mockedClient: SignifyClient = mock(SignifyClient); - // let c: Credentials = mock(Credentials); - // when(mockedClient.credentials()).thenReturn(instance(c)); + let c: Credentials = mock(Credentials); + when(mockedClient.credentials()).thenReturn(instance(c)); - // let client = instance(mockedClient); + let client = instance(mockedClient); - // let op = { done: true }; + let op = { done: true, name: 'my_op', response: 'yay'}; - // operations.getResult(client, op); - // }); + let resp = await operations.getResult({client: client, op: op}); + expect(resp).toEqual('yay'); + }); - it('should retry', () => { + 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(undefined); + 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 = operations.getResult({ client: client, op: op }); + let resp = await operations.getResult({ client: client, op: op }); expect(resp).toEqual('yay'); }); });