|
1 | 1 | import indy from 'indy-sdk';
|
2 | 2 | import { v4 as uuid } from 'uuid';
|
3 |
| -import { IndyWallet } from '../../wallet/IndyWallet'; |
4 |
| -import { Wallet } from '../../wallet/Wallet'; |
5 |
| -import { ConnectionService } from './ConnectionService'; |
6 |
| -import { ConnectionRecord, ConnectionStorageProps } from '../../storage/ConnectionRecord'; |
7 |
| -import { AgentConfig } from '../../agent/AgentConfig'; |
8 |
| -import { ConnectionState } from './domain/ConnectionState'; |
9 |
| -import { InitConfig } from '../../types'; |
10 |
| -import { ConnectionRole } from './domain/ConnectionRole'; |
11 |
| -import { ConnectionInvitationMessage } from './messages/ConnectionInvitationMessage'; |
12 |
| -import { Repository } from '../../storage/Repository'; |
13 |
| -import { Connection } from './domain/Connection'; |
14 |
| -import { signData, unpackAndVerifySignatureDecorator } from '../../decorators/signature/SignatureDecoratorUtils'; |
15 |
| -import { InboundMessageContext } from '../../agent/models/InboundMessageContext'; |
16 |
| -import { ConnectionResponseMessage } from './messages/ConnectionResponseMessage'; |
17 |
| -import { SignatureDecorator } from '../../decorators/signature/SignatureDecorator'; |
18 |
| -import { ConnectionRequestMessage } from './messages/ConnectionRequestMessage'; |
19 |
| -import { TrustPingMessage } from '../trustping/TrustPingMessage'; |
20 |
| -import { AckMessage, AckStatus } from './messages/AckMessage'; |
21 |
| -import { JsonTransformer } from '../../utils/JsonTransformer'; |
22 |
| -import { DidDoc } from './domain/did/DidDoc'; |
23 |
| -import { IndyAgentService } from './domain/did/service'; |
24 |
| - |
25 |
| -jest.mock('./../../storage/Repository'); |
| 3 | +import { IndyWallet } from '../../../wallet/IndyWallet'; |
| 4 | +import { Wallet } from '../../../wallet/Wallet'; |
| 5 | +import { ConnectionService } from '../ConnectionService'; |
| 6 | +import { ConnectionRecord, ConnectionStorageProps } from '../../../storage/ConnectionRecord'; |
| 7 | +import { AgentConfig } from '../../../agent/AgentConfig'; |
| 8 | +import { ConnectionState } from '../domain/ConnectionState'; |
| 9 | +import { InitConfig } from '../../../types'; |
| 10 | +import { ConnectionRole } from '../domain/ConnectionRole'; |
| 11 | +import { ConnectionInvitationMessage } from '../messages/ConnectionInvitationMessage'; |
| 12 | +import { Repository } from '../../../storage/Repository'; |
| 13 | +import { Connection } from '../domain/Connection'; |
| 14 | +import { signData, unpackAndVerifySignatureDecorator } from '../../../decorators/signature/SignatureDecoratorUtils'; |
| 15 | +import { InboundMessageContext } from '../../../agent/models/InboundMessageContext'; |
| 16 | +import { ConnectionResponseMessage } from '../messages/ConnectionResponseMessage'; |
| 17 | +import { SignatureDecorator } from '../../../decorators/signature/SignatureDecorator'; |
| 18 | +import { ConnectionRequestMessage } from '../messages/ConnectionRequestMessage'; |
| 19 | +import { TrustPingMessage } from '../../trustping/TrustPingMessage'; |
| 20 | +import { AckMessage, AckStatus } from '../messages/AckMessage'; |
| 21 | +import { JsonTransformer } from '../../../utils/JsonTransformer'; |
| 22 | +import { DidDoc } from '../domain/did/DidDoc'; |
| 23 | +import { IndyAgentService } from '../domain/did/service'; |
| 24 | + |
| 25 | +jest.mock('./../../../storage/Repository'); |
26 | 26 | const ConnectionRepository = <jest.Mock<Repository<ConnectionRecord>>>(<unknown>Repository);
|
27 | 27 |
|
28 | 28 | export function getMockConnection({
|
@@ -275,17 +275,20 @@ describe('ConnectionService', () => {
|
275 | 275 | ConnectionState.Responded,
|
276 | 276 | ConnectionState.Complete,
|
277 | 277 | ];
|
278 |
| - test.each(invalidConnectionStates)('throws an error when connection state is %s and not INVITED', state => { |
279 |
| - expect.assertions(1); |
| 278 | + test.each(invalidConnectionStates)( |
| 279 | + `throws an error when connection state is %s and not ${ConnectionState.Invited}`, |
| 280 | + state => { |
| 281 | + expect.assertions(1); |
280 | 282 |
|
281 |
| - // make separate mockFind variable to get the correct jest mock typing |
282 |
| - const mockFind = connectionRepository.find as jest.Mock<Promise<ConnectionRecord>, [string]>; |
| 283 | + // make separate mockFind variable to get the correct jest mock typing |
| 284 | + const mockFind = connectionRepository.find as jest.Mock<Promise<ConnectionRecord>, [string]>; |
283 | 285 |
|
284 |
| - mockFind.mockReturnValue(Promise.resolve(getMockConnection({ state }))); |
285 |
| - return expect(connectionService.createRequest('test')).rejects.toThrowError( |
286 |
| - `Connection record is in invalid state ${state}. Valid states are: ${ConnectionState.Invited}.` |
287 |
| - ); |
288 |
| - }); |
| 286 | + mockFind.mockReturnValue(Promise.resolve(getMockConnection({ state }))); |
| 287 | + return expect(connectionService.createRequest('test')).rejects.toThrowError( |
| 288 | + `Connection record is in invalid state ${state}. Valid states are: ${ConnectionState.Invited}.` |
| 289 | + ); |
| 290 | + } |
| 291 | + ); |
289 | 292 | });
|
290 | 293 |
|
291 | 294 | describe('processRequest', () => {
|
@@ -460,17 +463,20 @@ describe('ConnectionService', () => {
|
460 | 463 | ConnectionState.Responded,
|
461 | 464 | ConnectionState.Complete,
|
462 | 465 | ];
|
463 |
| - test.each(invalidConnectionStates)('throws an error when connection state is %s and not REQUESTED', async state => { |
464 |
| - expect.assertions(1); |
| 466 | + test.each(invalidConnectionStates)( |
| 467 | + `throws an error when connection state is %s and not ${ConnectionState.Requested}`, |
| 468 | + async state => { |
| 469 | + expect.assertions(1); |
465 | 470 |
|
466 |
| - // make separate mockFind variable to get the correct jest mock typing |
467 |
| - const mockFind = connectionRepository.find as jest.Mock<Promise<ConnectionRecord>, [string]>; |
468 |
| - mockFind.mockReturnValue(Promise.resolve(getMockConnection({ state }))); |
| 471 | + // make separate mockFind variable to get the correct jest mock typing |
| 472 | + const mockFind = connectionRepository.find as jest.Mock<Promise<ConnectionRecord>, [string]>; |
| 473 | + mockFind.mockReturnValue(Promise.resolve(getMockConnection({ state }))); |
469 | 474 |
|
470 |
| - return expect(connectionService.createResponse('test')).rejects.toThrowError( |
471 |
| - `Connection record is in invalid state ${state}. Valid states are: ${ConnectionState.Requested}.` |
472 |
| - ); |
473 |
| - }); |
| 475 | + return expect(connectionService.createResponse('test')).rejects.toThrowError( |
| 476 | + `Connection record is in invalid state ${state}. Valid states are: ${ConnectionState.Requested}.` |
| 477 | + ); |
| 478 | + } |
| 479 | + ); |
474 | 480 | });
|
475 | 481 |
|
476 | 482 | describe('processResponse', () => {
|
@@ -671,7 +677,7 @@ describe('ConnectionService', () => {
|
671 | 677 |
|
672 | 678 | const invalidConnectionStates = [ConnectionState.Init, ConnectionState.Invited, ConnectionState.Requested];
|
673 | 679 | test.each(invalidConnectionStates)(
|
674 |
| - 'throws an error when connection state is %s and not RESPONDED or COMPLETED', |
| 680 | + `throws an error when connection state is %s and not ${ConnectionState.Responded} or ${ConnectionState.Complete}`, |
675 | 681 | state => {
|
676 | 682 | expect.assertions(1);
|
677 | 683 |
|
|
0 commit comments