Skip to content

Commit 9fb4f36

Browse files
authored
update record states to match rfc (openwallet-foundation#180)
1 parent b984a38 commit 9fb4f36

File tree

10 files changed

+156
-100
lines changed

10 files changed

+156
-100
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/checkout@v2
2020

2121
- name: Get docker cache
22-
uses: satackey/[email protected].5
22+
uses: satackey/[email protected].11
2323

2424
- name: Start indy pool
2525
run: |

src/lib/agent/__tests__/AgentConfig.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getMockConnection } from '../../protocols/connections/ConnectionService.test';
1+
import { getMockConnection } from '../../protocols/connections/__tests__/ConnectionService.test';
22
import { DidDoc } from '../../protocols/connections/domain/did/DidDoc';
33
import { IndyAgentService } from '../../protocols/connections/domain/did/service';
44
import { AgentConfig } from '../AgentConfig';

src/lib/protocols/connections/ConnectionService.test.ts renamed to src/lib/protocols/connections/__tests__/ConnectionService.test.ts

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import indy from 'indy-sdk';
22
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');
2626
const ConnectionRepository = <jest.Mock<Repository<ConnectionRecord>>>(<unknown>Repository);
2727

2828
export function getMockConnection({
@@ -275,17 +275,20 @@ describe('ConnectionService', () => {
275275
ConnectionState.Responded,
276276
ConnectionState.Complete,
277277
];
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);
280282

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]>;
283285

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+
);
289292
});
290293

291294
describe('processRequest', () => {
@@ -460,17 +463,20 @@ describe('ConnectionService', () => {
460463
ConnectionState.Responded,
461464
ConnectionState.Complete,
462465
];
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);
465470

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 })));
469474

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+
);
474480
});
475481

476482
describe('processResponse', () => {
@@ -671,7 +677,7 @@ describe('ConnectionService', () => {
671677

672678
const invalidConnectionStates = [ConnectionState.Init, ConnectionState.Invited, ConnectionState.Requested];
673679
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}`,
675681
state => {
676682
expect.assertions(1);
677683

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ConnectionState } from '../domain/ConnectionState';
2+
3+
describe('ConnectionState', () => {
4+
test('state matches Connection 1.0 (RFC 0160) state value', () => {
5+
expect(ConnectionState.Init).toBe('init');
6+
expect(ConnectionState.Invited).toBe('invited');
7+
expect(ConnectionState.Requested).toBe('requested');
8+
expect(ConnectionState.Responded).toBe('responded');
9+
expect(ConnectionState.Complete).toBe('complete');
10+
});
11+
});
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
/**
2+
* Connection states as defined in RFC 0160.
3+
*
4+
* State 'null' from RFC is changed to 'init'
5+
*
6+
* @see https://github.com/hyperledger/aries-rfcs/blob/master/features/0160-connection-protocol/README.md#states
7+
*/
18
export enum ConnectionState {
2-
Init = 'INIT',
3-
Invited = 'INVITED',
4-
Requested = 'REQUESTED',
5-
Responded = 'RESPONDED',
6-
Complete = 'COMPLETE',
9+
Init = 'init',
10+
Invited = 'invited',
11+
Requested = 'requested',
12+
Responded = 'responded',
13+
Complete = 'complete',
714
}
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
/**
2+
* Issue Credential states as defined in RFC 0036
3+
*
4+
* @see https://github.com/hyperledger/aries-rfcs/blob/master/features/0036-issue-credential/README.md#states
5+
*/
16
export enum CredentialState {
2-
ProposalSent = 'PROPOSAL_SENT',
3-
ProposalReceived = 'PROPOSAL_RECEIVED',
4-
OfferSent = 'OFFER_SENT',
5-
OfferReceived = 'OFFER_RECEIVED',
6-
RequestSent = 'REQUEST_SENT',
7-
RequestReceived = 'REQUEST_RECEIVED',
8-
CredentialIssued = 'CREDENTIAL_ISSUED',
9-
CredentialReceived = 'CREDENTIAL_RECEIVED',
10-
Done = 'DONE',
7+
ProposalSent = 'proposal-sent',
8+
ProposalReceived = 'proposal-received',
9+
OfferSent = 'offer-sent',
10+
OfferReceived = 'offer-received',
11+
RequestSent = 'request-sent',
12+
RequestReceived = 'request-received',
13+
CredentialIssued = 'credential-issued',
14+
CredentialReceived = 'credential-received',
15+
Done = 'done',
1116
}

0 commit comments

Comments
 (0)