@sphereon/ssi-sdk.data-store 0.30.1-unstable.4 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +77 -77
- package/dist/contact/ContactStore.d.ts.map +1 -1
- package/dist/digitalCredential/DigitalCredentialStore.d.ts.map +1 -1
- package/dist/eventLogger/EventLoggerStore.d.ts.map +1 -1
- package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts.map +1 -1
- package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js +33 -33
- package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.js +16 -16
- package/dist/migrations/postgres/1715761125001-CreateContacts.js +33 -33
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js +12 -12
- package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js +32 -32
- package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.js +15 -15
- package/dist/migrations/sqlite/1710438363002-CreateContacts.js +13 -13
- package/dist/migrations/sqlite/1715761125002-CreateContacts.js +32 -32
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js +9 -9
- package/dist/presentationDefinition/PDStore.d.ts.map +1 -1
- package/dist/utils/SortingUtils.d.ts.map +1 -1
- package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
- package/dist/utils/digitalCredential/MappingUtils.d.ts.map +1 -1
- package/dist/utils/digitalCredential/MappingUtils.js +4 -4
- package/dist/utils/digitalCredential/MappingUtils.js.map +1 -1
- package/dist/utils/presentationDefinition/MappingUtils.js +2 -2
- package/dist/utils/presentationDefinition/MappingUtils.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/contact.entities.test.ts +2642 -2642
- package/src/__tests__/contact.store.test.ts +2649 -2649
- package/src/__tests__/digitalCredential.entities.test.ts +274 -274
- package/src/__tests__/digitalCredential.store.test.ts +330 -330
- package/src/__tests__/eventLogger.entities.test.ts +76 -76
- package/src/__tests__/eventLogger.store.test.ts +130 -130
- package/src/__tests__/issuanceBranding.entities.test.ts +846 -846
- package/src/__tests__/issuanceBranding.store.test.ts +1886 -1886
- package/src/__tests__/machineState.entities.test.ts +53 -53
- package/src/__tests__/machineState.store.test.ts +176 -176
- package/src/__tests__/pd-manager.entities.test.ts +73 -73
- package/src/__tests__/pd-manager.store.test.ts +193 -193
- package/src/contact/AbstractContactStore.ts +71 -71
- package/src/contact/ContactStore.ts +768 -768
- package/src/digitalCredential/AbstractDigitalCredentialStore.ts +21 -21
- package/src/digitalCredential/DigitalCredentialStore.ts +189 -189
- package/src/entities/contact/BaseContactEntity.ts +51 -51
- package/src/entities/contact/ConnectionEntity.ts +35 -35
- package/src/entities/contact/ContactMetadataItemEntity.ts +51 -51
- package/src/entities/contact/CorrelationIdentifierEntity.ts +43 -43
- package/src/entities/contact/DidAuthConfigEntity.ts +20 -20
- package/src/entities/contact/ElectronicAddressEntity.ts +70 -70
- package/src/entities/contact/IdentityEntity.ts +107 -107
- package/src/entities/contact/IdentityMetadataItemEntity.ts +48 -48
- package/src/entities/contact/NaturalPersonEntity.ts +44 -44
- package/src/entities/contact/OpenIdConfigEntity.ts +32 -32
- package/src/entities/contact/OrganizationEntity.ts +35 -35
- package/src/entities/contact/PartyEntity.ts +117 -117
- package/src/entities/contact/PartyRelationshipEntity.ts +68 -68
- package/src/entities/contact/PartyTypeEntity.ts +63 -63
- package/src/entities/contact/PhysicalAddressEntity.ts +95 -95
- package/src/entities/digitalCredential/DigitalCredentialEntity.ts +98 -98
- package/src/entities/eventLogger/AuditEventEntity.ts +92 -92
- package/src/entities/issuanceBranding/BackgroundAttributesEntity.ts +42 -42
- package/src/entities/issuanceBranding/BaseLocaleBrandingEntity.ts +87 -87
- package/src/entities/issuanceBranding/CredentialBrandingEntity.ts +79 -79
- package/src/entities/issuanceBranding/CredentialLocaleBrandingEntity.ts +33 -33
- package/src/entities/issuanceBranding/ImageAttributesEntity.ts +57 -57
- package/src/entities/issuanceBranding/ImageDimensionsEntity.ts +22 -22
- package/src/entities/issuanceBranding/IssuerBrandingEntity.ts +73 -73
- package/src/entities/issuanceBranding/IssuerLocaleBrandingEntity.ts +33 -33
- package/src/entities/issuanceBranding/TextAttributesEntity.ts +31 -31
- package/src/entities/machineState/MachineStateInfoEntity.ts +59 -59
- package/src/entities/presentationDefinition/PresentationDefinitionItemEntity.ts +44 -44
- package/src/entities/statusList2021/StatusList2021Entity.ts +96 -96
- package/src/entities/statusList2021/StatusList2021EntryEntity.ts +29 -29
- package/src/eventLogger/AbstractEventLoggerStore.ts +7 -7
- package/src/eventLogger/EventLoggerStore.ts +62 -62
- package/src/index.ts +160 -160
- package/src/issuanceBranding/IssuanceBrandingStore.ts +559 -559
- package/src/machineState/IAbstractMachineStateStore.ts +65 -65
- package/src/machineState/MachineStateStore.ts +149 -149
- package/src/migrations/generic/1-CreateContacts.ts +66 -66
- package/src/migrations/generic/10-CreatePresentationDefinitions.ts +66 -66
- package/src/migrations/generic/2-CreateIssuanceBranding.ts +64 -64
- package/src/migrations/generic/3-CreateContacts.ts +66 -66
- package/src/migrations/generic/4-CreateStatusList.ts +54 -54
- package/src/migrations/generic/5-CreateAuditEvents.ts +66 -66
- package/src/migrations/generic/6-CreateDigitalCredential.ts +66 -66
- package/src/migrations/generic/7-CreateMachineStateStore.ts +66 -66
- package/src/migrations/generic/8-CreateContacts.ts +66 -66
- package/src/migrations/generic/9-CreateContacts.ts +66 -66
- package/src/migrations/generic/index.ts +43 -43
- package/src/migrations/index.ts +10 -10
- package/src/migrations/postgres/1659463079428-CreateContacts.ts +63 -63
- package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +85 -85
- package/src/migrations/postgres/1690925872592-CreateContacts.ts +158 -158
- package/src/migrations/postgres/1693866470001-CreateStatusList.ts +24 -24
- package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +33 -33
- package/src/migrations/postgres/1708525189001-CreateDigitalCredential.ts +61 -61
- package/src/migrations/postgres/1708797018115-CreateMachineStateStore.ts +29 -29
- package/src/migrations/postgres/1710438363001-CreateContacts.ts +63 -63
- package/src/migrations/postgres/1715761125001-CreateContacts.ts +60 -60
- package/src/migrations/postgres/1716475165345-CreatePresentationDefinitions.ts +25 -25
- package/src/migrations/sqlite/1659463069549-CreateContacts.ts +110 -110
- package/src/migrations/sqlite/1685628973231-CreateIssuanceBranding.ts +119 -119
- package/src/migrations/sqlite/1690925872693-CreateContacts.ts +228 -228
- package/src/migrations/sqlite/1693866470000-CreateStatusList.ts +24 -24
- package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +15 -15
- package/src/migrations/sqlite/1708525189002-CreateDigitalCredential.ts +46 -46
- package/src/migrations/sqlite/1708796002272-CreateMachineStateStore.ts +28 -28
- package/src/migrations/sqlite/1710438363002-CreateContacts.ts +83 -83
- package/src/migrations/sqlite/1715761125002-CreateContacts.ts +59 -59
- package/src/migrations/sqlite/1716475165344-CreatePresentationDefinitions.ts +24 -24
- package/src/presentationDefinition/AbstractPDStore.ts +20 -20
- package/src/presentationDefinition/PDStore.ts +185 -185
- package/src/statusList/IStatusListStore.ts +44 -44
- package/src/statusList/StatusListStore.ts +236 -236
- package/src/types/contact/IAbstractContactStore.ts +161 -161
- package/src/types/contact/contact.ts +295 -295
- package/src/types/digitalCredential/IAbstractDigitalCredentialStore.ts +42 -42
- package/src/types/digitalCredential/digitalCredential.ts +102 -102
- package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -12
- package/src/types/eventLogger/eventLogger.ts +3 -3
- package/src/types/index.ts +14 -14
- package/src/types/machineState/IAbstractMachineStateStore.ts +68 -68
- package/src/types/presentationDefinition/IAbstractPDStore.ts +25 -25
- package/src/types/presentationDefinition/presentationDefinition.ts +17 -17
- package/src/utils/SortingUtils.ts +16 -16
- package/src/utils/contact/MappingUtils.ts +506 -506
- package/src/utils/digitalCredential/MappingUtils.ts +160 -160
- package/src/utils/hasher.ts +19 -19
- package/src/utils/presentationDefinition/MappingUtils.ts +52 -52
- package/dist/entities/contact/IMetadataEntity.d.ts +0 -8
- package/dist/entities/contact/IMetadataEntity.d.ts.map +0 -1
- package/dist/entities/contact/IMetadataEntity.js +0 -2
- package/dist/entities/contact/IMetadataEntity.js.map +0 -1
- package/dist/migrations/generic/8-CreatePresentationDefinitions.d.ts +0 -7
- package/dist/migrations/generic/8-CreatePresentationDefinitions.d.ts.map +0 -1
- package/dist/migrations/generic/8-CreatePresentationDefinitions.js +0 -78
- package/dist/migrations/generic/8-CreatePresentationDefinitions.js.map +0 -1
|
@@ -1,2649 +1,2649 @@
|
|
|
1
|
-
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
-
import { DataSource } from 'typeorm'
|
|
3
|
-
import { DataStoreContactEntities, DataStoreMigrations, IdentityOrigin, MetadataItem, MetadataTypes, PartyOrigin } from '../index'
|
|
4
|
-
import { ContactStore } from '../contact/ContactStore'
|
|
5
|
-
import {
|
|
6
|
-
CorrelationIdentifierType,
|
|
7
|
-
ElectronicAddress,
|
|
8
|
-
GetElectronicAddressesArgs,
|
|
9
|
-
GetIdentitiesArgs,
|
|
10
|
-
GetPartiesArgs,
|
|
11
|
-
GetPhysicalAddressesArgs,
|
|
12
|
-
GetRelationshipsArgs,
|
|
13
|
-
Identity,
|
|
14
|
-
CredentialRole,
|
|
15
|
-
NaturalPerson,
|
|
16
|
-
NonPersistedElectronicAddress,
|
|
17
|
-
NonPersistedIdentity,
|
|
18
|
-
NonPersistedNaturalPerson,
|
|
19
|
-
NonPersistedParty,
|
|
20
|
-
NonPersistedPartyRelationship,
|
|
21
|
-
NonPersistedPartyType,
|
|
22
|
-
NonPersistedPhysicalAddress,
|
|
23
|
-
Party,
|
|
24
|
-
PartyRelationship,
|
|
25
|
-
PartyType,
|
|
26
|
-
PartyTypeType,
|
|
27
|
-
PhysicalAddress,
|
|
28
|
-
} from '../types'
|
|
29
|
-
|
|
30
|
-
describe('Contact store tests', (): void => {
|
|
31
|
-
let dbConnection: DataSource
|
|
32
|
-
let contactStore: ContactStore
|
|
33
|
-
|
|
34
|
-
beforeEach(async (): Promise<void> => {
|
|
35
|
-
DataSources.singleInstance().defaultDbType = 'sqlite'
|
|
36
|
-
dbConnection = await new DataSource({
|
|
37
|
-
type: 'sqlite',
|
|
38
|
-
database: ':memory:',
|
|
39
|
-
logging: ['info'],
|
|
40
|
-
migrationsRun: false,
|
|
41
|
-
migrations: DataStoreMigrations,
|
|
42
|
-
synchronize: false,
|
|
43
|
-
entities: DataStoreContactEntities,
|
|
44
|
-
}).initialize()
|
|
45
|
-
await dbConnection.runMigrations()
|
|
46
|
-
expect(await dbConnection.showMigrations()).toBeFalsy()
|
|
47
|
-
contactStore = new ContactStore(dbConnection)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
afterEach(async (): Promise<void> => {
|
|
51
|
-
await (await dbConnection).destroy()
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('should get party by contact metadata', async (): Promise<void> => {
|
|
55
|
-
const dateOfBirth = new Date(2016, 0, 5)
|
|
56
|
-
const party: NonPersistedParty = {
|
|
57
|
-
uri: 'example.com',
|
|
58
|
-
partyType: {
|
|
59
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
60
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
61
|
-
name: 'example_name',
|
|
62
|
-
origin: PartyOrigin.EXTERNAL,
|
|
63
|
-
},
|
|
64
|
-
contact: {
|
|
65
|
-
firstName: 'example_first_name',
|
|
66
|
-
middleName: 'example_middle_name',
|
|
67
|
-
lastName: 'example_last_name',
|
|
68
|
-
metadata: [
|
|
69
|
-
{ label: 'grade', value: '5th' },
|
|
70
|
-
{ label: 'dateOfBirth', value: dateOfBirth },
|
|
71
|
-
] as Array<MetadataItem<MetadataTypes>>,
|
|
72
|
-
displayName: 'example_display_name',
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
77
|
-
expect(savedParty).toBeDefined()
|
|
78
|
-
|
|
79
|
-
const singleResult: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
80
|
-
expect(singleResult).toBeDefined()
|
|
81
|
-
|
|
82
|
-
const args: GetPartiesArgs = {
|
|
83
|
-
filter: [{ contact: { metadata: { label: 'dateOfBirth', value: dateOfBirth } } }],
|
|
84
|
-
}
|
|
85
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
86
|
-
expect(result).toBeDefined()
|
|
87
|
-
expect(result.length).toEqual(1)
|
|
88
|
-
expect(result[0]).toBeDefined()
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('should get a party by identity metadata', async (): Promise<void> => {
|
|
92
|
-
const party: NonPersistedParty = {
|
|
93
|
-
uri: 'example.com',
|
|
94
|
-
partyType: {
|
|
95
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
96
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
97
|
-
name: 'example_name',
|
|
98
|
-
origin: PartyOrigin.EXTERNAL,
|
|
99
|
-
},
|
|
100
|
-
contact: {
|
|
101
|
-
firstName: 'example_first_name',
|
|
102
|
-
middleName: 'example_middle_name',
|
|
103
|
-
lastName: 'example_last_name',
|
|
104
|
-
displayName: 'example_display_name',
|
|
105
|
-
},
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
109
|
-
expect(savedParty).toBeDefined()
|
|
110
|
-
|
|
111
|
-
const identity: NonPersistedIdentity = {
|
|
112
|
-
alias: 'test_alias',
|
|
113
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
114
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
115
|
-
identifier: {
|
|
116
|
-
type: CorrelationIdentifierType.DID,
|
|
117
|
-
correlationId: 'example_did',
|
|
118
|
-
},
|
|
119
|
-
metadata: [
|
|
120
|
-
{
|
|
121
|
-
label: 'label1',
|
|
122
|
-
value: 'example_value',
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
label: 'label2',
|
|
126
|
-
value: 'example_value',
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
}
|
|
130
|
-
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity })
|
|
131
|
-
expect(savedIdentity).toBeDefined()
|
|
132
|
-
|
|
133
|
-
const args: GetPartiesArgs = {
|
|
134
|
-
filter: [{ identities: { metadata: { label: 'label1', value: 'example_value' } } }],
|
|
135
|
-
}
|
|
136
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
137
|
-
expect(result).toBeDefined()
|
|
138
|
-
expect(result.length).toEqual(1)
|
|
139
|
-
expect(result[0]).toBeDefined()
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('should get party by both contact and identity metadata', async (): Promise<void> => {
|
|
143
|
-
const example_date = new Date(2016, 0, 5)
|
|
144
|
-
const party: NonPersistedParty = {
|
|
145
|
-
uri: 'example.com',
|
|
146
|
-
partyType: {
|
|
147
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
148
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
149
|
-
name: 'example_name',
|
|
150
|
-
origin: PartyOrigin.EXTERNAL,
|
|
151
|
-
},
|
|
152
|
-
contact: {
|
|
153
|
-
firstName: 'example_first_name',
|
|
154
|
-
middleName: 'example_middle_name',
|
|
155
|
-
lastName: 'example_last_name',
|
|
156
|
-
displayName: 'example_display_name',
|
|
157
|
-
metadata: [
|
|
158
|
-
{ label: 'label1', value: 'example_value' },
|
|
159
|
-
{ label: 'label2', value: example_date },
|
|
160
|
-
] as Array<MetadataItem<MetadataTypes>>,
|
|
161
|
-
},
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
165
|
-
expect(savedParty).toBeDefined()
|
|
166
|
-
|
|
167
|
-
const identity: NonPersistedIdentity = {
|
|
168
|
-
alias: 'test_alias',
|
|
169
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
170
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
171
|
-
identifier: {
|
|
172
|
-
type: CorrelationIdentifierType.DID,
|
|
173
|
-
correlationId: 'example_did',
|
|
174
|
-
},
|
|
175
|
-
metadata: [
|
|
176
|
-
{
|
|
177
|
-
label: 'label3',
|
|
178
|
-
value: 'example_value',
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
label: 'label4',
|
|
182
|
-
value: 'example_value',
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
|
-
}
|
|
186
|
-
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity })
|
|
187
|
-
expect(savedIdentity).toBeDefined()
|
|
188
|
-
|
|
189
|
-
const args: GetPartiesArgs = {
|
|
190
|
-
filter: [
|
|
191
|
-
{
|
|
192
|
-
contact: { metadata: { label: 'label2', value: example_date } },
|
|
193
|
-
identities: { metadata: { label: 'label3', value: 'example_value' } },
|
|
194
|
-
},
|
|
195
|
-
],
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
199
|
-
|
|
200
|
-
expect(result).toBeDefined()
|
|
201
|
-
expect(result.length).toEqual(1)
|
|
202
|
-
expect(result[0]).toBeDefined()
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
it('should get party by id', async (): Promise<void> => {
|
|
206
|
-
const party: NonPersistedParty = {
|
|
207
|
-
uri: 'example.com',
|
|
208
|
-
partyType: {
|
|
209
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
210
|
-
origin: PartyOrigin.INTERNAL,
|
|
211
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
212
|
-
name: 'example_name',
|
|
213
|
-
},
|
|
214
|
-
contact: {
|
|
215
|
-
firstName: 'example_first_name',
|
|
216
|
-
middleName: 'example_middle_name',
|
|
217
|
-
lastName: 'example_last_name',
|
|
218
|
-
displayName: 'example_display_name',
|
|
219
|
-
},
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
223
|
-
expect(savedParty).toBeDefined()
|
|
224
|
-
|
|
225
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
226
|
-
|
|
227
|
-
expect(result).toBeDefined()
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
it('should throw error when getting party with unknown id', async (): Promise<void> => {
|
|
231
|
-
const partyId = 'unknownPartyId'
|
|
232
|
-
|
|
233
|
-
await expect(contactStore.getParty({ partyId })).rejects.toThrow(`No party found for id: ${partyId}`)
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
it('should get all parties', async (): Promise<void> => {
|
|
237
|
-
const party1: NonPersistedParty = {
|
|
238
|
-
uri: 'example.com',
|
|
239
|
-
partyType: {
|
|
240
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
241
|
-
origin: PartyOrigin.INTERNAL,
|
|
242
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
243
|
-
name: 'example_name1',
|
|
244
|
-
},
|
|
245
|
-
contact: {
|
|
246
|
-
firstName: 'example_first_name1',
|
|
247
|
-
middleName: 'example_middle_name1',
|
|
248
|
-
lastName: 'example_last_name1',
|
|
249
|
-
displayName: 'example_display_name1',
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
253
|
-
expect(savedParty1).toBeDefined()
|
|
254
|
-
|
|
255
|
-
const party2: NonPersistedParty = {
|
|
256
|
-
uri: 'example.com',
|
|
257
|
-
partyType: {
|
|
258
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
259
|
-
origin: PartyOrigin.INTERNAL,
|
|
260
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
261
|
-
name: 'example_name2',
|
|
262
|
-
},
|
|
263
|
-
contact: {
|
|
264
|
-
firstName: 'example_first_name2',
|
|
265
|
-
middleName: 'example_middle_name2',
|
|
266
|
-
lastName: 'example_last_name2',
|
|
267
|
-
displayName: 'example_display_name2',
|
|
268
|
-
},
|
|
269
|
-
}
|
|
270
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
271
|
-
expect(savedParty2).toBeDefined()
|
|
272
|
-
|
|
273
|
-
const result: Array<Party> = await contactStore.getParties()
|
|
274
|
-
|
|
275
|
-
expect(result).toBeDefined()
|
|
276
|
-
expect(result.length).toEqual(2)
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
it('should get parties by filter', async (): Promise<void> => {
|
|
280
|
-
const party: NonPersistedParty = {
|
|
281
|
-
uri: 'example.com',
|
|
282
|
-
partyType: {
|
|
283
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
284
|
-
origin: PartyOrigin.INTERNAL,
|
|
285
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
286
|
-
name: 'example_name',
|
|
287
|
-
},
|
|
288
|
-
contact: {
|
|
289
|
-
firstName: 'example_first_name',
|
|
290
|
-
middleName: 'example_middle_name',
|
|
291
|
-
lastName: 'example_last_name',
|
|
292
|
-
displayName: 'example_display_name',
|
|
293
|
-
},
|
|
294
|
-
}
|
|
295
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
296
|
-
expect(savedParty).toBeDefined()
|
|
297
|
-
|
|
298
|
-
const args: GetPartiesArgs = {
|
|
299
|
-
filter: [
|
|
300
|
-
{
|
|
301
|
-
contact: {
|
|
302
|
-
firstName: (<NonPersistedNaturalPerson>party.contact).firstName,
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
{
|
|
306
|
-
contact: {
|
|
307
|
-
middleName: (<NonPersistedNaturalPerson>party.contact).middleName,
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
contact: {
|
|
312
|
-
lastName: (<NonPersistedNaturalPerson>party.contact).lastName,
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
contact: {
|
|
317
|
-
displayName: (<NonPersistedNaturalPerson>party.contact).displayName,
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
}
|
|
322
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
323
|
-
|
|
324
|
-
expect(result.length).toEqual(1)
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
it('should get whole parties by filter', async (): Promise<void> => {
|
|
328
|
-
const party: NonPersistedParty = {
|
|
329
|
-
uri: 'example.com',
|
|
330
|
-
partyType: {
|
|
331
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
332
|
-
origin: PartyOrigin.INTERNAL,
|
|
333
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
334
|
-
name: 'example_name',
|
|
335
|
-
},
|
|
336
|
-
contact: {
|
|
337
|
-
firstName: 'example_first_name',
|
|
338
|
-
middleName: 'example_middle_name',
|
|
339
|
-
lastName: 'example_last_name',
|
|
340
|
-
displayName: 'example_display_name',
|
|
341
|
-
},
|
|
342
|
-
identities: [
|
|
343
|
-
{
|
|
344
|
-
alias: 'test_alias1',
|
|
345
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
346
|
-
roles: [CredentialRole.ISSUER],
|
|
347
|
-
identifier: {
|
|
348
|
-
type: CorrelationIdentifierType.DID,
|
|
349
|
-
correlationId: 'example_did1',
|
|
350
|
-
},
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
alias: 'test_alias2',
|
|
354
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
355
|
-
roles: [CredentialRole.VERIFIER],
|
|
356
|
-
identifier: {
|
|
357
|
-
type: CorrelationIdentifierType.DID,
|
|
358
|
-
correlationId: 'example_did2',
|
|
359
|
-
},
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
alias: 'test_alias3',
|
|
363
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
364
|
-
roles: [CredentialRole.HOLDER],
|
|
365
|
-
identifier: {
|
|
366
|
-
type: CorrelationIdentifierType.DID,
|
|
367
|
-
correlationId: 'example_did3',
|
|
368
|
-
},
|
|
369
|
-
},
|
|
370
|
-
],
|
|
371
|
-
electronicAddresses: [
|
|
372
|
-
{
|
|
373
|
-
type: 'email',
|
|
374
|
-
electronicAddress: 'example_electronic_address',
|
|
375
|
-
},
|
|
376
|
-
],
|
|
377
|
-
}
|
|
378
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
379
|
-
expect(savedParty).toBeDefined()
|
|
380
|
-
|
|
381
|
-
const args: GetPartiesArgs = {
|
|
382
|
-
filter: [
|
|
383
|
-
{
|
|
384
|
-
identities: {
|
|
385
|
-
identifier: {
|
|
386
|
-
correlationId: 'example_did1',
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
},
|
|
390
|
-
],
|
|
391
|
-
}
|
|
392
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
393
|
-
|
|
394
|
-
expect(result[0].identities.length).toEqual(3)
|
|
395
|
-
expect(result[0].electronicAddresses.length).toEqual(1)
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
it('should get parties by name', async (): Promise<void> => {
|
|
399
|
-
const party: NonPersistedParty = {
|
|
400
|
-
uri: 'example.com',
|
|
401
|
-
partyType: {
|
|
402
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
403
|
-
origin: PartyOrigin.INTERNAL,
|
|
404
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
405
|
-
name: 'something',
|
|
406
|
-
},
|
|
407
|
-
contact: {
|
|
408
|
-
firstName: 'example_first_name',
|
|
409
|
-
middleName: 'example_middle_name',
|
|
410
|
-
lastName: 'example_last_name',
|
|
411
|
-
displayName: 'example_display_name',
|
|
412
|
-
},
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
416
|
-
expect(savedParty).toBeDefined()
|
|
417
|
-
|
|
418
|
-
const args: GetPartiesArgs = {
|
|
419
|
-
filter: [
|
|
420
|
-
{
|
|
421
|
-
contact: {
|
|
422
|
-
firstName: (<NonPersistedNaturalPerson>party.contact).firstName,
|
|
423
|
-
},
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
contact: {
|
|
427
|
-
middleName: (<NonPersistedNaturalPerson>party.contact).middleName,
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
contact: {
|
|
432
|
-
lastName: (<NonPersistedNaturalPerson>party.contact).lastName,
|
|
433
|
-
},
|
|
434
|
-
},
|
|
435
|
-
],
|
|
436
|
-
}
|
|
437
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
438
|
-
|
|
439
|
-
expect(result.length).toEqual(1)
|
|
440
|
-
})
|
|
441
|
-
|
|
442
|
-
it('should get parties by display name', async (): Promise<void> => {
|
|
443
|
-
const party: NonPersistedParty = {
|
|
444
|
-
uri: 'example.com',
|
|
445
|
-
partyType: {
|
|
446
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
447
|
-
origin: PartyOrigin.INTERNAL,
|
|
448
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
449
|
-
name: 'example_name',
|
|
450
|
-
},
|
|
451
|
-
contact: {
|
|
452
|
-
firstName: 'example_first_name',
|
|
453
|
-
middleName: 'example_middle_name',
|
|
454
|
-
lastName: 'example_last_name',
|
|
455
|
-
displayName: 'example_display_name',
|
|
456
|
-
},
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
460
|
-
expect(savedParty).toBeDefined()
|
|
461
|
-
|
|
462
|
-
const args: GetPartiesArgs = {
|
|
463
|
-
filter: [
|
|
464
|
-
{
|
|
465
|
-
contact: {
|
|
466
|
-
displayName: (<NonPersistedNaturalPerson>party.contact).displayName,
|
|
467
|
-
},
|
|
468
|
-
},
|
|
469
|
-
],
|
|
470
|
-
}
|
|
471
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
472
|
-
|
|
473
|
-
expect(result.length).toEqual(1)
|
|
474
|
-
})
|
|
475
|
-
|
|
476
|
-
it('should get parties by uri', async (): Promise<void> => {
|
|
477
|
-
const party: NonPersistedParty = {
|
|
478
|
-
uri: 'example.com',
|
|
479
|
-
partyType: {
|
|
480
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
481
|
-
origin: PartyOrigin.INTERNAL,
|
|
482
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
483
|
-
name: 'example_name',
|
|
484
|
-
},
|
|
485
|
-
contact: {
|
|
486
|
-
firstName: 'example_first_name',
|
|
487
|
-
middleName: 'example_middle_name',
|
|
488
|
-
lastName: 'example_last_name',
|
|
489
|
-
displayName: 'example_display_name',
|
|
490
|
-
},
|
|
491
|
-
}
|
|
492
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
493
|
-
expect(savedParty).toBeDefined()
|
|
494
|
-
|
|
495
|
-
const args: GetPartiesArgs = {
|
|
496
|
-
filter: [{ uri: 'example.com' }],
|
|
497
|
-
}
|
|
498
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
499
|
-
|
|
500
|
-
expect(result.length).toEqual(1)
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
it('should return no parties if filter does not match', async (): Promise<void> => {
|
|
504
|
-
const args: GetPartiesArgs = {
|
|
505
|
-
filter: [
|
|
506
|
-
{
|
|
507
|
-
contact: {
|
|
508
|
-
firstName: 'no_match_firstName',
|
|
509
|
-
},
|
|
510
|
-
},
|
|
511
|
-
{
|
|
512
|
-
contact: {
|
|
513
|
-
middleName: 'no_match_middleName',
|
|
514
|
-
},
|
|
515
|
-
},
|
|
516
|
-
{
|
|
517
|
-
contact: {
|
|
518
|
-
lastName: 'no_match_lastName',
|
|
519
|
-
},
|
|
520
|
-
},
|
|
521
|
-
],
|
|
522
|
-
}
|
|
523
|
-
const result: Array<Party> = await contactStore.getParties(args)
|
|
524
|
-
|
|
525
|
-
expect(result.length).toEqual(0)
|
|
526
|
-
})
|
|
527
|
-
|
|
528
|
-
it('should add party without identities', async (): Promise<void> => {
|
|
529
|
-
const party: NonPersistedParty = {
|
|
530
|
-
uri: 'example.com',
|
|
531
|
-
partyType: {
|
|
532
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
533
|
-
origin: PartyOrigin.INTERNAL,
|
|
534
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
535
|
-
name: 'example_name',
|
|
536
|
-
},
|
|
537
|
-
contact: {
|
|
538
|
-
firstName: 'example_first_name',
|
|
539
|
-
middleName: 'example_middle_name',
|
|
540
|
-
lastName: 'example_last_name',
|
|
541
|
-
displayName: 'example_display_name',
|
|
542
|
-
},
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
const result: Party = await contactStore.addParty(party)
|
|
546
|
-
|
|
547
|
-
expect(result).toBeDefined()
|
|
548
|
-
expect((<NaturalPerson>result.contact).firstName).toEqual((<NonPersistedNaturalPerson>party.contact).firstName)
|
|
549
|
-
expect((<NaturalPerson>result.contact).middleName).toEqual((<NonPersistedNaturalPerson>party.contact).middleName)
|
|
550
|
-
expect((<NaturalPerson>result.contact).lastName).toEqual((<NonPersistedNaturalPerson>party.contact).lastName)
|
|
551
|
-
expect(result.identities.length).toEqual(0)
|
|
552
|
-
})
|
|
553
|
-
|
|
554
|
-
it('should add party with identities', async (): Promise<void> => {
|
|
555
|
-
const party: NonPersistedParty = {
|
|
556
|
-
uri: 'example.com',
|
|
557
|
-
partyType: {
|
|
558
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
559
|
-
origin: PartyOrigin.INTERNAL,
|
|
560
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
561
|
-
name: 'example_name',
|
|
562
|
-
},
|
|
563
|
-
contact: {
|
|
564
|
-
firstName: 'example_first_name',
|
|
565
|
-
middleName: 'example_middle_name',
|
|
566
|
-
lastName: 'example_last_name',
|
|
567
|
-
displayName: 'example_display_name',
|
|
568
|
-
},
|
|
569
|
-
identities: [
|
|
570
|
-
{
|
|
571
|
-
alias: 'test_alias1',
|
|
572
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
573
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
574
|
-
identifier: {
|
|
575
|
-
type: CorrelationIdentifierType.DID,
|
|
576
|
-
correlationId: 'example_did1',
|
|
577
|
-
},
|
|
578
|
-
},
|
|
579
|
-
{
|
|
580
|
-
alias: 'test_alias2',
|
|
581
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
582
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
583
|
-
identifier: {
|
|
584
|
-
type: CorrelationIdentifierType.DID,
|
|
585
|
-
correlationId: 'example_did2',
|
|
586
|
-
},
|
|
587
|
-
},
|
|
588
|
-
],
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
const result: Party = await contactStore.addParty(party)
|
|
592
|
-
|
|
593
|
-
expect(result).toBeDefined()
|
|
594
|
-
expect((<NaturalPerson>result.contact).firstName).toEqual((<NonPersistedNaturalPerson>party.contact).firstName)
|
|
595
|
-
expect((<NaturalPerson>result.contact).middleName).toEqual((<NonPersistedNaturalPerson>party.contact).middleName)
|
|
596
|
-
expect((<NaturalPerson>result.contact).lastName).toEqual((<NonPersistedNaturalPerson>party.contact).lastName)
|
|
597
|
-
expect(result.identities.length).toEqual(2)
|
|
598
|
-
})
|
|
599
|
-
|
|
600
|
-
it('should throw error when adding party with invalid identity', async (): Promise<void> => {
|
|
601
|
-
const party: NonPersistedParty = {
|
|
602
|
-
uri: 'example.com',
|
|
603
|
-
partyType: {
|
|
604
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
605
|
-
origin: PartyOrigin.INTERNAL,
|
|
606
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
607
|
-
name: 'something',
|
|
608
|
-
},
|
|
609
|
-
contact: {
|
|
610
|
-
firstName: 'example_first_name',
|
|
611
|
-
middleName: 'example_middle_name',
|
|
612
|
-
lastName: 'example_last_name',
|
|
613
|
-
displayName: 'example_display_name',
|
|
614
|
-
},
|
|
615
|
-
identities: [
|
|
616
|
-
{
|
|
617
|
-
alias: 'test_alias1',
|
|
618
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
619
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
620
|
-
identifier: {
|
|
621
|
-
type: CorrelationIdentifierType.URL,
|
|
622
|
-
correlationId: 'example_did1',
|
|
623
|
-
},
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
alias: 'test_alias2',
|
|
627
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
628
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
629
|
-
identifier: {
|
|
630
|
-
type: CorrelationIdentifierType.DID,
|
|
631
|
-
correlationId: 'example_did2',
|
|
632
|
-
},
|
|
633
|
-
},
|
|
634
|
-
],
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
await expect(contactStore.addParty(party)).rejects.toThrow(`Identity with correlation type url should contain a connection`)
|
|
638
|
-
})
|
|
639
|
-
|
|
640
|
-
it('should update party by id', async (): Promise<void> => {
|
|
641
|
-
const party: NonPersistedParty = {
|
|
642
|
-
uri: 'example.com',
|
|
643
|
-
partyType: {
|
|
644
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
645
|
-
origin: PartyOrigin.INTERNAL,
|
|
646
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
647
|
-
name: 'example_name',
|
|
648
|
-
},
|
|
649
|
-
contact: {
|
|
650
|
-
firstName: 'example_first_name',
|
|
651
|
-
middleName: 'example_middle_name',
|
|
652
|
-
lastName: 'example_last_name',
|
|
653
|
-
displayName: 'example_display_name',
|
|
654
|
-
},
|
|
655
|
-
}
|
|
656
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
657
|
-
expect(savedParty).toBeDefined()
|
|
658
|
-
|
|
659
|
-
const identity1: NonPersistedIdentity = {
|
|
660
|
-
alias: 'test_alias1',
|
|
661
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
662
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
663
|
-
identifier: {
|
|
664
|
-
type: CorrelationIdentifierType.DID,
|
|
665
|
-
correlationId: 'example_did1',
|
|
666
|
-
},
|
|
667
|
-
}
|
|
668
|
-
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
669
|
-
expect(savedIdentity1).toBeDefined()
|
|
670
|
-
|
|
671
|
-
const identity2: NonPersistedIdentity = {
|
|
672
|
-
alias: 'test_alias2',
|
|
673
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
674
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
675
|
-
identifier: {
|
|
676
|
-
type: CorrelationIdentifierType.DID,
|
|
677
|
-
correlationId: 'example_did2',
|
|
678
|
-
},
|
|
679
|
-
}
|
|
680
|
-
const savedIdentity2: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity2 })
|
|
681
|
-
expect(savedIdentity2).toBeDefined()
|
|
682
|
-
|
|
683
|
-
const contactFirstName = 'updated_first_name'
|
|
684
|
-
const updatedParty: Party = {
|
|
685
|
-
...savedParty,
|
|
686
|
-
contact: {
|
|
687
|
-
...savedParty.contact,
|
|
688
|
-
firstName: contactFirstName,
|
|
689
|
-
},
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
await contactStore.updateParty({ party: updatedParty })
|
|
693
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
694
|
-
|
|
695
|
-
expect(result).toBeDefined()
|
|
696
|
-
expect((<NaturalPerson>result.contact).firstName).toEqual(contactFirstName)
|
|
697
|
-
expect(result.identities.length).toEqual(2)
|
|
698
|
-
})
|
|
699
|
-
|
|
700
|
-
it('should throw error when updating party with unknown id', async (): Promise<void> => {
|
|
701
|
-
const party: NonPersistedParty = {
|
|
702
|
-
uri: 'example.com',
|
|
703
|
-
partyType: {
|
|
704
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
705
|
-
origin: PartyOrigin.INTERNAL,
|
|
706
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
707
|
-
name: 'example_name',
|
|
708
|
-
},
|
|
709
|
-
contact: {
|
|
710
|
-
firstName: 'example_first_name',
|
|
711
|
-
middleName: 'example_middle_name',
|
|
712
|
-
lastName: 'example_last_name',
|
|
713
|
-
displayName: 'example_display_name',
|
|
714
|
-
},
|
|
715
|
-
}
|
|
716
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
717
|
-
expect(savedParty).toBeDefined()
|
|
718
|
-
|
|
719
|
-
const partyId = 'unknownPartyId'
|
|
720
|
-
const contactFirstName = 'updated_first_name'
|
|
721
|
-
const updatedParty: Party = {
|
|
722
|
-
...savedParty,
|
|
723
|
-
id: partyId,
|
|
724
|
-
contact: {
|
|
725
|
-
...savedParty.contact,
|
|
726
|
-
firstName: contactFirstName,
|
|
727
|
-
},
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
await expect(contactStore.updateParty({ party: updatedParty })).rejects.toThrow(`No party found for id: ${partyId}`)
|
|
731
|
-
})
|
|
732
|
-
|
|
733
|
-
it('should get identity by id', async (): Promise<void> => {
|
|
734
|
-
const party: NonPersistedParty = {
|
|
735
|
-
uri: 'example.com',
|
|
736
|
-
partyType: {
|
|
737
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
738
|
-
origin: PartyOrigin.INTERNAL,
|
|
739
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
740
|
-
name: 'example_name',
|
|
741
|
-
},
|
|
742
|
-
contact: {
|
|
743
|
-
firstName: 'example_first_name',
|
|
744
|
-
middleName: 'example_middle_name',
|
|
745
|
-
lastName: 'example_last_name',
|
|
746
|
-
displayName: 'example_display_name',
|
|
747
|
-
},
|
|
748
|
-
}
|
|
749
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
750
|
-
expect(savedParty).toBeDefined()
|
|
751
|
-
|
|
752
|
-
const identity: NonPersistedIdentity = {
|
|
753
|
-
alias: 'test_alias',
|
|
754
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
755
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
756
|
-
identifier: {
|
|
757
|
-
type: CorrelationIdentifierType.DID,
|
|
758
|
-
correlationId: 'example_did',
|
|
759
|
-
},
|
|
760
|
-
}
|
|
761
|
-
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
762
|
-
expect(savedIdentity).toBeDefined()
|
|
763
|
-
|
|
764
|
-
const result: Identity = await contactStore.getIdentity({ identityId: savedIdentity.id })
|
|
765
|
-
|
|
766
|
-
expect(result).toBeDefined()
|
|
767
|
-
})
|
|
768
|
-
|
|
769
|
-
it('should get holderDID identity by id', async (): Promise<void> => {
|
|
770
|
-
const party: NonPersistedParty = {
|
|
771
|
-
uri: 'example.com',
|
|
772
|
-
partyType: {
|
|
773
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
774
|
-
origin: PartyOrigin.INTERNAL,
|
|
775
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
776
|
-
name: 'example_name',
|
|
777
|
-
},
|
|
778
|
-
contact: {
|
|
779
|
-
firstName: 'example_first_name',
|
|
780
|
-
middleName: 'example_middle_name',
|
|
781
|
-
lastName: 'example_last_name',
|
|
782
|
-
displayName: 'example_display_name',
|
|
783
|
-
},
|
|
784
|
-
}
|
|
785
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
786
|
-
expect(savedParty).toBeDefined()
|
|
787
|
-
|
|
788
|
-
const identity: NonPersistedIdentity = {
|
|
789
|
-
alias: 'test_alias',
|
|
790
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
791
|
-
roles: [CredentialRole.HOLDER],
|
|
792
|
-
identifier: {
|
|
793
|
-
type: CorrelationIdentifierType.DID,
|
|
794
|
-
correlationId: 'example_did',
|
|
795
|
-
},
|
|
796
|
-
}
|
|
797
|
-
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
798
|
-
expect(savedIdentity).toBeDefined()
|
|
799
|
-
|
|
800
|
-
const result: Identity = await contactStore.getIdentity({ identityId: savedIdentity.id })
|
|
801
|
-
|
|
802
|
-
expect(result).toBeDefined()
|
|
803
|
-
})
|
|
804
|
-
|
|
805
|
-
it('should throw error when getting identity with unknown id', async (): Promise<void> => {
|
|
806
|
-
const identityId = 'unknownIdentityId'
|
|
807
|
-
|
|
808
|
-
await expect(contactStore.getIdentity({ identityId })).rejects.toThrow(`No identity found for id: ${identityId}`)
|
|
809
|
-
})
|
|
810
|
-
|
|
811
|
-
it('should get all identities for contact', async (): Promise<void> => {
|
|
812
|
-
const party: NonPersistedParty = {
|
|
813
|
-
uri: 'example.com',
|
|
814
|
-
partyType: {
|
|
815
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
816
|
-
origin: PartyOrigin.INTERNAL,
|
|
817
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
818
|
-
name: 'example_name',
|
|
819
|
-
},
|
|
820
|
-
contact: {
|
|
821
|
-
firstName: 'example_first_name',
|
|
822
|
-
middleName: 'example_middle_name',
|
|
823
|
-
lastName: 'example_last_name',
|
|
824
|
-
displayName: 'example_display_name',
|
|
825
|
-
},
|
|
826
|
-
}
|
|
827
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
828
|
-
expect(savedParty).toBeDefined()
|
|
829
|
-
|
|
830
|
-
const identity1: NonPersistedIdentity = {
|
|
831
|
-
alias: 'test_alias1',
|
|
832
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
833
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
834
|
-
identifier: {
|
|
835
|
-
type: CorrelationIdentifierType.DID,
|
|
836
|
-
correlationId: 'example_did1',
|
|
837
|
-
},
|
|
838
|
-
}
|
|
839
|
-
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
840
|
-
expect(savedIdentity1).toBeDefined()
|
|
841
|
-
|
|
842
|
-
const identity2: NonPersistedIdentity = {
|
|
843
|
-
alias: 'test_alias2',
|
|
844
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
845
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
846
|
-
identifier: {
|
|
847
|
-
type: CorrelationIdentifierType.DID,
|
|
848
|
-
correlationId: 'example_did2',
|
|
849
|
-
},
|
|
850
|
-
}
|
|
851
|
-
const savedIdentity2: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity2 })
|
|
852
|
-
expect(savedIdentity2).toBeDefined()
|
|
853
|
-
|
|
854
|
-
const args: GetIdentitiesArgs = {
|
|
855
|
-
filter: [{ partyId: savedParty.id }],
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
const result: Array<Identity> = await contactStore.getIdentities(args)
|
|
859
|
-
|
|
860
|
-
expect(result.length).toEqual(2)
|
|
861
|
-
})
|
|
862
|
-
|
|
863
|
-
it('should get all identities', async (): Promise<void> => {
|
|
864
|
-
const party: NonPersistedParty = {
|
|
865
|
-
uri: 'example.com',
|
|
866
|
-
partyType: {
|
|
867
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
868
|
-
origin: PartyOrigin.INTERNAL,
|
|
869
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
870
|
-
name: 'example_name',
|
|
871
|
-
},
|
|
872
|
-
contact: {
|
|
873
|
-
firstName: 'example_first_name',
|
|
874
|
-
middleName: 'example_middle_name',
|
|
875
|
-
lastName: 'example_last_name',
|
|
876
|
-
displayName: 'example_display_name',
|
|
877
|
-
},
|
|
878
|
-
}
|
|
879
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
880
|
-
expect(savedParty).toBeDefined()
|
|
881
|
-
|
|
882
|
-
const identity1: NonPersistedIdentity = {
|
|
883
|
-
alias: 'test_alias1',
|
|
884
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
885
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
886
|
-
identifier: {
|
|
887
|
-
type: CorrelationIdentifierType.DID,
|
|
888
|
-
correlationId: 'example_did1',
|
|
889
|
-
},
|
|
890
|
-
}
|
|
891
|
-
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
892
|
-
expect(savedIdentity1).toBeDefined()
|
|
893
|
-
|
|
894
|
-
const identity2: NonPersistedIdentity = {
|
|
895
|
-
alias: 'test_alias2',
|
|
896
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
897
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
898
|
-
identifier: {
|
|
899
|
-
type: CorrelationIdentifierType.DID,
|
|
900
|
-
correlationId: 'example_did2',
|
|
901
|
-
},
|
|
902
|
-
}
|
|
903
|
-
const savedIdentity2: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity2 })
|
|
904
|
-
expect(savedIdentity2).toBeDefined()
|
|
905
|
-
|
|
906
|
-
const result: Array<Identity> = await contactStore.getIdentities()
|
|
907
|
-
|
|
908
|
-
expect(result.length).toEqual(2)
|
|
909
|
-
})
|
|
910
|
-
|
|
911
|
-
it('should get identities by filter', async (): Promise<void> => {
|
|
912
|
-
const party: NonPersistedParty = {
|
|
913
|
-
uri: 'example.com',
|
|
914
|
-
partyType: {
|
|
915
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
916
|
-
origin: PartyOrigin.INTERNAL,
|
|
917
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
918
|
-
name: 'example_name',
|
|
919
|
-
},
|
|
920
|
-
contact: {
|
|
921
|
-
firstName: 'example_first_name',
|
|
922
|
-
middleName: 'example_middle_name',
|
|
923
|
-
lastName: 'example_last_name',
|
|
924
|
-
displayName: 'example_display_name',
|
|
925
|
-
},
|
|
926
|
-
}
|
|
927
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
928
|
-
expect(savedParty).toBeDefined()
|
|
929
|
-
|
|
930
|
-
const alias = 'test_alias1'
|
|
931
|
-
const identity1: NonPersistedIdentity = {
|
|
932
|
-
alias,
|
|
933
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
934
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
935
|
-
identifier: {
|
|
936
|
-
type: CorrelationIdentifierType.DID,
|
|
937
|
-
correlationId: 'example_did1',
|
|
938
|
-
},
|
|
939
|
-
}
|
|
940
|
-
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
941
|
-
expect(savedIdentity1).toBeDefined()
|
|
942
|
-
|
|
943
|
-
const identity2: NonPersistedIdentity = {
|
|
944
|
-
alias: 'test_alias2',
|
|
945
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
946
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
947
|
-
identifier: {
|
|
948
|
-
type: CorrelationIdentifierType.DID,
|
|
949
|
-
correlationId: 'example_did2',
|
|
950
|
-
},
|
|
951
|
-
}
|
|
952
|
-
const savedIdentity2: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity2 })
|
|
953
|
-
expect(savedIdentity2).toBeDefined()
|
|
954
|
-
|
|
955
|
-
const args: GetIdentitiesArgs = {
|
|
956
|
-
filter: [{ alias }],
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
const result: Array<Identity> = await contactStore.getIdentities(args)
|
|
960
|
-
|
|
961
|
-
expect(result.length).toEqual(1)
|
|
962
|
-
})
|
|
963
|
-
|
|
964
|
-
it('should get whole identities by filter', async (): Promise<void> => {
|
|
965
|
-
const party: NonPersistedParty = {
|
|
966
|
-
uri: 'example.com',
|
|
967
|
-
partyType: {
|
|
968
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
969
|
-
origin: PartyOrigin.INTERNAL,
|
|
970
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
971
|
-
name: 'example_name',
|
|
972
|
-
},
|
|
973
|
-
contact: {
|
|
974
|
-
firstName: 'example_first_name',
|
|
975
|
-
middleName: 'example_middle_name',
|
|
976
|
-
lastName: 'example_last_name',
|
|
977
|
-
displayName: 'example_display_name',
|
|
978
|
-
},
|
|
979
|
-
}
|
|
980
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
981
|
-
expect(savedParty).toBeDefined()
|
|
982
|
-
|
|
983
|
-
const alias = 'test_alias1'
|
|
984
|
-
const identity1: NonPersistedIdentity = {
|
|
985
|
-
alias,
|
|
986
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
987
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
988
|
-
identifier: {
|
|
989
|
-
type: CorrelationIdentifierType.DID,
|
|
990
|
-
correlationId: 'example_did1',
|
|
991
|
-
},
|
|
992
|
-
metadata: [
|
|
993
|
-
{
|
|
994
|
-
label: 'label1',
|
|
995
|
-
value: 'example_value',
|
|
996
|
-
},
|
|
997
|
-
{
|
|
998
|
-
label: 'label2',
|
|
999
|
-
value: 'example_value',
|
|
1000
|
-
},
|
|
1001
|
-
],
|
|
1002
|
-
}
|
|
1003
|
-
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
1004
|
-
expect(savedIdentity1).toBeDefined()
|
|
1005
|
-
|
|
1006
|
-
const args: GetIdentitiesArgs = {
|
|
1007
|
-
filter: [{ metadata: { label: 'label1', value: 'example_value' } }],
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
const result: Array<Identity> = await contactStore.getIdentities(args)
|
|
1011
|
-
|
|
1012
|
-
expect(result[0]).toBeDefined()
|
|
1013
|
-
expect(result[0].metadata!.length).toEqual(2)
|
|
1014
|
-
})
|
|
1015
|
-
|
|
1016
|
-
it('should add identity to contact', async (): Promise<void> => {
|
|
1017
|
-
const party: NonPersistedParty = {
|
|
1018
|
-
uri: 'example.com',
|
|
1019
|
-
partyType: {
|
|
1020
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1021
|
-
origin: PartyOrigin.INTERNAL,
|
|
1022
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1023
|
-
name: 'example_name',
|
|
1024
|
-
},
|
|
1025
|
-
contact: {
|
|
1026
|
-
firstName: 'example_first_name',
|
|
1027
|
-
middleName: 'example_middle_name',
|
|
1028
|
-
lastName: 'example_last_name',
|
|
1029
|
-
displayName: 'example_display_name',
|
|
1030
|
-
},
|
|
1031
|
-
}
|
|
1032
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
1033
|
-
expect(savedParty).toBeDefined()
|
|
1034
|
-
|
|
1035
|
-
const identity: NonPersistedIdentity = {
|
|
1036
|
-
alias: 'test_alias',
|
|
1037
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
1038
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
1039
|
-
identifier: {
|
|
1040
|
-
type: CorrelationIdentifierType.DID,
|
|
1041
|
-
correlationId: 'example_did',
|
|
1042
|
-
},
|
|
1043
|
-
}
|
|
1044
|
-
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
1045
|
-
expect(savedIdentity).toBeDefined()
|
|
1046
|
-
|
|
1047
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
1048
|
-
expect(result.identities.length).toEqual(1)
|
|
1049
|
-
})
|
|
1050
|
-
|
|
1051
|
-
it('should throw error when removing identity with unknown id', async (): Promise<void> => {
|
|
1052
|
-
const identityId = 'unknownIdentityId'
|
|
1053
|
-
|
|
1054
|
-
await expect(contactStore.removeIdentity({ identityId })).rejects.toThrow(`No identity found for id: ${identityId}`)
|
|
1055
|
-
})
|
|
1056
|
-
|
|
1057
|
-
it('should throw error when adding identity with invalid identifier', async (): Promise<void> => {
|
|
1058
|
-
const party: NonPersistedParty = {
|
|
1059
|
-
uri: 'example.com',
|
|
1060
|
-
partyType: {
|
|
1061
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1062
|
-
origin: PartyOrigin.INTERNAL,
|
|
1063
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1064
|
-
name: 'example_name',
|
|
1065
|
-
},
|
|
1066
|
-
contact: {
|
|
1067
|
-
firstName: 'example_first_name',
|
|
1068
|
-
middleName: 'example_middle_name',
|
|
1069
|
-
lastName: 'example_last_name',
|
|
1070
|
-
displayName: 'example_display_name',
|
|
1071
|
-
},
|
|
1072
|
-
}
|
|
1073
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
1074
|
-
expect(savedParty).toBeDefined()
|
|
1075
|
-
|
|
1076
|
-
const correlationId = 'missing_connection_example'
|
|
1077
|
-
const identity: NonPersistedIdentity = {
|
|
1078
|
-
alias: correlationId,
|
|
1079
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
1080
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
1081
|
-
identifier: {
|
|
1082
|
-
type: CorrelationIdentifierType.URL,
|
|
1083
|
-
correlationId,
|
|
1084
|
-
},
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
await expect(contactStore.addIdentity({ partyId: savedParty.id, identity })).rejects.toThrow(
|
|
1088
|
-
`Identity with correlation type url should contain a connection`,
|
|
1089
|
-
)
|
|
1090
|
-
})
|
|
1091
|
-
|
|
1092
|
-
it('should throw error when updating identity with invalid identifier', async (): Promise<void> => {
|
|
1093
|
-
const party: NonPersistedParty = {
|
|
1094
|
-
uri: 'example.com',
|
|
1095
|
-
partyType: {
|
|
1096
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1097
|
-
origin: PartyOrigin.INTERNAL,
|
|
1098
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1099
|
-
name: 'example_name',
|
|
1100
|
-
},
|
|
1101
|
-
contact: {
|
|
1102
|
-
firstName: 'example_first_name',
|
|
1103
|
-
middleName: 'example_middle_name',
|
|
1104
|
-
lastName: 'example_last_name',
|
|
1105
|
-
displayName: 'example_display_name',
|
|
1106
|
-
},
|
|
1107
|
-
}
|
|
1108
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
1109
|
-
expect(savedParty).toBeDefined()
|
|
1110
|
-
|
|
1111
|
-
const correlationId = 'missing_connection_example'
|
|
1112
|
-
const identity: NonPersistedIdentity = {
|
|
1113
|
-
alias: correlationId,
|
|
1114
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
1115
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER, CredentialRole.HOLDER],
|
|
1116
|
-
identifier: {
|
|
1117
|
-
type: CorrelationIdentifierType.DID,
|
|
1118
|
-
correlationId,
|
|
1119
|
-
},
|
|
1120
|
-
}
|
|
1121
|
-
const storedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
1122
|
-
storedIdentity.identifier = { ...storedIdentity.identifier, type: CorrelationIdentifierType.URL }
|
|
1123
|
-
|
|
1124
|
-
await expect(contactStore.updateIdentity({ identity: storedIdentity })).rejects.toThrow(
|
|
1125
|
-
`Identity with correlation type url should contain a connection`,
|
|
1126
|
-
)
|
|
1127
|
-
})
|
|
1128
|
-
|
|
1129
|
-
it('should update identity by id', async (): Promise<void> => {
|
|
1130
|
-
const party: NonPersistedParty = {
|
|
1131
|
-
uri: 'example.com',
|
|
1132
|
-
partyType: {
|
|
1133
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1134
|
-
origin: PartyOrigin.INTERNAL,
|
|
1135
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1136
|
-
name: 'example_name',
|
|
1137
|
-
},
|
|
1138
|
-
contact: {
|
|
1139
|
-
firstName: 'example_first_name',
|
|
1140
|
-
middleName: 'example_middle_name',
|
|
1141
|
-
lastName: 'example_last_name',
|
|
1142
|
-
displayName: 'example_display_name',
|
|
1143
|
-
},
|
|
1144
|
-
}
|
|
1145
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
1146
|
-
expect(savedParty).toBeDefined()
|
|
1147
|
-
|
|
1148
|
-
const identity: NonPersistedIdentity = {
|
|
1149
|
-
alias: 'example_did',
|
|
1150
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
1151
|
-
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
1152
|
-
identifier: {
|
|
1153
|
-
type: CorrelationIdentifierType.DID,
|
|
1154
|
-
correlationId: 'example_did',
|
|
1155
|
-
},
|
|
1156
|
-
}
|
|
1157
|
-
const storedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
1158
|
-
const correlationId = 'new_update_example_did'
|
|
1159
|
-
storedIdentity.identifier = { ...storedIdentity.identifier, correlationId }
|
|
1160
|
-
|
|
1161
|
-
await contactStore.updateIdentity({ identity: storedIdentity })
|
|
1162
|
-
const result: Identity = await contactStore.getIdentity({ identityId: storedIdentity.id })
|
|
1163
|
-
|
|
1164
|
-
expect(result).toBeDefined()
|
|
1165
|
-
expect(result.identifier.correlationId).toEqual(correlationId)
|
|
1166
|
-
})
|
|
1167
|
-
|
|
1168
|
-
it('should get aggregate of identity roles on party', async (): Promise<void> => {
|
|
1169
|
-
const party: NonPersistedParty = {
|
|
1170
|
-
uri: 'example.com',
|
|
1171
|
-
partyType: {
|
|
1172
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1173
|
-
origin: PartyOrigin.INTERNAL,
|
|
1174
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1175
|
-
name: 'example_name',
|
|
1176
|
-
},
|
|
1177
|
-
contact: {
|
|
1178
|
-
firstName: 'example_first_name',
|
|
1179
|
-
middleName: 'example_middle_name',
|
|
1180
|
-
lastName: 'example_last_name',
|
|
1181
|
-
displayName: 'example_display_name',
|
|
1182
|
-
},
|
|
1183
|
-
identities: [
|
|
1184
|
-
{
|
|
1185
|
-
alias: 'test_alias1',
|
|
1186
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
1187
|
-
roles: [CredentialRole.VERIFIER],
|
|
1188
|
-
identifier: {
|
|
1189
|
-
type: CorrelationIdentifierType.DID,
|
|
1190
|
-
correlationId: 'example_did1',
|
|
1191
|
-
},
|
|
1192
|
-
},
|
|
1193
|
-
{
|
|
1194
|
-
alias: 'test_alias2',
|
|
1195
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
1196
|
-
roles: [CredentialRole.ISSUER],
|
|
1197
|
-
identifier: {
|
|
1198
|
-
type: CorrelationIdentifierType.DID,
|
|
1199
|
-
correlationId: 'example_did2',
|
|
1200
|
-
},
|
|
1201
|
-
},
|
|
1202
|
-
{
|
|
1203
|
-
alias: 'test_alias3',
|
|
1204
|
-
origin: IdentityOrigin.EXTERNAL,
|
|
1205
|
-
roles: [CredentialRole.HOLDER],
|
|
1206
|
-
identifier: {
|
|
1207
|
-
type: CorrelationIdentifierType.DID,
|
|
1208
|
-
correlationId: 'example_did3',
|
|
1209
|
-
},
|
|
1210
|
-
},
|
|
1211
|
-
],
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
1215
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
1216
|
-
|
|
1217
|
-
expect(result.roles).toBeDefined()
|
|
1218
|
-
expect(result.roles.length).toEqual(3)
|
|
1219
|
-
expect(result.roles).toEqual([CredentialRole.VERIFIER, CredentialRole.ISSUER, CredentialRole.HOLDER])
|
|
1220
|
-
})
|
|
1221
|
-
|
|
1222
|
-
it('should add relationship', async (): Promise<void> => {
|
|
1223
|
-
const party1: NonPersistedParty = {
|
|
1224
|
-
uri: 'example1.com',
|
|
1225
|
-
partyType: {
|
|
1226
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1227
|
-
origin: PartyOrigin.INTERNAL,
|
|
1228
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1229
|
-
name: 'example_name1',
|
|
1230
|
-
},
|
|
1231
|
-
contact: {
|
|
1232
|
-
firstName: 'example_first_name1',
|
|
1233
|
-
middleName: 'example_middle_name1',
|
|
1234
|
-
lastName: 'example_last_name1',
|
|
1235
|
-
displayName: 'example_display_name1',
|
|
1236
|
-
},
|
|
1237
|
-
}
|
|
1238
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1239
|
-
expect(savedParty1).toBeDefined()
|
|
1240
|
-
|
|
1241
|
-
const party2: NonPersistedParty = {
|
|
1242
|
-
uri: 'example2.com',
|
|
1243
|
-
partyType: {
|
|
1244
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1245
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1246
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1247
|
-
name: 'example_name2',
|
|
1248
|
-
},
|
|
1249
|
-
contact: {
|
|
1250
|
-
firstName: 'example_first_name2',
|
|
1251
|
-
middleName: 'example_middle_name2',
|
|
1252
|
-
lastName: 'example_last_name2',
|
|
1253
|
-
displayName: 'example_display_name2',
|
|
1254
|
-
},
|
|
1255
|
-
}
|
|
1256
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1257
|
-
expect(savedParty2).toBeDefined()
|
|
1258
|
-
|
|
1259
|
-
const relationship: NonPersistedPartyRelationship = {
|
|
1260
|
-
leftId: savedParty1.id,
|
|
1261
|
-
rightId: savedParty2.id,
|
|
1262
|
-
}
|
|
1263
|
-
await contactStore.addRelationship(relationship)
|
|
1264
|
-
|
|
1265
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty1.id })
|
|
1266
|
-
|
|
1267
|
-
expect(result).toBeDefined()
|
|
1268
|
-
expect(result.relationships.length).toEqual(1)
|
|
1269
|
-
expect(result.relationships[0].leftId).toEqual(savedParty1.id)
|
|
1270
|
-
expect(result.relationships[0].rightId).toEqual(savedParty2.id)
|
|
1271
|
-
})
|
|
1272
|
-
|
|
1273
|
-
it('should get relationship', async (): Promise<void> => {
|
|
1274
|
-
const party1: NonPersistedParty = {
|
|
1275
|
-
uri: 'example1.com',
|
|
1276
|
-
partyType: {
|
|
1277
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1278
|
-
origin: PartyOrigin.INTERNAL,
|
|
1279
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1280
|
-
name: 'example_name1',
|
|
1281
|
-
},
|
|
1282
|
-
contact: {
|
|
1283
|
-
firstName: 'example_first_name1',
|
|
1284
|
-
middleName: 'example_middle_name1',
|
|
1285
|
-
lastName: 'example_last_name1',
|
|
1286
|
-
displayName: 'example_display_name1',
|
|
1287
|
-
},
|
|
1288
|
-
}
|
|
1289
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1290
|
-
expect(savedParty1).toBeDefined()
|
|
1291
|
-
|
|
1292
|
-
const party2: NonPersistedParty = {
|
|
1293
|
-
uri: 'example2.com',
|
|
1294
|
-
partyType: {
|
|
1295
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1296
|
-
origin: PartyOrigin.INTERNAL,
|
|
1297
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1298
|
-
name: 'example_name2',
|
|
1299
|
-
},
|
|
1300
|
-
contact: {
|
|
1301
|
-
firstName: 'example_first_name2',
|
|
1302
|
-
middleName: 'example_middle_name2',
|
|
1303
|
-
lastName: 'example_last_name2',
|
|
1304
|
-
displayName: 'example_display_name2',
|
|
1305
|
-
},
|
|
1306
|
-
}
|
|
1307
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1308
|
-
expect(savedParty2).toBeDefined()
|
|
1309
|
-
|
|
1310
|
-
const relationship: NonPersistedPartyRelationship = {
|
|
1311
|
-
leftId: savedParty1.id,
|
|
1312
|
-
rightId: savedParty2.id,
|
|
1313
|
-
}
|
|
1314
|
-
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1315
|
-
|
|
1316
|
-
const result: PartyRelationship = await contactStore.getRelationship({ relationshipId: savedRelationship.id })
|
|
1317
|
-
|
|
1318
|
-
expect(result).toBeDefined()
|
|
1319
|
-
expect(result.leftId).toEqual(savedParty1.id)
|
|
1320
|
-
expect(result.rightId).toEqual(savedParty2.id)
|
|
1321
|
-
})
|
|
1322
|
-
|
|
1323
|
-
it('should throw error when getting relationship with unknown id', async (): Promise<void> => {
|
|
1324
|
-
const relationshipId = 'unknownRelationshipId'
|
|
1325
|
-
|
|
1326
|
-
await expect(contactStore.getRelationship({ relationshipId })).rejects.toThrow(`No relationship found for id: ${relationshipId}`)
|
|
1327
|
-
})
|
|
1328
|
-
|
|
1329
|
-
it('should get all relationships', async (): Promise<void> => {
|
|
1330
|
-
const party1: NonPersistedParty = {
|
|
1331
|
-
uri: 'example1.com',
|
|
1332
|
-
partyType: {
|
|
1333
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1334
|
-
origin: PartyOrigin.INTERNAL,
|
|
1335
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1336
|
-
name: 'example_name1',
|
|
1337
|
-
},
|
|
1338
|
-
contact: {
|
|
1339
|
-
firstName: 'example_first_name1',
|
|
1340
|
-
middleName: 'example_middle_name1',
|
|
1341
|
-
lastName: 'example_last_name1',
|
|
1342
|
-
displayName: 'example_display_name1',
|
|
1343
|
-
},
|
|
1344
|
-
}
|
|
1345
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1346
|
-
expect(savedParty1).toBeDefined()
|
|
1347
|
-
|
|
1348
|
-
const party2: NonPersistedParty = {
|
|
1349
|
-
uri: 'example2.com',
|
|
1350
|
-
partyType: {
|
|
1351
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1352
|
-
origin: PartyOrigin.INTERNAL,
|
|
1353
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1354
|
-
name: 'example_name2',
|
|
1355
|
-
},
|
|
1356
|
-
contact: {
|
|
1357
|
-
firstName: 'example_first_name2',
|
|
1358
|
-
middleName: 'example_middle_name2',
|
|
1359
|
-
lastName: 'example_last_name2',
|
|
1360
|
-
displayName: 'example_display_name2',
|
|
1361
|
-
},
|
|
1362
|
-
}
|
|
1363
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1364
|
-
expect(savedParty2).toBeDefined()
|
|
1365
|
-
|
|
1366
|
-
const relationship1: NonPersistedPartyRelationship = {
|
|
1367
|
-
leftId: savedParty1.id,
|
|
1368
|
-
rightId: savedParty2.id,
|
|
1369
|
-
}
|
|
1370
|
-
await contactStore.addRelationship(relationship1)
|
|
1371
|
-
|
|
1372
|
-
const relationship2: NonPersistedPartyRelationship = {
|
|
1373
|
-
leftId: savedParty2.id,
|
|
1374
|
-
rightId: savedParty1.id,
|
|
1375
|
-
}
|
|
1376
|
-
await contactStore.addRelationship(relationship2)
|
|
1377
|
-
|
|
1378
|
-
const result: Array<PartyRelationship> = await contactStore.getRelationships()
|
|
1379
|
-
|
|
1380
|
-
expect(result).toBeDefined()
|
|
1381
|
-
expect(result.length).toEqual(2)
|
|
1382
|
-
})
|
|
1383
|
-
|
|
1384
|
-
it('should get relationships by filter', async (): Promise<void> => {
|
|
1385
|
-
const party1: NonPersistedParty = {
|
|
1386
|
-
uri: 'example1.com',
|
|
1387
|
-
partyType: {
|
|
1388
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1389
|
-
origin: PartyOrigin.INTERNAL,
|
|
1390
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1391
|
-
name: 'example_name1',
|
|
1392
|
-
},
|
|
1393
|
-
contact: {
|
|
1394
|
-
firstName: 'example_first_name1',
|
|
1395
|
-
middleName: 'example_middle_name1',
|
|
1396
|
-
lastName: 'example_last_name1',
|
|
1397
|
-
displayName: 'example_display_name1',
|
|
1398
|
-
},
|
|
1399
|
-
}
|
|
1400
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1401
|
-
expect(savedParty1).toBeDefined()
|
|
1402
|
-
|
|
1403
|
-
const party2: NonPersistedParty = {
|
|
1404
|
-
uri: 'example2.com',
|
|
1405
|
-
partyType: {
|
|
1406
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1407
|
-
origin: PartyOrigin.INTERNAL,
|
|
1408
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1409
|
-
name: 'example_name2',
|
|
1410
|
-
},
|
|
1411
|
-
contact: {
|
|
1412
|
-
firstName: 'example_first_name2',
|
|
1413
|
-
middleName: 'example_middle_name2',
|
|
1414
|
-
lastName: 'example_last_name2',
|
|
1415
|
-
displayName: 'example_display_name2',
|
|
1416
|
-
},
|
|
1417
|
-
}
|
|
1418
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1419
|
-
expect(savedParty2).toBeDefined()
|
|
1420
|
-
|
|
1421
|
-
const relationship1: NonPersistedPartyRelationship = {
|
|
1422
|
-
leftId: savedParty1.id,
|
|
1423
|
-
rightId: savedParty2.id,
|
|
1424
|
-
}
|
|
1425
|
-
await contactStore.addRelationship(relationship1)
|
|
1426
|
-
|
|
1427
|
-
const relationship2: NonPersistedPartyRelationship = {
|
|
1428
|
-
leftId: savedParty2.id,
|
|
1429
|
-
rightId: savedParty1.id,
|
|
1430
|
-
}
|
|
1431
|
-
await contactStore.addRelationship(relationship2)
|
|
1432
|
-
|
|
1433
|
-
const args: GetRelationshipsArgs = {
|
|
1434
|
-
filter: [
|
|
1435
|
-
{
|
|
1436
|
-
leftId: savedParty1.id,
|
|
1437
|
-
rightId: savedParty2.id,
|
|
1438
|
-
},
|
|
1439
|
-
],
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
const result: Array<PartyRelationship> = await contactStore.getRelationships(args)
|
|
1443
|
-
|
|
1444
|
-
expect(result).toBeDefined()
|
|
1445
|
-
expect(result.length).toEqual(1)
|
|
1446
|
-
})
|
|
1447
|
-
|
|
1448
|
-
it('should remove relationship', async (): Promise<void> => {
|
|
1449
|
-
const party1: NonPersistedParty = {
|
|
1450
|
-
uri: 'example1.com',
|
|
1451
|
-
partyType: {
|
|
1452
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1453
|
-
origin: PartyOrigin.INTERNAL,
|
|
1454
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1455
|
-
name: 'example_name1',
|
|
1456
|
-
},
|
|
1457
|
-
contact: {
|
|
1458
|
-
firstName: 'example_first_name1',
|
|
1459
|
-
middleName: 'example_middle_name1',
|
|
1460
|
-
lastName: 'example_last_name1',
|
|
1461
|
-
displayName: 'example_display_name1',
|
|
1462
|
-
},
|
|
1463
|
-
}
|
|
1464
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1465
|
-
expect(savedParty1).toBeDefined()
|
|
1466
|
-
|
|
1467
|
-
const party2: NonPersistedParty = {
|
|
1468
|
-
uri: 'example2.com',
|
|
1469
|
-
partyType: {
|
|
1470
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1471
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1472
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1473
|
-
name: 'example_name2',
|
|
1474
|
-
},
|
|
1475
|
-
contact: {
|
|
1476
|
-
firstName: 'example_first_name2',
|
|
1477
|
-
middleName: 'example_middle_name2',
|
|
1478
|
-
lastName: 'example_last_name2',
|
|
1479
|
-
displayName: 'example_display_name2',
|
|
1480
|
-
},
|
|
1481
|
-
}
|
|
1482
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1483
|
-
expect(savedParty2).toBeDefined()
|
|
1484
|
-
|
|
1485
|
-
const relationship: NonPersistedPartyRelationship = {
|
|
1486
|
-
leftId: savedParty1.id,
|
|
1487
|
-
rightId: savedParty2.id,
|
|
1488
|
-
}
|
|
1489
|
-
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1490
|
-
expect(savedRelationship).toBeDefined()
|
|
1491
|
-
|
|
1492
|
-
await contactStore.removeRelationship({ relationshipId: savedRelationship.id })
|
|
1493
|
-
|
|
1494
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty1.id })
|
|
1495
|
-
|
|
1496
|
-
expect(result).toBeDefined()
|
|
1497
|
-
expect(result?.relationships?.length).toEqual(0)
|
|
1498
|
-
})
|
|
1499
|
-
|
|
1500
|
-
it('should throw error when removing relationship with unknown id', async (): Promise<void> => {
|
|
1501
|
-
const relationshipId = 'unknownRelationshipId'
|
|
1502
|
-
|
|
1503
|
-
await expect(contactStore.removeRelationship({ relationshipId })).rejects.toThrow(`No relationship found for id: ${relationshipId}`)
|
|
1504
|
-
})
|
|
1505
|
-
|
|
1506
|
-
it('should return no relationships if filter does not match', async (): Promise<void> => {
|
|
1507
|
-
const args: GetRelationshipsArgs = {
|
|
1508
|
-
filter: [
|
|
1509
|
-
{
|
|
1510
|
-
leftId: 'unknown_id',
|
|
1511
|
-
},
|
|
1512
|
-
],
|
|
1513
|
-
}
|
|
1514
|
-
const result: Array<PartyRelationship> = await contactStore.getRelationships(args)
|
|
1515
|
-
|
|
1516
|
-
expect(result.length).toEqual(0)
|
|
1517
|
-
})
|
|
1518
|
-
|
|
1519
|
-
it('should update relationship by id', async (): Promise<void> => {
|
|
1520
|
-
const party1: NonPersistedParty = {
|
|
1521
|
-
uri: 'example1.com',
|
|
1522
|
-
partyType: {
|
|
1523
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1524
|
-
origin: PartyOrigin.INTERNAL,
|
|
1525
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1526
|
-
name: 'example_name1',
|
|
1527
|
-
},
|
|
1528
|
-
contact: {
|
|
1529
|
-
firstName: 'example_first_name1',
|
|
1530
|
-
middleName: 'example_middle_name1',
|
|
1531
|
-
lastName: 'example_last_name1',
|
|
1532
|
-
displayName: 'example_display_name1',
|
|
1533
|
-
},
|
|
1534
|
-
}
|
|
1535
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1536
|
-
expect(savedParty1).toBeDefined()
|
|
1537
|
-
|
|
1538
|
-
const party2: NonPersistedParty = {
|
|
1539
|
-
uri: 'example2.com',
|
|
1540
|
-
partyType: {
|
|
1541
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1542
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1543
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1544
|
-
name: 'example_name2',
|
|
1545
|
-
},
|
|
1546
|
-
contact: {
|
|
1547
|
-
firstName: 'example_first_name2',
|
|
1548
|
-
middleName: 'example_middle_name2',
|
|
1549
|
-
lastName: 'example_last_name2',
|
|
1550
|
-
displayName: 'example_display_name2',
|
|
1551
|
-
},
|
|
1552
|
-
}
|
|
1553
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1554
|
-
expect(savedParty2).toBeDefined()
|
|
1555
|
-
|
|
1556
|
-
const party3: NonPersistedParty = {
|
|
1557
|
-
uri: 'example3.com',
|
|
1558
|
-
partyType: {
|
|
1559
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1560
|
-
origin: PartyOrigin.INTERNAL,
|
|
1561
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287',
|
|
1562
|
-
name: 'example_name3',
|
|
1563
|
-
},
|
|
1564
|
-
contact: {
|
|
1565
|
-
firstName: 'example_first_name3',
|
|
1566
|
-
middleName: 'example_middle_name3',
|
|
1567
|
-
lastName: 'example_last_name3',
|
|
1568
|
-
displayName: 'example_display_name3',
|
|
1569
|
-
},
|
|
1570
|
-
}
|
|
1571
|
-
const savedParty3: Party = await contactStore.addParty(party3)
|
|
1572
|
-
expect(savedParty3).toBeDefined()
|
|
1573
|
-
|
|
1574
|
-
const relationship: NonPersistedPartyRelationship = {
|
|
1575
|
-
leftId: savedParty1.id,
|
|
1576
|
-
rightId: savedParty2.id,
|
|
1577
|
-
}
|
|
1578
|
-
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1579
|
-
|
|
1580
|
-
const updatedRelationship: PartyRelationship = {
|
|
1581
|
-
...savedRelationship,
|
|
1582
|
-
rightId: savedParty3.id,
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
await contactStore.updateRelationship({ relationship: updatedRelationship })
|
|
1586
|
-
|
|
1587
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty1.id })
|
|
1588
|
-
|
|
1589
|
-
expect(result).toBeDefined()
|
|
1590
|
-
expect(result.relationships.length).toEqual(1)
|
|
1591
|
-
expect(result.relationships[0].leftId).toEqual(savedParty1.id)
|
|
1592
|
-
expect(result.relationships[0].rightId).toEqual(savedParty3.id)
|
|
1593
|
-
})
|
|
1594
|
-
|
|
1595
|
-
it('should throw error when updating relationship with unknown id', async (): Promise<void> => {
|
|
1596
|
-
const party1: NonPersistedParty = {
|
|
1597
|
-
uri: 'example1.com',
|
|
1598
|
-
partyType: {
|
|
1599
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1600
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1601
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1602
|
-
name: 'example_name1',
|
|
1603
|
-
},
|
|
1604
|
-
contact: {
|
|
1605
|
-
firstName: 'example_first_name1',
|
|
1606
|
-
middleName: 'example_middle_name1',
|
|
1607
|
-
lastName: 'example_last_name1',
|
|
1608
|
-
displayName: 'example_display_name1',
|
|
1609
|
-
},
|
|
1610
|
-
}
|
|
1611
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1612
|
-
expect(savedParty1).toBeDefined()
|
|
1613
|
-
|
|
1614
|
-
const party2: NonPersistedParty = {
|
|
1615
|
-
uri: 'example2.com',
|
|
1616
|
-
partyType: {
|
|
1617
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1618
|
-
origin: PartyOrigin.INTERNAL,
|
|
1619
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1620
|
-
name: 'example_name2',
|
|
1621
|
-
},
|
|
1622
|
-
contact: {
|
|
1623
|
-
firstName: 'example_first_name2',
|
|
1624
|
-
middleName: 'example_middle_name2',
|
|
1625
|
-
lastName: 'example_last_name2',
|
|
1626
|
-
displayName: 'example_display_name2',
|
|
1627
|
-
},
|
|
1628
|
-
}
|
|
1629
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1630
|
-
expect(savedParty2).toBeDefined()
|
|
1631
|
-
|
|
1632
|
-
const relationship: NonPersistedPartyRelationship = {
|
|
1633
|
-
leftId: savedParty1.id,
|
|
1634
|
-
rightId: savedParty2.id,
|
|
1635
|
-
}
|
|
1636
|
-
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1637
|
-
|
|
1638
|
-
const relationshipId = 'unknownRelationshipId'
|
|
1639
|
-
const updatedRelationship: PartyRelationship = {
|
|
1640
|
-
...savedRelationship,
|
|
1641
|
-
id: relationshipId,
|
|
1642
|
-
rightId: savedParty2.id,
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
await expect(contactStore.updateRelationship({ relationship: updatedRelationship })).rejects.toThrow(
|
|
1646
|
-
`No party relationship found for id: ${relationshipId}`,
|
|
1647
|
-
)
|
|
1648
|
-
})
|
|
1649
|
-
|
|
1650
|
-
it('should throw error when updating relationship with unknown right side id', async (): Promise<void> => {
|
|
1651
|
-
const party1: NonPersistedParty = {
|
|
1652
|
-
uri: 'example1.com',
|
|
1653
|
-
partyType: {
|
|
1654
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1655
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1656
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1657
|
-
name: 'example_name1',
|
|
1658
|
-
},
|
|
1659
|
-
contact: {
|
|
1660
|
-
firstName: 'example_first_name1',
|
|
1661
|
-
middleName: 'example_middle_name1',
|
|
1662
|
-
lastName: 'example_last_name1',
|
|
1663
|
-
displayName: 'example_display_name1',
|
|
1664
|
-
},
|
|
1665
|
-
}
|
|
1666
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1667
|
-
expect(savedParty1).toBeDefined()
|
|
1668
|
-
|
|
1669
|
-
const party2: NonPersistedParty = {
|
|
1670
|
-
uri: 'example2.com',
|
|
1671
|
-
partyType: {
|
|
1672
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1673
|
-
origin: PartyOrigin.INTERNAL,
|
|
1674
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1675
|
-
name: 'example_name2',
|
|
1676
|
-
},
|
|
1677
|
-
contact: {
|
|
1678
|
-
firstName: 'example_first_name2',
|
|
1679
|
-
middleName: 'example_middle_name2',
|
|
1680
|
-
lastName: 'example_last_name2',
|
|
1681
|
-
displayName: 'example_display_name2',
|
|
1682
|
-
},
|
|
1683
|
-
}
|
|
1684
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1685
|
-
expect(savedParty2).toBeDefined()
|
|
1686
|
-
|
|
1687
|
-
const relationship: NonPersistedPartyRelationship = {
|
|
1688
|
-
leftId: savedParty1.id,
|
|
1689
|
-
rightId: savedParty2.id,
|
|
1690
|
-
}
|
|
1691
|
-
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1692
|
-
|
|
1693
|
-
const partyId = 'unknownPartyId'
|
|
1694
|
-
const updatedRelationship: PartyRelationship = {
|
|
1695
|
-
...savedRelationship,
|
|
1696
|
-
rightId: partyId,
|
|
1697
|
-
}
|
|
1698
|
-
|
|
1699
|
-
await expect(contactStore.updateRelationship({ relationship: updatedRelationship })).rejects.toThrow(
|
|
1700
|
-
`No party found for right side of the relationship, party id: ${partyId}`,
|
|
1701
|
-
)
|
|
1702
|
-
})
|
|
1703
|
-
|
|
1704
|
-
it('should throw error when updating relationship with unknown left side id', async (): Promise<void> => {
|
|
1705
|
-
const party1: NonPersistedParty = {
|
|
1706
|
-
uri: 'example1.com',
|
|
1707
|
-
partyType: {
|
|
1708
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1709
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1710
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1711
|
-
name: 'example_name1',
|
|
1712
|
-
},
|
|
1713
|
-
contact: {
|
|
1714
|
-
firstName: 'example_first_name1',
|
|
1715
|
-
middleName: 'example_middle_name1',
|
|
1716
|
-
lastName: 'example_last_name1',
|
|
1717
|
-
displayName: 'example_display_name1',
|
|
1718
|
-
},
|
|
1719
|
-
}
|
|
1720
|
-
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1721
|
-
expect(savedParty1).toBeDefined()
|
|
1722
|
-
|
|
1723
|
-
const party2: NonPersistedParty = {
|
|
1724
|
-
uri: 'example2.com',
|
|
1725
|
-
partyType: {
|
|
1726
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1727
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1728
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1729
|
-
name: 'example_name2',
|
|
1730
|
-
},
|
|
1731
|
-
contact: {
|
|
1732
|
-
firstName: 'example_first_name2',
|
|
1733
|
-
middleName: 'example_middle_name2',
|
|
1734
|
-
lastName: 'example_last_name2',
|
|
1735
|
-
displayName: 'example_display_name2',
|
|
1736
|
-
},
|
|
1737
|
-
}
|
|
1738
|
-
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1739
|
-
expect(savedParty2).toBeDefined()
|
|
1740
|
-
|
|
1741
|
-
const relationship: NonPersistedPartyRelationship = {
|
|
1742
|
-
leftId: savedParty1.id,
|
|
1743
|
-
rightId: savedParty2.id,
|
|
1744
|
-
}
|
|
1745
|
-
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1746
|
-
|
|
1747
|
-
const partyId = 'unknownPartyId'
|
|
1748
|
-
const updatedRelationship: PartyRelationship = {
|
|
1749
|
-
...savedRelationship,
|
|
1750
|
-
leftId: partyId,
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
await expect(contactStore.updateRelationship({ relationship: updatedRelationship })).rejects.toThrow(
|
|
1754
|
-
`No party found for left side of the relationship, party id: ${partyId}`,
|
|
1755
|
-
)
|
|
1756
|
-
})
|
|
1757
|
-
|
|
1758
|
-
it('should add party type', async (): Promise<void> => {
|
|
1759
|
-
const partyType: NonPersistedPartyType = {
|
|
1760
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1761
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1762
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1763
|
-
name: 'example_name',
|
|
1764
|
-
description: 'example_description',
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1768
|
-
const result: PartyType = await contactStore.getPartyType({ partyTypeId: savedPartyType.id })
|
|
1769
|
-
|
|
1770
|
-
expect(result).toBeDefined()
|
|
1771
|
-
expect(result.name).toEqual(partyType.name)
|
|
1772
|
-
expect(result.type).toEqual(partyType.type)
|
|
1773
|
-
expect(result.origin).toEqual(partyType.origin)
|
|
1774
|
-
expect(result.tenantId).toEqual(partyType.tenantId)
|
|
1775
|
-
expect(result.description).toEqual(partyType.description)
|
|
1776
|
-
expect(result.lastUpdatedAt).toBeDefined()
|
|
1777
|
-
expect(result.createdAt).toBeDefined()
|
|
1778
|
-
})
|
|
1779
|
-
|
|
1780
|
-
it('should get party types by filter', async (): Promise<void> => {
|
|
1781
|
-
const partyType1: NonPersistedPartyType = {
|
|
1782
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1783
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1784
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1785
|
-
name: 'example_name1',
|
|
1786
|
-
description: 'example_description1',
|
|
1787
|
-
}
|
|
1788
|
-
const savedPartyType1: PartyType = await contactStore.addPartyType(partyType1)
|
|
1789
|
-
expect(savedPartyType1).toBeDefined()
|
|
1790
|
-
|
|
1791
|
-
const partyType2: NonPersistedPartyType = {
|
|
1792
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1793
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1794
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287',
|
|
1795
|
-
name: 'example_name2',
|
|
1796
|
-
description: 'example_description2',
|
|
1797
|
-
}
|
|
1798
|
-
const savedPartyType2: PartyType = await contactStore.addPartyType(partyType2)
|
|
1799
|
-
expect(savedPartyType2).toBeDefined()
|
|
1800
|
-
|
|
1801
|
-
const result: Array<PartyType> = await contactStore.getPartyTypes({
|
|
1802
|
-
filter: [
|
|
1803
|
-
{
|
|
1804
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1805
|
-
name: 'example_name1',
|
|
1806
|
-
description: 'example_description1',
|
|
1807
|
-
},
|
|
1808
|
-
],
|
|
1809
|
-
})
|
|
1810
|
-
|
|
1811
|
-
expect(result).toBeDefined()
|
|
1812
|
-
expect(result.length).toEqual(1)
|
|
1813
|
-
})
|
|
1814
|
-
|
|
1815
|
-
it('should return no party types if filter does not match', async (): Promise<void> => {
|
|
1816
|
-
const partyType1: NonPersistedPartyType = {
|
|
1817
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1818
|
-
origin: PartyOrigin.INTERNAL,
|
|
1819
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1820
|
-
name: 'example_name1',
|
|
1821
|
-
description: 'example_description1',
|
|
1822
|
-
}
|
|
1823
|
-
const savedPartyType1: PartyType = await contactStore.addPartyType(partyType1)
|
|
1824
|
-
expect(savedPartyType1).toBeDefined()
|
|
1825
|
-
|
|
1826
|
-
const partyType2: NonPersistedPartyType = {
|
|
1827
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1828
|
-
origin: PartyOrigin.INTERNAL,
|
|
1829
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287',
|
|
1830
|
-
name: 'example_name2',
|
|
1831
|
-
description: 'example_description2',
|
|
1832
|
-
}
|
|
1833
|
-
const savedPartyType2: PartyType = await contactStore.addPartyType(partyType2)
|
|
1834
|
-
expect(savedPartyType2).toBeDefined()
|
|
1835
|
-
|
|
1836
|
-
const result: Array<PartyType> = await contactStore.getPartyTypes({
|
|
1837
|
-
filter: [
|
|
1838
|
-
{
|
|
1839
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1840
|
-
name: 'unknown_name',
|
|
1841
|
-
description: 'unknown_description',
|
|
1842
|
-
},
|
|
1843
|
-
],
|
|
1844
|
-
})
|
|
1845
|
-
|
|
1846
|
-
expect(result).toBeDefined()
|
|
1847
|
-
expect(result.length).toEqual(0)
|
|
1848
|
-
})
|
|
1849
|
-
|
|
1850
|
-
it('should throw error when updating party type with unknown id', async (): Promise<void> => {
|
|
1851
|
-
const partyType: NonPersistedPartyType = {
|
|
1852
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1853
|
-
origin: PartyOrigin.INTERNAL,
|
|
1854
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1855
|
-
name: 'example_name',
|
|
1856
|
-
description: 'example_description',
|
|
1857
|
-
}
|
|
1858
|
-
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1859
|
-
expect(savedPartyType).toBeDefined()
|
|
1860
|
-
|
|
1861
|
-
const partyTypeId = 'unknownPartyTypeId'
|
|
1862
|
-
const updatedPartyType: PartyType = {
|
|
1863
|
-
...savedPartyType,
|
|
1864
|
-
id: partyTypeId,
|
|
1865
|
-
description: 'new_example_description',
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
await expect(contactStore.updatePartyType({ partyType: updatedPartyType })).rejects.toThrow(`No party type found for id: ${partyTypeId}`)
|
|
1869
|
-
})
|
|
1870
|
-
|
|
1871
|
-
it('should update party type by id', async (): Promise<void> => {
|
|
1872
|
-
const partyType: NonPersistedPartyType = {
|
|
1873
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1874
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1875
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1876
|
-
name: 'example_name',
|
|
1877
|
-
description: 'example_description',
|
|
1878
|
-
}
|
|
1879
|
-
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1880
|
-
expect(savedPartyType).toBeDefined()
|
|
1881
|
-
|
|
1882
|
-
const newDescription = 'new_example_description'
|
|
1883
|
-
const updatedPartyType: PartyType = {
|
|
1884
|
-
...savedPartyType,
|
|
1885
|
-
description: newDescription,
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
const result: PartyType = await contactStore.updatePartyType({ partyType: updatedPartyType })
|
|
1889
|
-
|
|
1890
|
-
expect(result).toBeDefined()
|
|
1891
|
-
expect(result.description).toEqual(newDescription)
|
|
1892
|
-
})
|
|
1893
|
-
|
|
1894
|
-
it('should throw error when removing party type with unknown id', async (): Promise<void> => {
|
|
1895
|
-
const partyTypeId = 'unknownPartyTypeId'
|
|
1896
|
-
|
|
1897
|
-
await expect(contactStore.removePartyType({ partyTypeId })).rejects.toThrow(`No party type found for id: ${partyTypeId}`)
|
|
1898
|
-
})
|
|
1899
|
-
|
|
1900
|
-
it('should remove party type', async (): Promise<void> => {
|
|
1901
|
-
const partyType: NonPersistedPartyType = {
|
|
1902
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1903
|
-
origin: PartyOrigin.INTERNAL,
|
|
1904
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1905
|
-
name: 'example_name',
|
|
1906
|
-
description: 'example_description',
|
|
1907
|
-
}
|
|
1908
|
-
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1909
|
-
expect(savedPartyType).toBeDefined()
|
|
1910
|
-
|
|
1911
|
-
const resultPartyType: PartyType = await contactStore.getPartyType({ partyTypeId: savedPartyType.id })
|
|
1912
|
-
expect(resultPartyType).toBeDefined()
|
|
1913
|
-
|
|
1914
|
-
const includingMigrationPartyTypes: Array<PartyType> = await contactStore.getPartyTypes()
|
|
1915
|
-
// We are checking for 3 types here as we include the ones from the migrations
|
|
1916
|
-
expect(includingMigrationPartyTypes.length).toEqual(3)
|
|
1917
|
-
|
|
1918
|
-
await contactStore.removePartyType({ partyTypeId: savedPartyType.id })
|
|
1919
|
-
|
|
1920
|
-
const result: Array<PartyType> = await contactStore.getPartyTypes()
|
|
1921
|
-
|
|
1922
|
-
expect(result).toBeDefined()
|
|
1923
|
-
expect(result.length).toEqual(2)
|
|
1924
|
-
})
|
|
1925
|
-
|
|
1926
|
-
it('should throw error when removing party type attached to contact', async (): Promise<void> => {
|
|
1927
|
-
const party: NonPersistedParty = {
|
|
1928
|
-
uri: 'example.com',
|
|
1929
|
-
partyType: {
|
|
1930
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1931
|
-
origin: PartyOrigin.EXTERNAL,
|
|
1932
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1933
|
-
name: 'example_name',
|
|
1934
|
-
},
|
|
1935
|
-
contact: {
|
|
1936
|
-
firstName: 'example_first_name',
|
|
1937
|
-
middleName: 'example_middle_name',
|
|
1938
|
-
lastName: 'example_last_name',
|
|
1939
|
-
displayName: 'example_display_name',
|
|
1940
|
-
},
|
|
1941
|
-
}
|
|
1942
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
1943
|
-
expect(savedParty).toBeDefined()
|
|
1944
|
-
|
|
1945
|
-
await expect(contactStore.removePartyType({ partyTypeId: savedParty.partyType.id })).rejects.toThrow(
|
|
1946
|
-
`Unable to remove party type with id: ${savedParty.partyType.id}. Party type is in use`,
|
|
1947
|
-
)
|
|
1948
|
-
})
|
|
1949
|
-
|
|
1950
|
-
it('Should save party with existing party type', async (): Promise<void> => {
|
|
1951
|
-
const partyType: NonPersistedPartyType = {
|
|
1952
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
1953
|
-
origin: PartyOrigin.INTERNAL,
|
|
1954
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1955
|
-
name: 'example_name',
|
|
1956
|
-
}
|
|
1957
|
-
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1958
|
-
expect(savedPartyType).toBeDefined()
|
|
1959
|
-
|
|
1960
|
-
const party: NonPersistedParty = {
|
|
1961
|
-
uri: 'example.com',
|
|
1962
|
-
partyType: savedPartyType,
|
|
1963
|
-
contact: {
|
|
1964
|
-
firstName: 'example_first_name',
|
|
1965
|
-
middleName: 'example_middle_name',
|
|
1966
|
-
lastName: 'example_last_name',
|
|
1967
|
-
displayName: 'example_display_name',
|
|
1968
|
-
},
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
const result: Party = await contactStore.addParty(party)
|
|
1972
|
-
|
|
1973
|
-
expect(result).toBeDefined()
|
|
1974
|
-
expect(result?.partyType).toBeDefined()
|
|
1975
|
-
expect(result?.partyType.id).toEqual(savedPartyType.id)
|
|
1976
|
-
expect(result?.partyType.type).toEqual(savedPartyType.type)
|
|
1977
|
-
expect(result?.partyType.origin).toEqual(savedPartyType.origin)
|
|
1978
|
-
expect(result?.partyType.tenantId).toEqual(savedPartyType.tenantId)
|
|
1979
|
-
expect(result?.partyType.name).toEqual(savedPartyType.name)
|
|
1980
|
-
})
|
|
1981
|
-
|
|
1982
|
-
it('should throw error when adding person party with wrong contact type', async (): Promise<void> => {
|
|
1983
|
-
const partyType = PartyTypeType.ORGANIZATION
|
|
1984
|
-
const partyTypeOrigin = PartyOrigin.INTERNAL
|
|
1985
|
-
const party: NonPersistedParty = {
|
|
1986
|
-
uri: 'example.com',
|
|
1987
|
-
partyType: {
|
|
1988
|
-
type: partyType,
|
|
1989
|
-
origin: partyTypeOrigin,
|
|
1990
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1991
|
-
name: 'example_name',
|
|
1992
|
-
},
|
|
1993
|
-
contact: {
|
|
1994
|
-
firstName: 'example_first_name',
|
|
1995
|
-
middleName: 'example_middle_name',
|
|
1996
|
-
lastName: 'example_last_name',
|
|
1997
|
-
displayName: 'example_display_name',
|
|
1998
|
-
},
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
|
-
await expect(contactStore.addParty(party)).rejects.toThrow(`Party type ${partyType}, does not match for provided contact`)
|
|
2002
|
-
})
|
|
2003
|
-
|
|
2004
|
-
it('should throw error when adding organization party with wrong contact type', async (): Promise<void> => {
|
|
2005
|
-
const partyType = PartyTypeType.NATURAL_PERSON
|
|
2006
|
-
const partyTypeOrigin = PartyOrigin.EXTERNAL
|
|
2007
|
-
const party: NonPersistedParty = {
|
|
2008
|
-
uri: 'example.com',
|
|
2009
|
-
partyType: {
|
|
2010
|
-
type: partyType,
|
|
2011
|
-
origin: partyTypeOrigin,
|
|
2012
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2013
|
-
name: 'example_name',
|
|
2014
|
-
},
|
|
2015
|
-
contact: {
|
|
2016
|
-
legalName: 'example_legal_name',
|
|
2017
|
-
displayName: 'example_display_name',
|
|
2018
|
-
},
|
|
2019
|
-
}
|
|
2020
|
-
|
|
2021
|
-
await expect(contactStore.addParty(party)).rejects.toThrow(`Party type ${partyType}, does not match for provided contact`)
|
|
2022
|
-
})
|
|
2023
|
-
|
|
2024
|
-
it('should get electronic address by id', async (): Promise<void> => {
|
|
2025
|
-
const party: NonPersistedParty = {
|
|
2026
|
-
uri: 'example.com',
|
|
2027
|
-
partyType: {
|
|
2028
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2029
|
-
origin: PartyOrigin.INTERNAL,
|
|
2030
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2031
|
-
name: 'example_name',
|
|
2032
|
-
},
|
|
2033
|
-
contact: {
|
|
2034
|
-
firstName: 'example_first_name',
|
|
2035
|
-
middleName: 'example_middle_name',
|
|
2036
|
-
lastName: 'example_last_name',
|
|
2037
|
-
displayName: 'example_display_name',
|
|
2038
|
-
},
|
|
2039
|
-
}
|
|
2040
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2041
|
-
expect(savedParty).toBeDefined()
|
|
2042
|
-
|
|
2043
|
-
const electronicAddress: NonPersistedElectronicAddress = {
|
|
2044
|
-
type: 'email',
|
|
2045
|
-
electronicAddress: 'example_electronic_address',
|
|
2046
|
-
}
|
|
2047
|
-
const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
|
|
2048
|
-
expect(savedElectronicAddress).toBeDefined()
|
|
2049
|
-
|
|
2050
|
-
const result: ElectronicAddress = await contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
|
|
2051
|
-
|
|
2052
|
-
expect(result).toBeDefined()
|
|
2053
|
-
})
|
|
2054
|
-
|
|
2055
|
-
it('should throw error when getting electronic address with unknown id', async (): Promise<void> => {
|
|
2056
|
-
const electronicAddressId = 'unknownElectronicAddressId'
|
|
2057
|
-
|
|
2058
|
-
await expect(contactStore.getElectronicAddress({ electronicAddressId })).rejects.toThrow(
|
|
2059
|
-
`No electronic address found for id: ${electronicAddressId}`,
|
|
2060
|
-
)
|
|
2061
|
-
})
|
|
2062
|
-
|
|
2063
|
-
it('should get all electronic addresses for contact', async (): Promise<void> => {
|
|
2064
|
-
const party: NonPersistedParty = {
|
|
2065
|
-
uri: 'example.com',
|
|
2066
|
-
partyType: {
|
|
2067
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2068
|
-
origin: PartyOrigin.EXTERNAL,
|
|
2069
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2070
|
-
name: 'example_name',
|
|
2071
|
-
},
|
|
2072
|
-
contact: {
|
|
2073
|
-
firstName: 'example_first_name',
|
|
2074
|
-
middleName: 'example_middle_name',
|
|
2075
|
-
lastName: 'example_last_name',
|
|
2076
|
-
displayName: 'example_display_name',
|
|
2077
|
-
},
|
|
2078
|
-
}
|
|
2079
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2080
|
-
expect(savedParty).toBeDefined()
|
|
2081
|
-
|
|
2082
|
-
const electronicAddress1: NonPersistedElectronicAddress = {
|
|
2083
|
-
type: 'email',
|
|
2084
|
-
electronicAddress: 'example_electronic_address1',
|
|
2085
|
-
}
|
|
2086
|
-
const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2087
|
-
partyId: savedParty.id,
|
|
2088
|
-
electronicAddress: electronicAddress1,
|
|
2089
|
-
})
|
|
2090
|
-
expect(savedElectronicAddress1).toBeDefined()
|
|
2091
|
-
|
|
2092
|
-
const electronicAddress2: NonPersistedElectronicAddress = {
|
|
2093
|
-
type: 'email',
|
|
2094
|
-
electronicAddress: 'example_electronic_address2',
|
|
2095
|
-
}
|
|
2096
|
-
const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2097
|
-
partyId: savedParty.id,
|
|
2098
|
-
electronicAddress: electronicAddress2,
|
|
2099
|
-
})
|
|
2100
|
-
expect(savedElectronicAddress2).toBeDefined()
|
|
2101
|
-
|
|
2102
|
-
const args: GetElectronicAddressesArgs = {
|
|
2103
|
-
filter: [{ partyId: savedParty.id }],
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
|
-
const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses(args)
|
|
2107
|
-
|
|
2108
|
-
expect(result.length).toEqual(2)
|
|
2109
|
-
})
|
|
2110
|
-
|
|
2111
|
-
it('should get all electronic addresses', async (): Promise<void> => {
|
|
2112
|
-
const party: NonPersistedParty = {
|
|
2113
|
-
uri: 'example.com',
|
|
2114
|
-
partyType: {
|
|
2115
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2116
|
-
origin: PartyOrigin.INTERNAL,
|
|
2117
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2118
|
-
name: 'example_name',
|
|
2119
|
-
},
|
|
2120
|
-
contact: {
|
|
2121
|
-
firstName: 'example_first_name',
|
|
2122
|
-
middleName: 'example_middle_name',
|
|
2123
|
-
lastName: 'example_last_name',
|
|
2124
|
-
displayName: 'example_display_name',
|
|
2125
|
-
},
|
|
2126
|
-
}
|
|
2127
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2128
|
-
expect(savedParty).toBeDefined()
|
|
2129
|
-
|
|
2130
|
-
const electronicAddress1: NonPersistedElectronicAddress = {
|
|
2131
|
-
type: 'email',
|
|
2132
|
-
electronicAddress: 'example_electronic_address1',
|
|
2133
|
-
}
|
|
2134
|
-
const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2135
|
-
partyId: savedParty.id,
|
|
2136
|
-
electronicAddress: electronicAddress1,
|
|
2137
|
-
})
|
|
2138
|
-
expect(savedElectronicAddress1).toBeDefined()
|
|
2139
|
-
|
|
2140
|
-
const electronicAddress2: NonPersistedElectronicAddress = {
|
|
2141
|
-
type: 'email',
|
|
2142
|
-
electronicAddress: 'example_electronic_address2',
|
|
2143
|
-
}
|
|
2144
|
-
const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2145
|
-
partyId: savedParty.id,
|
|
2146
|
-
electronicAddress: electronicAddress2,
|
|
2147
|
-
})
|
|
2148
|
-
expect(savedElectronicAddress2).toBeDefined()
|
|
2149
|
-
|
|
2150
|
-
const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses()
|
|
2151
|
-
|
|
2152
|
-
expect(result.length).toEqual(2)
|
|
2153
|
-
})
|
|
2154
|
-
|
|
2155
|
-
it('should get electronic addresses by filter', async (): Promise<void> => {
|
|
2156
|
-
const party: NonPersistedParty = {
|
|
2157
|
-
uri: 'example.com',
|
|
2158
|
-
partyType: {
|
|
2159
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2160
|
-
origin: PartyOrigin.EXTERNAL,
|
|
2161
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2162
|
-
name: 'example_name',
|
|
2163
|
-
},
|
|
2164
|
-
contact: {
|
|
2165
|
-
firstName: 'example_first_name',
|
|
2166
|
-
middleName: 'example_middle_name',
|
|
2167
|
-
lastName: 'example_last_name',
|
|
2168
|
-
displayName: 'example_display_name',
|
|
2169
|
-
},
|
|
2170
|
-
}
|
|
2171
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2172
|
-
expect(savedParty).toBeDefined()
|
|
2173
|
-
|
|
2174
|
-
const electronicAddress = 'example_electronic_address1'
|
|
2175
|
-
const electronicAddress1: NonPersistedElectronicAddress = {
|
|
2176
|
-
type: 'email',
|
|
2177
|
-
electronicAddress,
|
|
2178
|
-
}
|
|
2179
|
-
const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2180
|
-
partyId: savedParty.id,
|
|
2181
|
-
electronicAddress: electronicAddress1,
|
|
2182
|
-
})
|
|
2183
|
-
expect(savedElectronicAddress1).toBeDefined()
|
|
2184
|
-
|
|
2185
|
-
const electronicAddress2: NonPersistedElectronicAddress = {
|
|
2186
|
-
type: 'email',
|
|
2187
|
-
electronicAddress: 'example_electronic_address2',
|
|
2188
|
-
}
|
|
2189
|
-
const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2190
|
-
partyId: savedParty.id,
|
|
2191
|
-
electronicAddress: electronicAddress2,
|
|
2192
|
-
})
|
|
2193
|
-
expect(savedElectronicAddress2).toBeDefined()
|
|
2194
|
-
|
|
2195
|
-
const args: GetElectronicAddressesArgs = {
|
|
2196
|
-
filter: [{ electronicAddress }],
|
|
2197
|
-
}
|
|
2198
|
-
|
|
2199
|
-
const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses(args)
|
|
2200
|
-
|
|
2201
|
-
expect(result.length).toEqual(1)
|
|
2202
|
-
})
|
|
2203
|
-
|
|
2204
|
-
it('should add electronic address to contact', async (): Promise<void> => {
|
|
2205
|
-
const party: NonPersistedParty = {
|
|
2206
|
-
uri: 'example.com',
|
|
2207
|
-
partyType: {
|
|
2208
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2209
|
-
origin: PartyOrigin.INTERNAL,
|
|
2210
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2211
|
-
name: 'example_name',
|
|
2212
|
-
},
|
|
2213
|
-
contact: {
|
|
2214
|
-
firstName: 'example_first_name',
|
|
2215
|
-
middleName: 'example_middle_name',
|
|
2216
|
-
lastName: 'example_last_name',
|
|
2217
|
-
displayName: 'example_display_name',
|
|
2218
|
-
},
|
|
2219
|
-
}
|
|
2220
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2221
|
-
expect(savedParty).toBeDefined()
|
|
2222
|
-
|
|
2223
|
-
const electronicAddress: NonPersistedElectronicAddress = {
|
|
2224
|
-
type: 'email',
|
|
2225
|
-
electronicAddress: 'example_electronic_address',
|
|
2226
|
-
}
|
|
2227
|
-
const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
|
|
2228
|
-
expect(savedElectronicAddress).toBeDefined()
|
|
2229
|
-
|
|
2230
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
2231
|
-
expect(result.electronicAddresses.length).toEqual(1)
|
|
2232
|
-
})
|
|
2233
|
-
|
|
2234
|
-
it('should update electronic address by id', async (): Promise<void> => {
|
|
2235
|
-
const party: NonPersistedParty = {
|
|
2236
|
-
uri: 'example.com',
|
|
2237
|
-
partyType: {
|
|
2238
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2239
|
-
origin: PartyOrigin.EXTERNAL,
|
|
2240
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2241
|
-
name: 'example_name',
|
|
2242
|
-
},
|
|
2243
|
-
contact: {
|
|
2244
|
-
firstName: 'example_first_name',
|
|
2245
|
-
middleName: 'example_middle_name',
|
|
2246
|
-
lastName: 'example_last_name',
|
|
2247
|
-
displayName: 'example_display_name',
|
|
2248
|
-
},
|
|
2249
|
-
}
|
|
2250
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2251
|
-
expect(savedParty).toBeDefined()
|
|
2252
|
-
|
|
2253
|
-
const electronicAddress: NonPersistedElectronicAddress = {
|
|
2254
|
-
type: 'email',
|
|
2255
|
-
electronicAddress: 'example_electronic_address',
|
|
2256
|
-
}
|
|
2257
|
-
const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
|
|
2258
|
-
const newElectronicAddress = 'new_example_electronic_address'
|
|
2259
|
-
savedElectronicAddress.electronicAddress = newElectronicAddress
|
|
2260
|
-
|
|
2261
|
-
await contactStore.updateElectronicAddress({ electronicAddress: savedElectronicAddress })
|
|
2262
|
-
const result: ElectronicAddress = await contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
|
|
2263
|
-
|
|
2264
|
-
expect(result).toBeDefined()
|
|
2265
|
-
expect(result.electronicAddress).toEqual(newElectronicAddress)
|
|
2266
|
-
})
|
|
2267
|
-
|
|
2268
|
-
it('should remove electronic address', async (): Promise<void> => {
|
|
2269
|
-
const party: NonPersistedParty = {
|
|
2270
|
-
uri: 'example.com',
|
|
2271
|
-
partyType: {
|
|
2272
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2273
|
-
origin: PartyOrigin.INTERNAL,
|
|
2274
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2275
|
-
name: 'example_name',
|
|
2276
|
-
},
|
|
2277
|
-
contact: {
|
|
2278
|
-
firstName: 'example_first_name',
|
|
2279
|
-
middleName: 'example_middle_name',
|
|
2280
|
-
lastName: 'example_last_name',
|
|
2281
|
-
displayName: 'example_display_name',
|
|
2282
|
-
},
|
|
2283
|
-
}
|
|
2284
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2285
|
-
expect(savedParty).toBeDefined()
|
|
2286
|
-
|
|
2287
|
-
const electronicAddress: NonPersistedElectronicAddress = {
|
|
2288
|
-
type: 'email',
|
|
2289
|
-
electronicAddress: 'example_electronic_address',
|
|
2290
|
-
}
|
|
2291
|
-
const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
|
|
2292
|
-
expect(savedElectronicAddress).toBeDefined()
|
|
2293
|
-
|
|
2294
|
-
await contactStore.removeElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
|
|
2295
|
-
|
|
2296
|
-
await expect(contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })).rejects.toThrow(
|
|
2297
|
-
`No electronic address found for id: ${savedElectronicAddress.id}`,
|
|
2298
|
-
)
|
|
2299
|
-
})
|
|
2300
|
-
|
|
2301
|
-
it('should throw error when removing electronic address with unknown id', async (): Promise<void> => {
|
|
2302
|
-
const electronicAddressId = 'unknownElectronicAddressId'
|
|
2303
|
-
|
|
2304
|
-
await expect(contactStore.removeElectronicAddress({ electronicAddressId })).rejects.toThrow(
|
|
2305
|
-
`No electronic address found for id: ${electronicAddressId}`,
|
|
2306
|
-
)
|
|
2307
|
-
})
|
|
2308
|
-
|
|
2309
|
-
it('should get physical address by id', async (): Promise<void> => {
|
|
2310
|
-
const party: NonPersistedParty = {
|
|
2311
|
-
uri: 'example.com',
|
|
2312
|
-
partyType: {
|
|
2313
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2314
|
-
origin: PartyOrigin.EXTERNAL,
|
|
2315
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2316
|
-
name: 'example_name',
|
|
2317
|
-
},
|
|
2318
|
-
contact: {
|
|
2319
|
-
firstName: 'example_first_name',
|
|
2320
|
-
middleName: 'example_middle_name',
|
|
2321
|
-
lastName: 'example_last_name',
|
|
2322
|
-
displayName: 'example_display_name',
|
|
2323
|
-
},
|
|
2324
|
-
}
|
|
2325
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2326
|
-
expect(savedParty).toBeDefined()
|
|
2327
|
-
|
|
2328
|
-
const physicalAddress: NonPersistedPhysicalAddress = {
|
|
2329
|
-
type: 'home',
|
|
2330
|
-
streetName: 'example_street_name',
|
|
2331
|
-
streetNumber: 'example_street_number',
|
|
2332
|
-
buildingName: 'example_building_name',
|
|
2333
|
-
postalCode: 'example_postal_code',
|
|
2334
|
-
cityName: 'example_city_name',
|
|
2335
|
-
provinceName: 'example_province_name',
|
|
2336
|
-
countryCode: 'example_country_code',
|
|
2337
|
-
}
|
|
2338
|
-
const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
|
|
2339
|
-
expect(savedPhysicalAddress).toBeDefined()
|
|
2340
|
-
|
|
2341
|
-
const result: PhysicalAddress = await contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
|
|
2342
|
-
|
|
2343
|
-
expect(result).toBeDefined()
|
|
2344
|
-
})
|
|
2345
|
-
|
|
2346
|
-
it('should throw error when getting physical address with unknown id', async (): Promise<void> => {
|
|
2347
|
-
const physicalAddressId = 'unknownPhysicalAddressId'
|
|
2348
|
-
|
|
2349
|
-
await expect(contactStore.getPhysicalAddress({ physicalAddressId })).rejects.toThrow(`No physical address found for id: ${physicalAddressId}`)
|
|
2350
|
-
})
|
|
2351
|
-
|
|
2352
|
-
it('should get all physical addresses for contact', async (): Promise<void> => {
|
|
2353
|
-
const party: NonPersistedParty = {
|
|
2354
|
-
uri: 'example.com',
|
|
2355
|
-
partyType: {
|
|
2356
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2357
|
-
origin: PartyOrigin.INTERNAL,
|
|
2358
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2359
|
-
name: 'example_name',
|
|
2360
|
-
},
|
|
2361
|
-
contact: {
|
|
2362
|
-
firstName: 'example_first_name',
|
|
2363
|
-
middleName: 'example_middle_name',
|
|
2364
|
-
lastName: 'example_last_name',
|
|
2365
|
-
displayName: 'example_display_name',
|
|
2366
|
-
},
|
|
2367
|
-
}
|
|
2368
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2369
|
-
expect(savedParty).toBeDefined()
|
|
2370
|
-
|
|
2371
|
-
const physicalAddress1: NonPersistedPhysicalAddress = {
|
|
2372
|
-
type: 'home',
|
|
2373
|
-
streetName: 'example_street_name',
|
|
2374
|
-
streetNumber: 'example_street_number',
|
|
2375
|
-
buildingName: 'example_building_name',
|
|
2376
|
-
postalCode: 'example_postal_code',
|
|
2377
|
-
cityName: 'example_city_name',
|
|
2378
|
-
provinceName: 'example_province_name',
|
|
2379
|
-
countryCode: 'example_country_code',
|
|
2380
|
-
}
|
|
2381
|
-
const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2382
|
-
partyId: savedParty.id,
|
|
2383
|
-
physicalAddress: physicalAddress1,
|
|
2384
|
-
})
|
|
2385
|
-
expect(savedPhysicalAddress1).toBeDefined()
|
|
2386
|
-
|
|
2387
|
-
const physicalAddress2: NonPersistedPhysicalAddress = {
|
|
2388
|
-
type: 'home',
|
|
2389
|
-
streetName: 'example_street_name',
|
|
2390
|
-
streetNumber: 'example_street_number',
|
|
2391
|
-
buildingName: 'example_building_name',
|
|
2392
|
-
postalCode: 'example_postal_code',
|
|
2393
|
-
cityName: 'example_city_name',
|
|
2394
|
-
provinceName: 'example_province_name',
|
|
2395
|
-
countryCode: 'example_country_code',
|
|
2396
|
-
}
|
|
2397
|
-
const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2398
|
-
partyId: savedParty.id,
|
|
2399
|
-
physicalAddress: physicalAddress2,
|
|
2400
|
-
})
|
|
2401
|
-
expect(savedPhysicalAddress2).toBeDefined()
|
|
2402
|
-
|
|
2403
|
-
const args: GetPhysicalAddressesArgs = {
|
|
2404
|
-
filter: [{ partyId: savedParty.id }],
|
|
2405
|
-
}
|
|
2406
|
-
|
|
2407
|
-
const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses(args)
|
|
2408
|
-
|
|
2409
|
-
expect(result.length).toEqual(2)
|
|
2410
|
-
})
|
|
2411
|
-
|
|
2412
|
-
it('should get all electronic addresses', async (): Promise<void> => {
|
|
2413
|
-
const party: NonPersistedParty = {
|
|
2414
|
-
uri: 'example.com',
|
|
2415
|
-
partyType: {
|
|
2416
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2417
|
-
origin: PartyOrigin.EXTERNAL,
|
|
2418
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2419
|
-
name: 'example_name',
|
|
2420
|
-
},
|
|
2421
|
-
contact: {
|
|
2422
|
-
firstName: 'example_first_name',
|
|
2423
|
-
middleName: 'example_middle_name',
|
|
2424
|
-
lastName: 'example_last_name',
|
|
2425
|
-
displayName: 'example_display_name',
|
|
2426
|
-
},
|
|
2427
|
-
}
|
|
2428
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2429
|
-
expect(savedParty).toBeDefined()
|
|
2430
|
-
|
|
2431
|
-
const physicalAddress1: NonPersistedPhysicalAddress = {
|
|
2432
|
-
type: 'home',
|
|
2433
|
-
streetName: 'example_street_name',
|
|
2434
|
-
streetNumber: 'example_street_number',
|
|
2435
|
-
buildingName: 'example_building_name',
|
|
2436
|
-
postalCode: 'example_postal_code',
|
|
2437
|
-
cityName: 'example_city_name',
|
|
2438
|
-
provinceName: 'example_province_name',
|
|
2439
|
-
countryCode: 'example_country_code',
|
|
2440
|
-
}
|
|
2441
|
-
const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2442
|
-
partyId: savedParty.id,
|
|
2443
|
-
physicalAddress: physicalAddress1,
|
|
2444
|
-
})
|
|
2445
|
-
expect(savedPhysicalAddress1).toBeDefined()
|
|
2446
|
-
|
|
2447
|
-
const physicalAddress2: NonPersistedPhysicalAddress = {
|
|
2448
|
-
type: 'home',
|
|
2449
|
-
streetName: 'example_street_name',
|
|
2450
|
-
streetNumber: 'example_street_number',
|
|
2451
|
-
buildingName: 'example_building_name',
|
|
2452
|
-
postalCode: 'example_postal_code',
|
|
2453
|
-
cityName: 'example_city_name',
|
|
2454
|
-
provinceName: 'example_province_name',
|
|
2455
|
-
countryCode: 'example_country_code',
|
|
2456
|
-
}
|
|
2457
|
-
const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2458
|
-
partyId: savedParty.id,
|
|
2459
|
-
physicalAddress: physicalAddress2,
|
|
2460
|
-
})
|
|
2461
|
-
expect(savedPhysicalAddress2).toBeDefined()
|
|
2462
|
-
|
|
2463
|
-
const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses()
|
|
2464
|
-
|
|
2465
|
-
expect(result.length).toEqual(2)
|
|
2466
|
-
})
|
|
2467
|
-
|
|
2468
|
-
it('should get electronic addresses by filter', async (): Promise<void> => {
|
|
2469
|
-
const party: NonPersistedParty = {
|
|
2470
|
-
uri: 'example.com',
|
|
2471
|
-
partyType: {
|
|
2472
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2473
|
-
origin: PartyOrigin.INTERNAL,
|
|
2474
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2475
|
-
name: 'example_name',
|
|
2476
|
-
},
|
|
2477
|
-
contact: {
|
|
2478
|
-
firstName: 'example_first_name',
|
|
2479
|
-
middleName: 'example_middle_name',
|
|
2480
|
-
lastName: 'example_last_name',
|
|
2481
|
-
displayName: 'example_display_name',
|
|
2482
|
-
},
|
|
2483
|
-
}
|
|
2484
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2485
|
-
expect(savedParty).toBeDefined()
|
|
2486
|
-
|
|
2487
|
-
const streetName = 'example_electronic_address1'
|
|
2488
|
-
const physicalAddress1: NonPersistedPhysicalAddress = {
|
|
2489
|
-
type: 'home',
|
|
2490
|
-
streetName,
|
|
2491
|
-
streetNumber: 'example_street_number1',
|
|
2492
|
-
buildingName: 'example_building_name1',
|
|
2493
|
-
postalCode: 'example_postal_code1',
|
|
2494
|
-
cityName: 'example_city_name1',
|
|
2495
|
-
provinceName: 'example_province_name1',
|
|
2496
|
-
countryCode: 'example_country_code1',
|
|
2497
|
-
}
|
|
2498
|
-
const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2499
|
-
partyId: savedParty.id,
|
|
2500
|
-
physicalAddress: physicalAddress1,
|
|
2501
|
-
})
|
|
2502
|
-
expect(savedPhysicalAddress1).toBeDefined()
|
|
2503
|
-
|
|
2504
|
-
const physicalAddress2: NonPersistedPhysicalAddress = {
|
|
2505
|
-
type: 'home',
|
|
2506
|
-
streetName: 'example_street_name2',
|
|
2507
|
-
streetNumber: 'example_street_number2',
|
|
2508
|
-
buildingName: 'example_building_name2',
|
|
2509
|
-
postalCode: 'example_postal_code2',
|
|
2510
|
-
cityName: 'example_city_name2',
|
|
2511
|
-
provinceName: 'example_province_name2',
|
|
2512
|
-
countryCode: 'example_country_code2',
|
|
2513
|
-
}
|
|
2514
|
-
const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2515
|
-
partyId: savedParty.id,
|
|
2516
|
-
physicalAddress: physicalAddress2,
|
|
2517
|
-
})
|
|
2518
|
-
expect(savedPhysicalAddress2).toBeDefined()
|
|
2519
|
-
|
|
2520
|
-
const args: GetPhysicalAddressesArgs = {
|
|
2521
|
-
filter: [{ streetName }],
|
|
2522
|
-
}
|
|
2523
|
-
|
|
2524
|
-
const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses(args)
|
|
2525
|
-
|
|
2526
|
-
expect(result.length).toEqual(1)
|
|
2527
|
-
})
|
|
2528
|
-
|
|
2529
|
-
it('should add physical address to contact', async (): Promise<void> => {
|
|
2530
|
-
const party: NonPersistedParty = {
|
|
2531
|
-
uri: 'example.com',
|
|
2532
|
-
partyType: {
|
|
2533
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2534
|
-
origin: PartyOrigin.EXTERNAL,
|
|
2535
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2536
|
-
name: 'example_name',
|
|
2537
|
-
},
|
|
2538
|
-
contact: {
|
|
2539
|
-
firstName: 'example_first_name',
|
|
2540
|
-
middleName: 'example_middle_name',
|
|
2541
|
-
lastName: 'example_last_name',
|
|
2542
|
-
displayName: 'example_display_name',
|
|
2543
|
-
},
|
|
2544
|
-
}
|
|
2545
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2546
|
-
expect(savedParty).toBeDefined()
|
|
2547
|
-
|
|
2548
|
-
const physicalAddress: NonPersistedPhysicalAddress = {
|
|
2549
|
-
type: 'home',
|
|
2550
|
-
streetName: 'example_street_name',
|
|
2551
|
-
streetNumber: 'example_street_number',
|
|
2552
|
-
buildingName: 'example_building_name',
|
|
2553
|
-
postalCode: 'example_postal_code',
|
|
2554
|
-
cityName: 'example_city_name',
|
|
2555
|
-
provinceName: 'example_province_name',
|
|
2556
|
-
countryCode: 'example_country_code',
|
|
2557
|
-
}
|
|
2558
|
-
const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
|
|
2559
|
-
expect(savedPhysicalAddress).toBeDefined()
|
|
2560
|
-
|
|
2561
|
-
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
2562
|
-
expect(result.physicalAddresses.length).toEqual(1)
|
|
2563
|
-
})
|
|
2564
|
-
|
|
2565
|
-
it('should update physical address by id', async (): Promise<void> => {
|
|
2566
|
-
const party: NonPersistedParty = {
|
|
2567
|
-
uri: 'example.com',
|
|
2568
|
-
partyType: {
|
|
2569
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2570
|
-
origin: PartyOrigin.INTERNAL,
|
|
2571
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2572
|
-
name: 'example_name',
|
|
2573
|
-
},
|
|
2574
|
-
contact: {
|
|
2575
|
-
firstName: 'example_first_name',
|
|
2576
|
-
middleName: 'example_middle_name',
|
|
2577
|
-
lastName: 'example_last_name',
|
|
2578
|
-
displayName: 'example_display_name',
|
|
2579
|
-
},
|
|
2580
|
-
}
|
|
2581
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2582
|
-
expect(savedParty).toBeDefined()
|
|
2583
|
-
|
|
2584
|
-
const physicalAddress: NonPersistedPhysicalAddress = {
|
|
2585
|
-
type: 'home',
|
|
2586
|
-
streetName: 'example_street_name',
|
|
2587
|
-
streetNumber: 'example_street_number',
|
|
2588
|
-
buildingName: 'example_building_name',
|
|
2589
|
-
postalCode: 'example_postal_code',
|
|
2590
|
-
cityName: 'example_city_name',
|
|
2591
|
-
provinceName: 'example_province_name',
|
|
2592
|
-
countryCode: 'example_country_code',
|
|
2593
|
-
}
|
|
2594
|
-
const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
|
|
2595
|
-
const newStreetName = 'new_example_street_name'
|
|
2596
|
-
savedPhysicalAddress.streetName = newStreetName
|
|
2597
|
-
|
|
2598
|
-
await contactStore.updatePhysicalAddress({ physicalAddress: savedPhysicalAddress })
|
|
2599
|
-
const result: PhysicalAddress = await contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
|
|
2600
|
-
|
|
2601
|
-
expect(result).toBeDefined()
|
|
2602
|
-
expect(result.streetName).toEqual(newStreetName)
|
|
2603
|
-
})
|
|
2604
|
-
|
|
2605
|
-
it('should remove physical address', async (): Promise<void> => {
|
|
2606
|
-
const party: NonPersistedParty = {
|
|
2607
|
-
uri: 'example.com',
|
|
2608
|
-
partyType: {
|
|
2609
|
-
type: PartyTypeType.NATURAL_PERSON,
|
|
2610
|
-
origin: PartyOrigin.EXTERNAL,
|
|
2611
|
-
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2612
|
-
name: 'example_name',
|
|
2613
|
-
},
|
|
2614
|
-
contact: {
|
|
2615
|
-
firstName: 'example_first_name',
|
|
2616
|
-
middleName: 'example_middle_name',
|
|
2617
|
-
lastName: 'example_last_name',
|
|
2618
|
-
displayName: 'example_display_name',
|
|
2619
|
-
},
|
|
2620
|
-
}
|
|
2621
|
-
const savedParty: Party = await contactStore.addParty(party)
|
|
2622
|
-
expect(savedParty).toBeDefined()
|
|
2623
|
-
|
|
2624
|
-
const physicalAddress: NonPersistedPhysicalAddress = {
|
|
2625
|
-
type: 'home',
|
|
2626
|
-
streetName: 'example_street_name',
|
|
2627
|
-
streetNumber: 'example_street_number',
|
|
2628
|
-
buildingName: 'example_building_name',
|
|
2629
|
-
postalCode: 'example_postal_code',
|
|
2630
|
-
cityName: 'example_city_name',
|
|
2631
|
-
provinceName: 'example_province_name',
|
|
2632
|
-
countryCode: 'example_country_code',
|
|
2633
|
-
}
|
|
2634
|
-
const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
|
|
2635
|
-
expect(savedPhysicalAddress).toBeDefined()
|
|
2636
|
-
|
|
2637
|
-
await contactStore.removePhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
|
|
2638
|
-
|
|
2639
|
-
await expect(contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })).rejects.toThrow(
|
|
2640
|
-
`No physical address found for id: ${savedPhysicalAddress.id}`,
|
|
2641
|
-
)
|
|
2642
|
-
})
|
|
2643
|
-
|
|
2644
|
-
it('should throw error when removing physical address with unknown id', async (): Promise<void> => {
|
|
2645
|
-
const physicalAddressId = 'unknownPhysicalAddressId'
|
|
2646
|
-
|
|
2647
|
-
await expect(contactStore.removePhysicalAddress({ physicalAddressId })).rejects.toThrow(`No physical address found for id: ${physicalAddressId}`)
|
|
2648
|
-
})
|
|
2649
|
-
})
|
|
1
|
+
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
+
import { DataSource } from 'typeorm'
|
|
3
|
+
import { DataStoreContactEntities, DataStoreMigrations, IdentityOrigin, MetadataItem, MetadataTypes, PartyOrigin } from '../index'
|
|
4
|
+
import { ContactStore } from '../contact/ContactStore'
|
|
5
|
+
import {
|
|
6
|
+
CorrelationIdentifierType,
|
|
7
|
+
ElectronicAddress,
|
|
8
|
+
GetElectronicAddressesArgs,
|
|
9
|
+
GetIdentitiesArgs,
|
|
10
|
+
GetPartiesArgs,
|
|
11
|
+
GetPhysicalAddressesArgs,
|
|
12
|
+
GetRelationshipsArgs,
|
|
13
|
+
Identity,
|
|
14
|
+
CredentialRole,
|
|
15
|
+
NaturalPerson,
|
|
16
|
+
NonPersistedElectronicAddress,
|
|
17
|
+
NonPersistedIdentity,
|
|
18
|
+
NonPersistedNaturalPerson,
|
|
19
|
+
NonPersistedParty,
|
|
20
|
+
NonPersistedPartyRelationship,
|
|
21
|
+
NonPersistedPartyType,
|
|
22
|
+
NonPersistedPhysicalAddress,
|
|
23
|
+
Party,
|
|
24
|
+
PartyRelationship,
|
|
25
|
+
PartyType,
|
|
26
|
+
PartyTypeType,
|
|
27
|
+
PhysicalAddress,
|
|
28
|
+
} from '../types'
|
|
29
|
+
|
|
30
|
+
describe('Contact store tests', (): void => {
|
|
31
|
+
let dbConnection: DataSource
|
|
32
|
+
let contactStore: ContactStore
|
|
33
|
+
|
|
34
|
+
beforeEach(async (): Promise<void> => {
|
|
35
|
+
DataSources.singleInstance().defaultDbType = 'sqlite'
|
|
36
|
+
dbConnection = await new DataSource({
|
|
37
|
+
type: 'sqlite',
|
|
38
|
+
database: ':memory:',
|
|
39
|
+
logging: ['info'],
|
|
40
|
+
migrationsRun: false,
|
|
41
|
+
migrations: DataStoreMigrations,
|
|
42
|
+
synchronize: false,
|
|
43
|
+
entities: DataStoreContactEntities,
|
|
44
|
+
}).initialize()
|
|
45
|
+
await dbConnection.runMigrations()
|
|
46
|
+
expect(await dbConnection.showMigrations()).toBeFalsy()
|
|
47
|
+
contactStore = new ContactStore(dbConnection)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
afterEach(async (): Promise<void> => {
|
|
51
|
+
await (await dbConnection).destroy()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should get party by contact metadata', async (): Promise<void> => {
|
|
55
|
+
const dateOfBirth = new Date(2016, 0, 5)
|
|
56
|
+
const party: NonPersistedParty = {
|
|
57
|
+
uri: 'example.com',
|
|
58
|
+
partyType: {
|
|
59
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
60
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
61
|
+
name: 'example_name',
|
|
62
|
+
origin: PartyOrigin.EXTERNAL,
|
|
63
|
+
},
|
|
64
|
+
contact: {
|
|
65
|
+
firstName: 'example_first_name',
|
|
66
|
+
middleName: 'example_middle_name',
|
|
67
|
+
lastName: 'example_last_name',
|
|
68
|
+
metadata: [
|
|
69
|
+
{ label: 'grade', value: '5th' },
|
|
70
|
+
{ label: 'dateOfBirth', value: dateOfBirth },
|
|
71
|
+
] as Array<MetadataItem<MetadataTypes>>,
|
|
72
|
+
displayName: 'example_display_name',
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
77
|
+
expect(savedParty).toBeDefined()
|
|
78
|
+
|
|
79
|
+
const singleResult: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
80
|
+
expect(singleResult).toBeDefined()
|
|
81
|
+
|
|
82
|
+
const args: GetPartiesArgs = {
|
|
83
|
+
filter: [{ contact: { metadata: { label: 'dateOfBirth', value: dateOfBirth } } }],
|
|
84
|
+
}
|
|
85
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
86
|
+
expect(result).toBeDefined()
|
|
87
|
+
expect(result.length).toEqual(1)
|
|
88
|
+
expect(result[0]).toBeDefined()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('should get a party by identity metadata', async (): Promise<void> => {
|
|
92
|
+
const party: NonPersistedParty = {
|
|
93
|
+
uri: 'example.com',
|
|
94
|
+
partyType: {
|
|
95
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
96
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
97
|
+
name: 'example_name',
|
|
98
|
+
origin: PartyOrigin.EXTERNAL,
|
|
99
|
+
},
|
|
100
|
+
contact: {
|
|
101
|
+
firstName: 'example_first_name',
|
|
102
|
+
middleName: 'example_middle_name',
|
|
103
|
+
lastName: 'example_last_name',
|
|
104
|
+
displayName: 'example_display_name',
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
109
|
+
expect(savedParty).toBeDefined()
|
|
110
|
+
|
|
111
|
+
const identity: NonPersistedIdentity = {
|
|
112
|
+
alias: 'test_alias',
|
|
113
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
114
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
115
|
+
identifier: {
|
|
116
|
+
type: CorrelationIdentifierType.DID,
|
|
117
|
+
correlationId: 'example_did',
|
|
118
|
+
},
|
|
119
|
+
metadata: [
|
|
120
|
+
{
|
|
121
|
+
label: 'label1',
|
|
122
|
+
value: 'example_value',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
label: 'label2',
|
|
126
|
+
value: 'example_value',
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
}
|
|
130
|
+
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity })
|
|
131
|
+
expect(savedIdentity).toBeDefined()
|
|
132
|
+
|
|
133
|
+
const args: GetPartiesArgs = {
|
|
134
|
+
filter: [{ identities: { metadata: { label: 'label1', value: 'example_value' } } }],
|
|
135
|
+
}
|
|
136
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
137
|
+
expect(result).toBeDefined()
|
|
138
|
+
expect(result.length).toEqual(1)
|
|
139
|
+
expect(result[0]).toBeDefined()
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('should get party by both contact and identity metadata', async (): Promise<void> => {
|
|
143
|
+
const example_date = new Date(2016, 0, 5)
|
|
144
|
+
const party: NonPersistedParty = {
|
|
145
|
+
uri: 'example.com',
|
|
146
|
+
partyType: {
|
|
147
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
148
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
149
|
+
name: 'example_name',
|
|
150
|
+
origin: PartyOrigin.EXTERNAL,
|
|
151
|
+
},
|
|
152
|
+
contact: {
|
|
153
|
+
firstName: 'example_first_name',
|
|
154
|
+
middleName: 'example_middle_name',
|
|
155
|
+
lastName: 'example_last_name',
|
|
156
|
+
displayName: 'example_display_name',
|
|
157
|
+
metadata: [
|
|
158
|
+
{ label: 'label1', value: 'example_value' },
|
|
159
|
+
{ label: 'label2', value: example_date },
|
|
160
|
+
] as Array<MetadataItem<MetadataTypes>>,
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
165
|
+
expect(savedParty).toBeDefined()
|
|
166
|
+
|
|
167
|
+
const identity: NonPersistedIdentity = {
|
|
168
|
+
alias: 'test_alias',
|
|
169
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
170
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
171
|
+
identifier: {
|
|
172
|
+
type: CorrelationIdentifierType.DID,
|
|
173
|
+
correlationId: 'example_did',
|
|
174
|
+
},
|
|
175
|
+
metadata: [
|
|
176
|
+
{
|
|
177
|
+
label: 'label3',
|
|
178
|
+
value: 'example_value',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
label: 'label4',
|
|
182
|
+
value: 'example_value',
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
}
|
|
186
|
+
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity })
|
|
187
|
+
expect(savedIdentity).toBeDefined()
|
|
188
|
+
|
|
189
|
+
const args: GetPartiesArgs = {
|
|
190
|
+
filter: [
|
|
191
|
+
{
|
|
192
|
+
contact: { metadata: { label: 'label2', value: example_date } },
|
|
193
|
+
identities: { metadata: { label: 'label3', value: 'example_value' } },
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
199
|
+
|
|
200
|
+
expect(result).toBeDefined()
|
|
201
|
+
expect(result.length).toEqual(1)
|
|
202
|
+
expect(result[0]).toBeDefined()
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('should get party by id', async (): Promise<void> => {
|
|
206
|
+
const party: NonPersistedParty = {
|
|
207
|
+
uri: 'example.com',
|
|
208
|
+
partyType: {
|
|
209
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
210
|
+
origin: PartyOrigin.INTERNAL,
|
|
211
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
212
|
+
name: 'example_name',
|
|
213
|
+
},
|
|
214
|
+
contact: {
|
|
215
|
+
firstName: 'example_first_name',
|
|
216
|
+
middleName: 'example_middle_name',
|
|
217
|
+
lastName: 'example_last_name',
|
|
218
|
+
displayName: 'example_display_name',
|
|
219
|
+
},
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
223
|
+
expect(savedParty).toBeDefined()
|
|
224
|
+
|
|
225
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
226
|
+
|
|
227
|
+
expect(result).toBeDefined()
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('should throw error when getting party with unknown id', async (): Promise<void> => {
|
|
231
|
+
const partyId = 'unknownPartyId'
|
|
232
|
+
|
|
233
|
+
await expect(contactStore.getParty({ partyId })).rejects.toThrow(`No party found for id: ${partyId}`)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('should get all parties', async (): Promise<void> => {
|
|
237
|
+
const party1: NonPersistedParty = {
|
|
238
|
+
uri: 'example.com',
|
|
239
|
+
partyType: {
|
|
240
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
241
|
+
origin: PartyOrigin.INTERNAL,
|
|
242
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
243
|
+
name: 'example_name1',
|
|
244
|
+
},
|
|
245
|
+
contact: {
|
|
246
|
+
firstName: 'example_first_name1',
|
|
247
|
+
middleName: 'example_middle_name1',
|
|
248
|
+
lastName: 'example_last_name1',
|
|
249
|
+
displayName: 'example_display_name1',
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
253
|
+
expect(savedParty1).toBeDefined()
|
|
254
|
+
|
|
255
|
+
const party2: NonPersistedParty = {
|
|
256
|
+
uri: 'example.com',
|
|
257
|
+
partyType: {
|
|
258
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
259
|
+
origin: PartyOrigin.INTERNAL,
|
|
260
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
261
|
+
name: 'example_name2',
|
|
262
|
+
},
|
|
263
|
+
contact: {
|
|
264
|
+
firstName: 'example_first_name2',
|
|
265
|
+
middleName: 'example_middle_name2',
|
|
266
|
+
lastName: 'example_last_name2',
|
|
267
|
+
displayName: 'example_display_name2',
|
|
268
|
+
},
|
|
269
|
+
}
|
|
270
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
271
|
+
expect(savedParty2).toBeDefined()
|
|
272
|
+
|
|
273
|
+
const result: Array<Party> = await contactStore.getParties()
|
|
274
|
+
|
|
275
|
+
expect(result).toBeDefined()
|
|
276
|
+
expect(result.length).toEqual(2)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it('should get parties by filter', async (): Promise<void> => {
|
|
280
|
+
const party: NonPersistedParty = {
|
|
281
|
+
uri: 'example.com',
|
|
282
|
+
partyType: {
|
|
283
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
284
|
+
origin: PartyOrigin.INTERNAL,
|
|
285
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
286
|
+
name: 'example_name',
|
|
287
|
+
},
|
|
288
|
+
contact: {
|
|
289
|
+
firstName: 'example_first_name',
|
|
290
|
+
middleName: 'example_middle_name',
|
|
291
|
+
lastName: 'example_last_name',
|
|
292
|
+
displayName: 'example_display_name',
|
|
293
|
+
},
|
|
294
|
+
}
|
|
295
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
296
|
+
expect(savedParty).toBeDefined()
|
|
297
|
+
|
|
298
|
+
const args: GetPartiesArgs = {
|
|
299
|
+
filter: [
|
|
300
|
+
{
|
|
301
|
+
contact: {
|
|
302
|
+
firstName: (<NonPersistedNaturalPerson>party.contact).firstName,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
contact: {
|
|
307
|
+
middleName: (<NonPersistedNaturalPerson>party.contact).middleName,
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
contact: {
|
|
312
|
+
lastName: (<NonPersistedNaturalPerson>party.contact).lastName,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
contact: {
|
|
317
|
+
displayName: (<NonPersistedNaturalPerson>party.contact).displayName,
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
}
|
|
322
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
323
|
+
|
|
324
|
+
expect(result.length).toEqual(1)
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
it('should get whole parties by filter', async (): Promise<void> => {
|
|
328
|
+
const party: NonPersistedParty = {
|
|
329
|
+
uri: 'example.com',
|
|
330
|
+
partyType: {
|
|
331
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
332
|
+
origin: PartyOrigin.INTERNAL,
|
|
333
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
334
|
+
name: 'example_name',
|
|
335
|
+
},
|
|
336
|
+
contact: {
|
|
337
|
+
firstName: 'example_first_name',
|
|
338
|
+
middleName: 'example_middle_name',
|
|
339
|
+
lastName: 'example_last_name',
|
|
340
|
+
displayName: 'example_display_name',
|
|
341
|
+
},
|
|
342
|
+
identities: [
|
|
343
|
+
{
|
|
344
|
+
alias: 'test_alias1',
|
|
345
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
346
|
+
roles: [CredentialRole.ISSUER],
|
|
347
|
+
identifier: {
|
|
348
|
+
type: CorrelationIdentifierType.DID,
|
|
349
|
+
correlationId: 'example_did1',
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
alias: 'test_alias2',
|
|
354
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
355
|
+
roles: [CredentialRole.VERIFIER],
|
|
356
|
+
identifier: {
|
|
357
|
+
type: CorrelationIdentifierType.DID,
|
|
358
|
+
correlationId: 'example_did2',
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
alias: 'test_alias3',
|
|
363
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
364
|
+
roles: [CredentialRole.HOLDER],
|
|
365
|
+
identifier: {
|
|
366
|
+
type: CorrelationIdentifierType.DID,
|
|
367
|
+
correlationId: 'example_did3',
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
electronicAddresses: [
|
|
372
|
+
{
|
|
373
|
+
type: 'email',
|
|
374
|
+
electronicAddress: 'example_electronic_address',
|
|
375
|
+
},
|
|
376
|
+
],
|
|
377
|
+
}
|
|
378
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
379
|
+
expect(savedParty).toBeDefined()
|
|
380
|
+
|
|
381
|
+
const args: GetPartiesArgs = {
|
|
382
|
+
filter: [
|
|
383
|
+
{
|
|
384
|
+
identities: {
|
|
385
|
+
identifier: {
|
|
386
|
+
correlationId: 'example_did1',
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
],
|
|
391
|
+
}
|
|
392
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
393
|
+
|
|
394
|
+
expect(result[0].identities.length).toEqual(3)
|
|
395
|
+
expect(result[0].electronicAddresses.length).toEqual(1)
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
it('should get parties by name', async (): Promise<void> => {
|
|
399
|
+
const party: NonPersistedParty = {
|
|
400
|
+
uri: 'example.com',
|
|
401
|
+
partyType: {
|
|
402
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
403
|
+
origin: PartyOrigin.INTERNAL,
|
|
404
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
405
|
+
name: 'something',
|
|
406
|
+
},
|
|
407
|
+
contact: {
|
|
408
|
+
firstName: 'example_first_name',
|
|
409
|
+
middleName: 'example_middle_name',
|
|
410
|
+
lastName: 'example_last_name',
|
|
411
|
+
displayName: 'example_display_name',
|
|
412
|
+
},
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
416
|
+
expect(savedParty).toBeDefined()
|
|
417
|
+
|
|
418
|
+
const args: GetPartiesArgs = {
|
|
419
|
+
filter: [
|
|
420
|
+
{
|
|
421
|
+
contact: {
|
|
422
|
+
firstName: (<NonPersistedNaturalPerson>party.contact).firstName,
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
contact: {
|
|
427
|
+
middleName: (<NonPersistedNaturalPerson>party.contact).middleName,
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
contact: {
|
|
432
|
+
lastName: (<NonPersistedNaturalPerson>party.contact).lastName,
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
}
|
|
437
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
438
|
+
|
|
439
|
+
expect(result.length).toEqual(1)
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
it('should get parties by display name', async (): Promise<void> => {
|
|
443
|
+
const party: NonPersistedParty = {
|
|
444
|
+
uri: 'example.com',
|
|
445
|
+
partyType: {
|
|
446
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
447
|
+
origin: PartyOrigin.INTERNAL,
|
|
448
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
449
|
+
name: 'example_name',
|
|
450
|
+
},
|
|
451
|
+
contact: {
|
|
452
|
+
firstName: 'example_first_name',
|
|
453
|
+
middleName: 'example_middle_name',
|
|
454
|
+
lastName: 'example_last_name',
|
|
455
|
+
displayName: 'example_display_name',
|
|
456
|
+
},
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
460
|
+
expect(savedParty).toBeDefined()
|
|
461
|
+
|
|
462
|
+
const args: GetPartiesArgs = {
|
|
463
|
+
filter: [
|
|
464
|
+
{
|
|
465
|
+
contact: {
|
|
466
|
+
displayName: (<NonPersistedNaturalPerson>party.contact).displayName,
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
],
|
|
470
|
+
}
|
|
471
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
472
|
+
|
|
473
|
+
expect(result.length).toEqual(1)
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
it('should get parties by uri', async (): Promise<void> => {
|
|
477
|
+
const party: NonPersistedParty = {
|
|
478
|
+
uri: 'example.com',
|
|
479
|
+
partyType: {
|
|
480
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
481
|
+
origin: PartyOrigin.INTERNAL,
|
|
482
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
483
|
+
name: 'example_name',
|
|
484
|
+
},
|
|
485
|
+
contact: {
|
|
486
|
+
firstName: 'example_first_name',
|
|
487
|
+
middleName: 'example_middle_name',
|
|
488
|
+
lastName: 'example_last_name',
|
|
489
|
+
displayName: 'example_display_name',
|
|
490
|
+
},
|
|
491
|
+
}
|
|
492
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
493
|
+
expect(savedParty).toBeDefined()
|
|
494
|
+
|
|
495
|
+
const args: GetPartiesArgs = {
|
|
496
|
+
filter: [{ uri: 'example.com' }],
|
|
497
|
+
}
|
|
498
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
499
|
+
|
|
500
|
+
expect(result.length).toEqual(1)
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
it('should return no parties if filter does not match', async (): Promise<void> => {
|
|
504
|
+
const args: GetPartiesArgs = {
|
|
505
|
+
filter: [
|
|
506
|
+
{
|
|
507
|
+
contact: {
|
|
508
|
+
firstName: 'no_match_firstName',
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
contact: {
|
|
513
|
+
middleName: 'no_match_middleName',
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
contact: {
|
|
518
|
+
lastName: 'no_match_lastName',
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
],
|
|
522
|
+
}
|
|
523
|
+
const result: Array<Party> = await contactStore.getParties(args)
|
|
524
|
+
|
|
525
|
+
expect(result.length).toEqual(0)
|
|
526
|
+
})
|
|
527
|
+
|
|
528
|
+
it('should add party without identities', async (): Promise<void> => {
|
|
529
|
+
const party: NonPersistedParty = {
|
|
530
|
+
uri: 'example.com',
|
|
531
|
+
partyType: {
|
|
532
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
533
|
+
origin: PartyOrigin.INTERNAL,
|
|
534
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
535
|
+
name: 'example_name',
|
|
536
|
+
},
|
|
537
|
+
contact: {
|
|
538
|
+
firstName: 'example_first_name',
|
|
539
|
+
middleName: 'example_middle_name',
|
|
540
|
+
lastName: 'example_last_name',
|
|
541
|
+
displayName: 'example_display_name',
|
|
542
|
+
},
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const result: Party = await contactStore.addParty(party)
|
|
546
|
+
|
|
547
|
+
expect(result).toBeDefined()
|
|
548
|
+
expect((<NaturalPerson>result.contact).firstName).toEqual((<NonPersistedNaturalPerson>party.contact).firstName)
|
|
549
|
+
expect((<NaturalPerson>result.contact).middleName).toEqual((<NonPersistedNaturalPerson>party.contact).middleName)
|
|
550
|
+
expect((<NaturalPerson>result.contact).lastName).toEqual((<NonPersistedNaturalPerson>party.contact).lastName)
|
|
551
|
+
expect(result.identities.length).toEqual(0)
|
|
552
|
+
})
|
|
553
|
+
|
|
554
|
+
it('should add party with identities', async (): Promise<void> => {
|
|
555
|
+
const party: NonPersistedParty = {
|
|
556
|
+
uri: 'example.com',
|
|
557
|
+
partyType: {
|
|
558
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
559
|
+
origin: PartyOrigin.INTERNAL,
|
|
560
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
561
|
+
name: 'example_name',
|
|
562
|
+
},
|
|
563
|
+
contact: {
|
|
564
|
+
firstName: 'example_first_name',
|
|
565
|
+
middleName: 'example_middle_name',
|
|
566
|
+
lastName: 'example_last_name',
|
|
567
|
+
displayName: 'example_display_name',
|
|
568
|
+
},
|
|
569
|
+
identities: [
|
|
570
|
+
{
|
|
571
|
+
alias: 'test_alias1',
|
|
572
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
573
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
574
|
+
identifier: {
|
|
575
|
+
type: CorrelationIdentifierType.DID,
|
|
576
|
+
correlationId: 'example_did1',
|
|
577
|
+
},
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
alias: 'test_alias2',
|
|
581
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
582
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
583
|
+
identifier: {
|
|
584
|
+
type: CorrelationIdentifierType.DID,
|
|
585
|
+
correlationId: 'example_did2',
|
|
586
|
+
},
|
|
587
|
+
},
|
|
588
|
+
],
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const result: Party = await contactStore.addParty(party)
|
|
592
|
+
|
|
593
|
+
expect(result).toBeDefined()
|
|
594
|
+
expect((<NaturalPerson>result.contact).firstName).toEqual((<NonPersistedNaturalPerson>party.contact).firstName)
|
|
595
|
+
expect((<NaturalPerson>result.contact).middleName).toEqual((<NonPersistedNaturalPerson>party.contact).middleName)
|
|
596
|
+
expect((<NaturalPerson>result.contact).lastName).toEqual((<NonPersistedNaturalPerson>party.contact).lastName)
|
|
597
|
+
expect(result.identities.length).toEqual(2)
|
|
598
|
+
})
|
|
599
|
+
|
|
600
|
+
it('should throw error when adding party with invalid identity', async (): Promise<void> => {
|
|
601
|
+
const party: NonPersistedParty = {
|
|
602
|
+
uri: 'example.com',
|
|
603
|
+
partyType: {
|
|
604
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
605
|
+
origin: PartyOrigin.INTERNAL,
|
|
606
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
607
|
+
name: 'something',
|
|
608
|
+
},
|
|
609
|
+
contact: {
|
|
610
|
+
firstName: 'example_first_name',
|
|
611
|
+
middleName: 'example_middle_name',
|
|
612
|
+
lastName: 'example_last_name',
|
|
613
|
+
displayName: 'example_display_name',
|
|
614
|
+
},
|
|
615
|
+
identities: [
|
|
616
|
+
{
|
|
617
|
+
alias: 'test_alias1',
|
|
618
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
619
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
620
|
+
identifier: {
|
|
621
|
+
type: CorrelationIdentifierType.URL,
|
|
622
|
+
correlationId: 'example_did1',
|
|
623
|
+
},
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
alias: 'test_alias2',
|
|
627
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
628
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
629
|
+
identifier: {
|
|
630
|
+
type: CorrelationIdentifierType.DID,
|
|
631
|
+
correlationId: 'example_did2',
|
|
632
|
+
},
|
|
633
|
+
},
|
|
634
|
+
],
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
await expect(contactStore.addParty(party)).rejects.toThrow(`Identity with correlation type url should contain a connection`)
|
|
638
|
+
})
|
|
639
|
+
|
|
640
|
+
it('should update party by id', async (): Promise<void> => {
|
|
641
|
+
const party: NonPersistedParty = {
|
|
642
|
+
uri: 'example.com',
|
|
643
|
+
partyType: {
|
|
644
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
645
|
+
origin: PartyOrigin.INTERNAL,
|
|
646
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
647
|
+
name: 'example_name',
|
|
648
|
+
},
|
|
649
|
+
contact: {
|
|
650
|
+
firstName: 'example_first_name',
|
|
651
|
+
middleName: 'example_middle_name',
|
|
652
|
+
lastName: 'example_last_name',
|
|
653
|
+
displayName: 'example_display_name',
|
|
654
|
+
},
|
|
655
|
+
}
|
|
656
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
657
|
+
expect(savedParty).toBeDefined()
|
|
658
|
+
|
|
659
|
+
const identity1: NonPersistedIdentity = {
|
|
660
|
+
alias: 'test_alias1',
|
|
661
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
662
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
663
|
+
identifier: {
|
|
664
|
+
type: CorrelationIdentifierType.DID,
|
|
665
|
+
correlationId: 'example_did1',
|
|
666
|
+
},
|
|
667
|
+
}
|
|
668
|
+
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
669
|
+
expect(savedIdentity1).toBeDefined()
|
|
670
|
+
|
|
671
|
+
const identity2: NonPersistedIdentity = {
|
|
672
|
+
alias: 'test_alias2',
|
|
673
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
674
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
675
|
+
identifier: {
|
|
676
|
+
type: CorrelationIdentifierType.DID,
|
|
677
|
+
correlationId: 'example_did2',
|
|
678
|
+
},
|
|
679
|
+
}
|
|
680
|
+
const savedIdentity2: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity2 })
|
|
681
|
+
expect(savedIdentity2).toBeDefined()
|
|
682
|
+
|
|
683
|
+
const contactFirstName = 'updated_first_name'
|
|
684
|
+
const updatedParty: Party = {
|
|
685
|
+
...savedParty,
|
|
686
|
+
contact: {
|
|
687
|
+
...savedParty.contact,
|
|
688
|
+
firstName: contactFirstName,
|
|
689
|
+
},
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
await contactStore.updateParty({ party: updatedParty })
|
|
693
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
694
|
+
|
|
695
|
+
expect(result).toBeDefined()
|
|
696
|
+
expect((<NaturalPerson>result.contact).firstName).toEqual(contactFirstName)
|
|
697
|
+
expect(result.identities.length).toEqual(2)
|
|
698
|
+
})
|
|
699
|
+
|
|
700
|
+
it('should throw error when updating party with unknown id', async (): Promise<void> => {
|
|
701
|
+
const party: NonPersistedParty = {
|
|
702
|
+
uri: 'example.com',
|
|
703
|
+
partyType: {
|
|
704
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
705
|
+
origin: PartyOrigin.INTERNAL,
|
|
706
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
707
|
+
name: 'example_name',
|
|
708
|
+
},
|
|
709
|
+
contact: {
|
|
710
|
+
firstName: 'example_first_name',
|
|
711
|
+
middleName: 'example_middle_name',
|
|
712
|
+
lastName: 'example_last_name',
|
|
713
|
+
displayName: 'example_display_name',
|
|
714
|
+
},
|
|
715
|
+
}
|
|
716
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
717
|
+
expect(savedParty).toBeDefined()
|
|
718
|
+
|
|
719
|
+
const partyId = 'unknownPartyId'
|
|
720
|
+
const contactFirstName = 'updated_first_name'
|
|
721
|
+
const updatedParty: Party = {
|
|
722
|
+
...savedParty,
|
|
723
|
+
id: partyId,
|
|
724
|
+
contact: {
|
|
725
|
+
...savedParty.contact,
|
|
726
|
+
firstName: contactFirstName,
|
|
727
|
+
},
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
await expect(contactStore.updateParty({ party: updatedParty })).rejects.toThrow(`No party found for id: ${partyId}`)
|
|
731
|
+
})
|
|
732
|
+
|
|
733
|
+
it('should get identity by id', async (): Promise<void> => {
|
|
734
|
+
const party: NonPersistedParty = {
|
|
735
|
+
uri: 'example.com',
|
|
736
|
+
partyType: {
|
|
737
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
738
|
+
origin: PartyOrigin.INTERNAL,
|
|
739
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
740
|
+
name: 'example_name',
|
|
741
|
+
},
|
|
742
|
+
contact: {
|
|
743
|
+
firstName: 'example_first_name',
|
|
744
|
+
middleName: 'example_middle_name',
|
|
745
|
+
lastName: 'example_last_name',
|
|
746
|
+
displayName: 'example_display_name',
|
|
747
|
+
},
|
|
748
|
+
}
|
|
749
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
750
|
+
expect(savedParty).toBeDefined()
|
|
751
|
+
|
|
752
|
+
const identity: NonPersistedIdentity = {
|
|
753
|
+
alias: 'test_alias',
|
|
754
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
755
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
756
|
+
identifier: {
|
|
757
|
+
type: CorrelationIdentifierType.DID,
|
|
758
|
+
correlationId: 'example_did',
|
|
759
|
+
},
|
|
760
|
+
}
|
|
761
|
+
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
762
|
+
expect(savedIdentity).toBeDefined()
|
|
763
|
+
|
|
764
|
+
const result: Identity = await contactStore.getIdentity({ identityId: savedIdentity.id })
|
|
765
|
+
|
|
766
|
+
expect(result).toBeDefined()
|
|
767
|
+
})
|
|
768
|
+
|
|
769
|
+
it('should get holderDID identity by id', async (): Promise<void> => {
|
|
770
|
+
const party: NonPersistedParty = {
|
|
771
|
+
uri: 'example.com',
|
|
772
|
+
partyType: {
|
|
773
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
774
|
+
origin: PartyOrigin.INTERNAL,
|
|
775
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
776
|
+
name: 'example_name',
|
|
777
|
+
},
|
|
778
|
+
contact: {
|
|
779
|
+
firstName: 'example_first_name',
|
|
780
|
+
middleName: 'example_middle_name',
|
|
781
|
+
lastName: 'example_last_name',
|
|
782
|
+
displayName: 'example_display_name',
|
|
783
|
+
},
|
|
784
|
+
}
|
|
785
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
786
|
+
expect(savedParty).toBeDefined()
|
|
787
|
+
|
|
788
|
+
const identity: NonPersistedIdentity = {
|
|
789
|
+
alias: 'test_alias',
|
|
790
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
791
|
+
roles: [CredentialRole.HOLDER],
|
|
792
|
+
identifier: {
|
|
793
|
+
type: CorrelationIdentifierType.DID,
|
|
794
|
+
correlationId: 'example_did',
|
|
795
|
+
},
|
|
796
|
+
}
|
|
797
|
+
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
798
|
+
expect(savedIdentity).toBeDefined()
|
|
799
|
+
|
|
800
|
+
const result: Identity = await contactStore.getIdentity({ identityId: savedIdentity.id })
|
|
801
|
+
|
|
802
|
+
expect(result).toBeDefined()
|
|
803
|
+
})
|
|
804
|
+
|
|
805
|
+
it('should throw error when getting identity with unknown id', async (): Promise<void> => {
|
|
806
|
+
const identityId = 'unknownIdentityId'
|
|
807
|
+
|
|
808
|
+
await expect(contactStore.getIdentity({ identityId })).rejects.toThrow(`No identity found for id: ${identityId}`)
|
|
809
|
+
})
|
|
810
|
+
|
|
811
|
+
it('should get all identities for contact', async (): Promise<void> => {
|
|
812
|
+
const party: NonPersistedParty = {
|
|
813
|
+
uri: 'example.com',
|
|
814
|
+
partyType: {
|
|
815
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
816
|
+
origin: PartyOrigin.INTERNAL,
|
|
817
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
818
|
+
name: 'example_name',
|
|
819
|
+
},
|
|
820
|
+
contact: {
|
|
821
|
+
firstName: 'example_first_name',
|
|
822
|
+
middleName: 'example_middle_name',
|
|
823
|
+
lastName: 'example_last_name',
|
|
824
|
+
displayName: 'example_display_name',
|
|
825
|
+
},
|
|
826
|
+
}
|
|
827
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
828
|
+
expect(savedParty).toBeDefined()
|
|
829
|
+
|
|
830
|
+
const identity1: NonPersistedIdentity = {
|
|
831
|
+
alias: 'test_alias1',
|
|
832
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
833
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
834
|
+
identifier: {
|
|
835
|
+
type: CorrelationIdentifierType.DID,
|
|
836
|
+
correlationId: 'example_did1',
|
|
837
|
+
},
|
|
838
|
+
}
|
|
839
|
+
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
840
|
+
expect(savedIdentity1).toBeDefined()
|
|
841
|
+
|
|
842
|
+
const identity2: NonPersistedIdentity = {
|
|
843
|
+
alias: 'test_alias2',
|
|
844
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
845
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
846
|
+
identifier: {
|
|
847
|
+
type: CorrelationIdentifierType.DID,
|
|
848
|
+
correlationId: 'example_did2',
|
|
849
|
+
},
|
|
850
|
+
}
|
|
851
|
+
const savedIdentity2: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity2 })
|
|
852
|
+
expect(savedIdentity2).toBeDefined()
|
|
853
|
+
|
|
854
|
+
const args: GetIdentitiesArgs = {
|
|
855
|
+
filter: [{ partyId: savedParty.id }],
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
const result: Array<Identity> = await contactStore.getIdentities(args)
|
|
859
|
+
|
|
860
|
+
expect(result.length).toEqual(2)
|
|
861
|
+
})
|
|
862
|
+
|
|
863
|
+
it('should get all identities', async (): Promise<void> => {
|
|
864
|
+
const party: NonPersistedParty = {
|
|
865
|
+
uri: 'example.com',
|
|
866
|
+
partyType: {
|
|
867
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
868
|
+
origin: PartyOrigin.INTERNAL,
|
|
869
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
870
|
+
name: 'example_name',
|
|
871
|
+
},
|
|
872
|
+
contact: {
|
|
873
|
+
firstName: 'example_first_name',
|
|
874
|
+
middleName: 'example_middle_name',
|
|
875
|
+
lastName: 'example_last_name',
|
|
876
|
+
displayName: 'example_display_name',
|
|
877
|
+
},
|
|
878
|
+
}
|
|
879
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
880
|
+
expect(savedParty).toBeDefined()
|
|
881
|
+
|
|
882
|
+
const identity1: NonPersistedIdentity = {
|
|
883
|
+
alias: 'test_alias1',
|
|
884
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
885
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
886
|
+
identifier: {
|
|
887
|
+
type: CorrelationIdentifierType.DID,
|
|
888
|
+
correlationId: 'example_did1',
|
|
889
|
+
},
|
|
890
|
+
}
|
|
891
|
+
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
892
|
+
expect(savedIdentity1).toBeDefined()
|
|
893
|
+
|
|
894
|
+
const identity2: NonPersistedIdentity = {
|
|
895
|
+
alias: 'test_alias2',
|
|
896
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
897
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
898
|
+
identifier: {
|
|
899
|
+
type: CorrelationIdentifierType.DID,
|
|
900
|
+
correlationId: 'example_did2',
|
|
901
|
+
},
|
|
902
|
+
}
|
|
903
|
+
const savedIdentity2: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity2 })
|
|
904
|
+
expect(savedIdentity2).toBeDefined()
|
|
905
|
+
|
|
906
|
+
const result: Array<Identity> = await contactStore.getIdentities()
|
|
907
|
+
|
|
908
|
+
expect(result.length).toEqual(2)
|
|
909
|
+
})
|
|
910
|
+
|
|
911
|
+
it('should get identities by filter', async (): Promise<void> => {
|
|
912
|
+
const party: NonPersistedParty = {
|
|
913
|
+
uri: 'example.com',
|
|
914
|
+
partyType: {
|
|
915
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
916
|
+
origin: PartyOrigin.INTERNAL,
|
|
917
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
918
|
+
name: 'example_name',
|
|
919
|
+
},
|
|
920
|
+
contact: {
|
|
921
|
+
firstName: 'example_first_name',
|
|
922
|
+
middleName: 'example_middle_name',
|
|
923
|
+
lastName: 'example_last_name',
|
|
924
|
+
displayName: 'example_display_name',
|
|
925
|
+
},
|
|
926
|
+
}
|
|
927
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
928
|
+
expect(savedParty).toBeDefined()
|
|
929
|
+
|
|
930
|
+
const alias = 'test_alias1'
|
|
931
|
+
const identity1: NonPersistedIdentity = {
|
|
932
|
+
alias,
|
|
933
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
934
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
935
|
+
identifier: {
|
|
936
|
+
type: CorrelationIdentifierType.DID,
|
|
937
|
+
correlationId: 'example_did1',
|
|
938
|
+
},
|
|
939
|
+
}
|
|
940
|
+
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
941
|
+
expect(savedIdentity1).toBeDefined()
|
|
942
|
+
|
|
943
|
+
const identity2: NonPersistedIdentity = {
|
|
944
|
+
alias: 'test_alias2',
|
|
945
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
946
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
947
|
+
identifier: {
|
|
948
|
+
type: CorrelationIdentifierType.DID,
|
|
949
|
+
correlationId: 'example_did2',
|
|
950
|
+
},
|
|
951
|
+
}
|
|
952
|
+
const savedIdentity2: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity2 })
|
|
953
|
+
expect(savedIdentity2).toBeDefined()
|
|
954
|
+
|
|
955
|
+
const args: GetIdentitiesArgs = {
|
|
956
|
+
filter: [{ alias }],
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
const result: Array<Identity> = await contactStore.getIdentities(args)
|
|
960
|
+
|
|
961
|
+
expect(result.length).toEqual(1)
|
|
962
|
+
})
|
|
963
|
+
|
|
964
|
+
it('should get whole identities by filter', async (): Promise<void> => {
|
|
965
|
+
const party: NonPersistedParty = {
|
|
966
|
+
uri: 'example.com',
|
|
967
|
+
partyType: {
|
|
968
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
969
|
+
origin: PartyOrigin.INTERNAL,
|
|
970
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
971
|
+
name: 'example_name',
|
|
972
|
+
},
|
|
973
|
+
contact: {
|
|
974
|
+
firstName: 'example_first_name',
|
|
975
|
+
middleName: 'example_middle_name',
|
|
976
|
+
lastName: 'example_last_name',
|
|
977
|
+
displayName: 'example_display_name',
|
|
978
|
+
},
|
|
979
|
+
}
|
|
980
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
981
|
+
expect(savedParty).toBeDefined()
|
|
982
|
+
|
|
983
|
+
const alias = 'test_alias1'
|
|
984
|
+
const identity1: NonPersistedIdentity = {
|
|
985
|
+
alias,
|
|
986
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
987
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
988
|
+
identifier: {
|
|
989
|
+
type: CorrelationIdentifierType.DID,
|
|
990
|
+
correlationId: 'example_did1',
|
|
991
|
+
},
|
|
992
|
+
metadata: [
|
|
993
|
+
{
|
|
994
|
+
label: 'label1',
|
|
995
|
+
value: 'example_value',
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
label: 'label2',
|
|
999
|
+
value: 'example_value',
|
|
1000
|
+
},
|
|
1001
|
+
],
|
|
1002
|
+
}
|
|
1003
|
+
const savedIdentity1: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity: identity1 })
|
|
1004
|
+
expect(savedIdentity1).toBeDefined()
|
|
1005
|
+
|
|
1006
|
+
const args: GetIdentitiesArgs = {
|
|
1007
|
+
filter: [{ metadata: { label: 'label1', value: 'example_value' } }],
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
const result: Array<Identity> = await contactStore.getIdentities(args)
|
|
1011
|
+
|
|
1012
|
+
expect(result[0]).toBeDefined()
|
|
1013
|
+
expect(result[0].metadata!.length).toEqual(2)
|
|
1014
|
+
})
|
|
1015
|
+
|
|
1016
|
+
it('should add identity to contact', async (): Promise<void> => {
|
|
1017
|
+
const party: NonPersistedParty = {
|
|
1018
|
+
uri: 'example.com',
|
|
1019
|
+
partyType: {
|
|
1020
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1021
|
+
origin: PartyOrigin.INTERNAL,
|
|
1022
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1023
|
+
name: 'example_name',
|
|
1024
|
+
},
|
|
1025
|
+
contact: {
|
|
1026
|
+
firstName: 'example_first_name',
|
|
1027
|
+
middleName: 'example_middle_name',
|
|
1028
|
+
lastName: 'example_last_name',
|
|
1029
|
+
displayName: 'example_display_name',
|
|
1030
|
+
},
|
|
1031
|
+
}
|
|
1032
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
1033
|
+
expect(savedParty).toBeDefined()
|
|
1034
|
+
|
|
1035
|
+
const identity: NonPersistedIdentity = {
|
|
1036
|
+
alias: 'test_alias',
|
|
1037
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
1038
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
1039
|
+
identifier: {
|
|
1040
|
+
type: CorrelationIdentifierType.DID,
|
|
1041
|
+
correlationId: 'example_did',
|
|
1042
|
+
},
|
|
1043
|
+
}
|
|
1044
|
+
const savedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
1045
|
+
expect(savedIdentity).toBeDefined()
|
|
1046
|
+
|
|
1047
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
1048
|
+
expect(result.identities.length).toEqual(1)
|
|
1049
|
+
})
|
|
1050
|
+
|
|
1051
|
+
it('should throw error when removing identity with unknown id', async (): Promise<void> => {
|
|
1052
|
+
const identityId = 'unknownIdentityId'
|
|
1053
|
+
|
|
1054
|
+
await expect(contactStore.removeIdentity({ identityId })).rejects.toThrow(`No identity found for id: ${identityId}`)
|
|
1055
|
+
})
|
|
1056
|
+
|
|
1057
|
+
it('should throw error when adding identity with invalid identifier', async (): Promise<void> => {
|
|
1058
|
+
const party: NonPersistedParty = {
|
|
1059
|
+
uri: 'example.com',
|
|
1060
|
+
partyType: {
|
|
1061
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1062
|
+
origin: PartyOrigin.INTERNAL,
|
|
1063
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1064
|
+
name: 'example_name',
|
|
1065
|
+
},
|
|
1066
|
+
contact: {
|
|
1067
|
+
firstName: 'example_first_name',
|
|
1068
|
+
middleName: 'example_middle_name',
|
|
1069
|
+
lastName: 'example_last_name',
|
|
1070
|
+
displayName: 'example_display_name',
|
|
1071
|
+
},
|
|
1072
|
+
}
|
|
1073
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
1074
|
+
expect(savedParty).toBeDefined()
|
|
1075
|
+
|
|
1076
|
+
const correlationId = 'missing_connection_example'
|
|
1077
|
+
const identity: NonPersistedIdentity = {
|
|
1078
|
+
alias: correlationId,
|
|
1079
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
1080
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
1081
|
+
identifier: {
|
|
1082
|
+
type: CorrelationIdentifierType.URL,
|
|
1083
|
+
correlationId,
|
|
1084
|
+
},
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
await expect(contactStore.addIdentity({ partyId: savedParty.id, identity })).rejects.toThrow(
|
|
1088
|
+
`Identity with correlation type url should contain a connection`,
|
|
1089
|
+
)
|
|
1090
|
+
})
|
|
1091
|
+
|
|
1092
|
+
it('should throw error when updating identity with invalid identifier', async (): Promise<void> => {
|
|
1093
|
+
const party: NonPersistedParty = {
|
|
1094
|
+
uri: 'example.com',
|
|
1095
|
+
partyType: {
|
|
1096
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1097
|
+
origin: PartyOrigin.INTERNAL,
|
|
1098
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1099
|
+
name: 'example_name',
|
|
1100
|
+
},
|
|
1101
|
+
contact: {
|
|
1102
|
+
firstName: 'example_first_name',
|
|
1103
|
+
middleName: 'example_middle_name',
|
|
1104
|
+
lastName: 'example_last_name',
|
|
1105
|
+
displayName: 'example_display_name',
|
|
1106
|
+
},
|
|
1107
|
+
}
|
|
1108
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
1109
|
+
expect(savedParty).toBeDefined()
|
|
1110
|
+
|
|
1111
|
+
const correlationId = 'missing_connection_example'
|
|
1112
|
+
const identity: NonPersistedIdentity = {
|
|
1113
|
+
alias: correlationId,
|
|
1114
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
1115
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER, CredentialRole.HOLDER],
|
|
1116
|
+
identifier: {
|
|
1117
|
+
type: CorrelationIdentifierType.DID,
|
|
1118
|
+
correlationId,
|
|
1119
|
+
},
|
|
1120
|
+
}
|
|
1121
|
+
const storedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
1122
|
+
storedIdentity.identifier = { ...storedIdentity.identifier, type: CorrelationIdentifierType.URL }
|
|
1123
|
+
|
|
1124
|
+
await expect(contactStore.updateIdentity({ identity: storedIdentity })).rejects.toThrow(
|
|
1125
|
+
`Identity with correlation type url should contain a connection`,
|
|
1126
|
+
)
|
|
1127
|
+
})
|
|
1128
|
+
|
|
1129
|
+
it('should update identity by id', async (): Promise<void> => {
|
|
1130
|
+
const party: NonPersistedParty = {
|
|
1131
|
+
uri: 'example.com',
|
|
1132
|
+
partyType: {
|
|
1133
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1134
|
+
origin: PartyOrigin.INTERNAL,
|
|
1135
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1136
|
+
name: 'example_name',
|
|
1137
|
+
},
|
|
1138
|
+
contact: {
|
|
1139
|
+
firstName: 'example_first_name',
|
|
1140
|
+
middleName: 'example_middle_name',
|
|
1141
|
+
lastName: 'example_last_name',
|
|
1142
|
+
displayName: 'example_display_name',
|
|
1143
|
+
},
|
|
1144
|
+
}
|
|
1145
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
1146
|
+
expect(savedParty).toBeDefined()
|
|
1147
|
+
|
|
1148
|
+
const identity: NonPersistedIdentity = {
|
|
1149
|
+
alias: 'example_did',
|
|
1150
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
1151
|
+
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
|
|
1152
|
+
identifier: {
|
|
1153
|
+
type: CorrelationIdentifierType.DID,
|
|
1154
|
+
correlationId: 'example_did',
|
|
1155
|
+
},
|
|
1156
|
+
}
|
|
1157
|
+
const storedIdentity: Identity = await contactStore.addIdentity({ partyId: savedParty.id, identity })
|
|
1158
|
+
const correlationId = 'new_update_example_did'
|
|
1159
|
+
storedIdentity.identifier = { ...storedIdentity.identifier, correlationId }
|
|
1160
|
+
|
|
1161
|
+
await contactStore.updateIdentity({ identity: storedIdentity })
|
|
1162
|
+
const result: Identity = await contactStore.getIdentity({ identityId: storedIdentity.id })
|
|
1163
|
+
|
|
1164
|
+
expect(result).toBeDefined()
|
|
1165
|
+
expect(result.identifier.correlationId).toEqual(correlationId)
|
|
1166
|
+
})
|
|
1167
|
+
|
|
1168
|
+
it('should get aggregate of identity roles on party', async (): Promise<void> => {
|
|
1169
|
+
const party: NonPersistedParty = {
|
|
1170
|
+
uri: 'example.com',
|
|
1171
|
+
partyType: {
|
|
1172
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1173
|
+
origin: PartyOrigin.INTERNAL,
|
|
1174
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1175
|
+
name: 'example_name',
|
|
1176
|
+
},
|
|
1177
|
+
contact: {
|
|
1178
|
+
firstName: 'example_first_name',
|
|
1179
|
+
middleName: 'example_middle_name',
|
|
1180
|
+
lastName: 'example_last_name',
|
|
1181
|
+
displayName: 'example_display_name',
|
|
1182
|
+
},
|
|
1183
|
+
identities: [
|
|
1184
|
+
{
|
|
1185
|
+
alias: 'test_alias1',
|
|
1186
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
1187
|
+
roles: [CredentialRole.VERIFIER],
|
|
1188
|
+
identifier: {
|
|
1189
|
+
type: CorrelationIdentifierType.DID,
|
|
1190
|
+
correlationId: 'example_did1',
|
|
1191
|
+
},
|
|
1192
|
+
},
|
|
1193
|
+
{
|
|
1194
|
+
alias: 'test_alias2',
|
|
1195
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
1196
|
+
roles: [CredentialRole.ISSUER],
|
|
1197
|
+
identifier: {
|
|
1198
|
+
type: CorrelationIdentifierType.DID,
|
|
1199
|
+
correlationId: 'example_did2',
|
|
1200
|
+
},
|
|
1201
|
+
},
|
|
1202
|
+
{
|
|
1203
|
+
alias: 'test_alias3',
|
|
1204
|
+
origin: IdentityOrigin.EXTERNAL,
|
|
1205
|
+
roles: [CredentialRole.HOLDER],
|
|
1206
|
+
identifier: {
|
|
1207
|
+
type: CorrelationIdentifierType.DID,
|
|
1208
|
+
correlationId: 'example_did3',
|
|
1209
|
+
},
|
|
1210
|
+
},
|
|
1211
|
+
],
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
1215
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
1216
|
+
|
|
1217
|
+
expect(result.roles).toBeDefined()
|
|
1218
|
+
expect(result.roles.length).toEqual(3)
|
|
1219
|
+
expect(result.roles).toEqual([CredentialRole.VERIFIER, CredentialRole.ISSUER, CredentialRole.HOLDER])
|
|
1220
|
+
})
|
|
1221
|
+
|
|
1222
|
+
it('should add relationship', async (): Promise<void> => {
|
|
1223
|
+
const party1: NonPersistedParty = {
|
|
1224
|
+
uri: 'example1.com',
|
|
1225
|
+
partyType: {
|
|
1226
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1227
|
+
origin: PartyOrigin.INTERNAL,
|
|
1228
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1229
|
+
name: 'example_name1',
|
|
1230
|
+
},
|
|
1231
|
+
contact: {
|
|
1232
|
+
firstName: 'example_first_name1',
|
|
1233
|
+
middleName: 'example_middle_name1',
|
|
1234
|
+
lastName: 'example_last_name1',
|
|
1235
|
+
displayName: 'example_display_name1',
|
|
1236
|
+
},
|
|
1237
|
+
}
|
|
1238
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1239
|
+
expect(savedParty1).toBeDefined()
|
|
1240
|
+
|
|
1241
|
+
const party2: NonPersistedParty = {
|
|
1242
|
+
uri: 'example2.com',
|
|
1243
|
+
partyType: {
|
|
1244
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1245
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1246
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1247
|
+
name: 'example_name2',
|
|
1248
|
+
},
|
|
1249
|
+
contact: {
|
|
1250
|
+
firstName: 'example_first_name2',
|
|
1251
|
+
middleName: 'example_middle_name2',
|
|
1252
|
+
lastName: 'example_last_name2',
|
|
1253
|
+
displayName: 'example_display_name2',
|
|
1254
|
+
},
|
|
1255
|
+
}
|
|
1256
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1257
|
+
expect(savedParty2).toBeDefined()
|
|
1258
|
+
|
|
1259
|
+
const relationship: NonPersistedPartyRelationship = {
|
|
1260
|
+
leftId: savedParty1.id,
|
|
1261
|
+
rightId: savedParty2.id,
|
|
1262
|
+
}
|
|
1263
|
+
await contactStore.addRelationship(relationship)
|
|
1264
|
+
|
|
1265
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty1.id })
|
|
1266
|
+
|
|
1267
|
+
expect(result).toBeDefined()
|
|
1268
|
+
expect(result.relationships.length).toEqual(1)
|
|
1269
|
+
expect(result.relationships[0].leftId).toEqual(savedParty1.id)
|
|
1270
|
+
expect(result.relationships[0].rightId).toEqual(savedParty2.id)
|
|
1271
|
+
})
|
|
1272
|
+
|
|
1273
|
+
it('should get relationship', async (): Promise<void> => {
|
|
1274
|
+
const party1: NonPersistedParty = {
|
|
1275
|
+
uri: 'example1.com',
|
|
1276
|
+
partyType: {
|
|
1277
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1278
|
+
origin: PartyOrigin.INTERNAL,
|
|
1279
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1280
|
+
name: 'example_name1',
|
|
1281
|
+
},
|
|
1282
|
+
contact: {
|
|
1283
|
+
firstName: 'example_first_name1',
|
|
1284
|
+
middleName: 'example_middle_name1',
|
|
1285
|
+
lastName: 'example_last_name1',
|
|
1286
|
+
displayName: 'example_display_name1',
|
|
1287
|
+
},
|
|
1288
|
+
}
|
|
1289
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1290
|
+
expect(savedParty1).toBeDefined()
|
|
1291
|
+
|
|
1292
|
+
const party2: NonPersistedParty = {
|
|
1293
|
+
uri: 'example2.com',
|
|
1294
|
+
partyType: {
|
|
1295
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1296
|
+
origin: PartyOrigin.INTERNAL,
|
|
1297
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1298
|
+
name: 'example_name2',
|
|
1299
|
+
},
|
|
1300
|
+
contact: {
|
|
1301
|
+
firstName: 'example_first_name2',
|
|
1302
|
+
middleName: 'example_middle_name2',
|
|
1303
|
+
lastName: 'example_last_name2',
|
|
1304
|
+
displayName: 'example_display_name2',
|
|
1305
|
+
},
|
|
1306
|
+
}
|
|
1307
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1308
|
+
expect(savedParty2).toBeDefined()
|
|
1309
|
+
|
|
1310
|
+
const relationship: NonPersistedPartyRelationship = {
|
|
1311
|
+
leftId: savedParty1.id,
|
|
1312
|
+
rightId: savedParty2.id,
|
|
1313
|
+
}
|
|
1314
|
+
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1315
|
+
|
|
1316
|
+
const result: PartyRelationship = await contactStore.getRelationship({ relationshipId: savedRelationship.id })
|
|
1317
|
+
|
|
1318
|
+
expect(result).toBeDefined()
|
|
1319
|
+
expect(result.leftId).toEqual(savedParty1.id)
|
|
1320
|
+
expect(result.rightId).toEqual(savedParty2.id)
|
|
1321
|
+
})
|
|
1322
|
+
|
|
1323
|
+
it('should throw error when getting relationship with unknown id', async (): Promise<void> => {
|
|
1324
|
+
const relationshipId = 'unknownRelationshipId'
|
|
1325
|
+
|
|
1326
|
+
await expect(contactStore.getRelationship({ relationshipId })).rejects.toThrow(`No relationship found for id: ${relationshipId}`)
|
|
1327
|
+
})
|
|
1328
|
+
|
|
1329
|
+
it('should get all relationships', async (): Promise<void> => {
|
|
1330
|
+
const party1: NonPersistedParty = {
|
|
1331
|
+
uri: 'example1.com',
|
|
1332
|
+
partyType: {
|
|
1333
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1334
|
+
origin: PartyOrigin.INTERNAL,
|
|
1335
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1336
|
+
name: 'example_name1',
|
|
1337
|
+
},
|
|
1338
|
+
contact: {
|
|
1339
|
+
firstName: 'example_first_name1',
|
|
1340
|
+
middleName: 'example_middle_name1',
|
|
1341
|
+
lastName: 'example_last_name1',
|
|
1342
|
+
displayName: 'example_display_name1',
|
|
1343
|
+
},
|
|
1344
|
+
}
|
|
1345
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1346
|
+
expect(savedParty1).toBeDefined()
|
|
1347
|
+
|
|
1348
|
+
const party2: NonPersistedParty = {
|
|
1349
|
+
uri: 'example2.com',
|
|
1350
|
+
partyType: {
|
|
1351
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1352
|
+
origin: PartyOrigin.INTERNAL,
|
|
1353
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1354
|
+
name: 'example_name2',
|
|
1355
|
+
},
|
|
1356
|
+
contact: {
|
|
1357
|
+
firstName: 'example_first_name2',
|
|
1358
|
+
middleName: 'example_middle_name2',
|
|
1359
|
+
lastName: 'example_last_name2',
|
|
1360
|
+
displayName: 'example_display_name2',
|
|
1361
|
+
},
|
|
1362
|
+
}
|
|
1363
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1364
|
+
expect(savedParty2).toBeDefined()
|
|
1365
|
+
|
|
1366
|
+
const relationship1: NonPersistedPartyRelationship = {
|
|
1367
|
+
leftId: savedParty1.id,
|
|
1368
|
+
rightId: savedParty2.id,
|
|
1369
|
+
}
|
|
1370
|
+
await contactStore.addRelationship(relationship1)
|
|
1371
|
+
|
|
1372
|
+
const relationship2: NonPersistedPartyRelationship = {
|
|
1373
|
+
leftId: savedParty2.id,
|
|
1374
|
+
rightId: savedParty1.id,
|
|
1375
|
+
}
|
|
1376
|
+
await contactStore.addRelationship(relationship2)
|
|
1377
|
+
|
|
1378
|
+
const result: Array<PartyRelationship> = await contactStore.getRelationships()
|
|
1379
|
+
|
|
1380
|
+
expect(result).toBeDefined()
|
|
1381
|
+
expect(result.length).toEqual(2)
|
|
1382
|
+
})
|
|
1383
|
+
|
|
1384
|
+
it('should get relationships by filter', async (): Promise<void> => {
|
|
1385
|
+
const party1: NonPersistedParty = {
|
|
1386
|
+
uri: 'example1.com',
|
|
1387
|
+
partyType: {
|
|
1388
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1389
|
+
origin: PartyOrigin.INTERNAL,
|
|
1390
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1391
|
+
name: 'example_name1',
|
|
1392
|
+
},
|
|
1393
|
+
contact: {
|
|
1394
|
+
firstName: 'example_first_name1',
|
|
1395
|
+
middleName: 'example_middle_name1',
|
|
1396
|
+
lastName: 'example_last_name1',
|
|
1397
|
+
displayName: 'example_display_name1',
|
|
1398
|
+
},
|
|
1399
|
+
}
|
|
1400
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1401
|
+
expect(savedParty1).toBeDefined()
|
|
1402
|
+
|
|
1403
|
+
const party2: NonPersistedParty = {
|
|
1404
|
+
uri: 'example2.com',
|
|
1405
|
+
partyType: {
|
|
1406
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1407
|
+
origin: PartyOrigin.INTERNAL,
|
|
1408
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1409
|
+
name: 'example_name2',
|
|
1410
|
+
},
|
|
1411
|
+
contact: {
|
|
1412
|
+
firstName: 'example_first_name2',
|
|
1413
|
+
middleName: 'example_middle_name2',
|
|
1414
|
+
lastName: 'example_last_name2',
|
|
1415
|
+
displayName: 'example_display_name2',
|
|
1416
|
+
},
|
|
1417
|
+
}
|
|
1418
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1419
|
+
expect(savedParty2).toBeDefined()
|
|
1420
|
+
|
|
1421
|
+
const relationship1: NonPersistedPartyRelationship = {
|
|
1422
|
+
leftId: savedParty1.id,
|
|
1423
|
+
rightId: savedParty2.id,
|
|
1424
|
+
}
|
|
1425
|
+
await contactStore.addRelationship(relationship1)
|
|
1426
|
+
|
|
1427
|
+
const relationship2: NonPersistedPartyRelationship = {
|
|
1428
|
+
leftId: savedParty2.id,
|
|
1429
|
+
rightId: savedParty1.id,
|
|
1430
|
+
}
|
|
1431
|
+
await contactStore.addRelationship(relationship2)
|
|
1432
|
+
|
|
1433
|
+
const args: GetRelationshipsArgs = {
|
|
1434
|
+
filter: [
|
|
1435
|
+
{
|
|
1436
|
+
leftId: savedParty1.id,
|
|
1437
|
+
rightId: savedParty2.id,
|
|
1438
|
+
},
|
|
1439
|
+
],
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
const result: Array<PartyRelationship> = await contactStore.getRelationships(args)
|
|
1443
|
+
|
|
1444
|
+
expect(result).toBeDefined()
|
|
1445
|
+
expect(result.length).toEqual(1)
|
|
1446
|
+
})
|
|
1447
|
+
|
|
1448
|
+
it('should remove relationship', async (): Promise<void> => {
|
|
1449
|
+
const party1: NonPersistedParty = {
|
|
1450
|
+
uri: 'example1.com',
|
|
1451
|
+
partyType: {
|
|
1452
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1453
|
+
origin: PartyOrigin.INTERNAL,
|
|
1454
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1455
|
+
name: 'example_name1',
|
|
1456
|
+
},
|
|
1457
|
+
contact: {
|
|
1458
|
+
firstName: 'example_first_name1',
|
|
1459
|
+
middleName: 'example_middle_name1',
|
|
1460
|
+
lastName: 'example_last_name1',
|
|
1461
|
+
displayName: 'example_display_name1',
|
|
1462
|
+
},
|
|
1463
|
+
}
|
|
1464
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1465
|
+
expect(savedParty1).toBeDefined()
|
|
1466
|
+
|
|
1467
|
+
const party2: NonPersistedParty = {
|
|
1468
|
+
uri: 'example2.com',
|
|
1469
|
+
partyType: {
|
|
1470
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1471
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1472
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1473
|
+
name: 'example_name2',
|
|
1474
|
+
},
|
|
1475
|
+
contact: {
|
|
1476
|
+
firstName: 'example_first_name2',
|
|
1477
|
+
middleName: 'example_middle_name2',
|
|
1478
|
+
lastName: 'example_last_name2',
|
|
1479
|
+
displayName: 'example_display_name2',
|
|
1480
|
+
},
|
|
1481
|
+
}
|
|
1482
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1483
|
+
expect(savedParty2).toBeDefined()
|
|
1484
|
+
|
|
1485
|
+
const relationship: NonPersistedPartyRelationship = {
|
|
1486
|
+
leftId: savedParty1.id,
|
|
1487
|
+
rightId: savedParty2.id,
|
|
1488
|
+
}
|
|
1489
|
+
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1490
|
+
expect(savedRelationship).toBeDefined()
|
|
1491
|
+
|
|
1492
|
+
await contactStore.removeRelationship({ relationshipId: savedRelationship.id })
|
|
1493
|
+
|
|
1494
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty1.id })
|
|
1495
|
+
|
|
1496
|
+
expect(result).toBeDefined()
|
|
1497
|
+
expect(result?.relationships?.length).toEqual(0)
|
|
1498
|
+
})
|
|
1499
|
+
|
|
1500
|
+
it('should throw error when removing relationship with unknown id', async (): Promise<void> => {
|
|
1501
|
+
const relationshipId = 'unknownRelationshipId'
|
|
1502
|
+
|
|
1503
|
+
await expect(contactStore.removeRelationship({ relationshipId })).rejects.toThrow(`No relationship found for id: ${relationshipId}`)
|
|
1504
|
+
})
|
|
1505
|
+
|
|
1506
|
+
it('should return no relationships if filter does not match', async (): Promise<void> => {
|
|
1507
|
+
const args: GetRelationshipsArgs = {
|
|
1508
|
+
filter: [
|
|
1509
|
+
{
|
|
1510
|
+
leftId: 'unknown_id',
|
|
1511
|
+
},
|
|
1512
|
+
],
|
|
1513
|
+
}
|
|
1514
|
+
const result: Array<PartyRelationship> = await contactStore.getRelationships(args)
|
|
1515
|
+
|
|
1516
|
+
expect(result.length).toEqual(0)
|
|
1517
|
+
})
|
|
1518
|
+
|
|
1519
|
+
it('should update relationship by id', async (): Promise<void> => {
|
|
1520
|
+
const party1: NonPersistedParty = {
|
|
1521
|
+
uri: 'example1.com',
|
|
1522
|
+
partyType: {
|
|
1523
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1524
|
+
origin: PartyOrigin.INTERNAL,
|
|
1525
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1526
|
+
name: 'example_name1',
|
|
1527
|
+
},
|
|
1528
|
+
contact: {
|
|
1529
|
+
firstName: 'example_first_name1',
|
|
1530
|
+
middleName: 'example_middle_name1',
|
|
1531
|
+
lastName: 'example_last_name1',
|
|
1532
|
+
displayName: 'example_display_name1',
|
|
1533
|
+
},
|
|
1534
|
+
}
|
|
1535
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1536
|
+
expect(savedParty1).toBeDefined()
|
|
1537
|
+
|
|
1538
|
+
const party2: NonPersistedParty = {
|
|
1539
|
+
uri: 'example2.com',
|
|
1540
|
+
partyType: {
|
|
1541
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1542
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1543
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1544
|
+
name: 'example_name2',
|
|
1545
|
+
},
|
|
1546
|
+
contact: {
|
|
1547
|
+
firstName: 'example_first_name2',
|
|
1548
|
+
middleName: 'example_middle_name2',
|
|
1549
|
+
lastName: 'example_last_name2',
|
|
1550
|
+
displayName: 'example_display_name2',
|
|
1551
|
+
},
|
|
1552
|
+
}
|
|
1553
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1554
|
+
expect(savedParty2).toBeDefined()
|
|
1555
|
+
|
|
1556
|
+
const party3: NonPersistedParty = {
|
|
1557
|
+
uri: 'example3.com',
|
|
1558
|
+
partyType: {
|
|
1559
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1560
|
+
origin: PartyOrigin.INTERNAL,
|
|
1561
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287',
|
|
1562
|
+
name: 'example_name3',
|
|
1563
|
+
},
|
|
1564
|
+
contact: {
|
|
1565
|
+
firstName: 'example_first_name3',
|
|
1566
|
+
middleName: 'example_middle_name3',
|
|
1567
|
+
lastName: 'example_last_name3',
|
|
1568
|
+
displayName: 'example_display_name3',
|
|
1569
|
+
},
|
|
1570
|
+
}
|
|
1571
|
+
const savedParty3: Party = await contactStore.addParty(party3)
|
|
1572
|
+
expect(savedParty3).toBeDefined()
|
|
1573
|
+
|
|
1574
|
+
const relationship: NonPersistedPartyRelationship = {
|
|
1575
|
+
leftId: savedParty1.id,
|
|
1576
|
+
rightId: savedParty2.id,
|
|
1577
|
+
}
|
|
1578
|
+
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1579
|
+
|
|
1580
|
+
const updatedRelationship: PartyRelationship = {
|
|
1581
|
+
...savedRelationship,
|
|
1582
|
+
rightId: savedParty3.id,
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
await contactStore.updateRelationship({ relationship: updatedRelationship })
|
|
1586
|
+
|
|
1587
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty1.id })
|
|
1588
|
+
|
|
1589
|
+
expect(result).toBeDefined()
|
|
1590
|
+
expect(result.relationships.length).toEqual(1)
|
|
1591
|
+
expect(result.relationships[0].leftId).toEqual(savedParty1.id)
|
|
1592
|
+
expect(result.relationships[0].rightId).toEqual(savedParty3.id)
|
|
1593
|
+
})
|
|
1594
|
+
|
|
1595
|
+
it('should throw error when updating relationship with unknown id', async (): Promise<void> => {
|
|
1596
|
+
const party1: NonPersistedParty = {
|
|
1597
|
+
uri: 'example1.com',
|
|
1598
|
+
partyType: {
|
|
1599
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1600
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1601
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1602
|
+
name: 'example_name1',
|
|
1603
|
+
},
|
|
1604
|
+
contact: {
|
|
1605
|
+
firstName: 'example_first_name1',
|
|
1606
|
+
middleName: 'example_middle_name1',
|
|
1607
|
+
lastName: 'example_last_name1',
|
|
1608
|
+
displayName: 'example_display_name1',
|
|
1609
|
+
},
|
|
1610
|
+
}
|
|
1611
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1612
|
+
expect(savedParty1).toBeDefined()
|
|
1613
|
+
|
|
1614
|
+
const party2: NonPersistedParty = {
|
|
1615
|
+
uri: 'example2.com',
|
|
1616
|
+
partyType: {
|
|
1617
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1618
|
+
origin: PartyOrigin.INTERNAL,
|
|
1619
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1620
|
+
name: 'example_name2',
|
|
1621
|
+
},
|
|
1622
|
+
contact: {
|
|
1623
|
+
firstName: 'example_first_name2',
|
|
1624
|
+
middleName: 'example_middle_name2',
|
|
1625
|
+
lastName: 'example_last_name2',
|
|
1626
|
+
displayName: 'example_display_name2',
|
|
1627
|
+
},
|
|
1628
|
+
}
|
|
1629
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1630
|
+
expect(savedParty2).toBeDefined()
|
|
1631
|
+
|
|
1632
|
+
const relationship: NonPersistedPartyRelationship = {
|
|
1633
|
+
leftId: savedParty1.id,
|
|
1634
|
+
rightId: savedParty2.id,
|
|
1635
|
+
}
|
|
1636
|
+
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1637
|
+
|
|
1638
|
+
const relationshipId = 'unknownRelationshipId'
|
|
1639
|
+
const updatedRelationship: PartyRelationship = {
|
|
1640
|
+
...savedRelationship,
|
|
1641
|
+
id: relationshipId,
|
|
1642
|
+
rightId: savedParty2.id,
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
await expect(contactStore.updateRelationship({ relationship: updatedRelationship })).rejects.toThrow(
|
|
1646
|
+
`No party relationship found for id: ${relationshipId}`,
|
|
1647
|
+
)
|
|
1648
|
+
})
|
|
1649
|
+
|
|
1650
|
+
it('should throw error when updating relationship with unknown right side id', async (): Promise<void> => {
|
|
1651
|
+
const party1: NonPersistedParty = {
|
|
1652
|
+
uri: 'example1.com',
|
|
1653
|
+
partyType: {
|
|
1654
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1655
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1656
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1657
|
+
name: 'example_name1',
|
|
1658
|
+
},
|
|
1659
|
+
contact: {
|
|
1660
|
+
firstName: 'example_first_name1',
|
|
1661
|
+
middleName: 'example_middle_name1',
|
|
1662
|
+
lastName: 'example_last_name1',
|
|
1663
|
+
displayName: 'example_display_name1',
|
|
1664
|
+
},
|
|
1665
|
+
}
|
|
1666
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1667
|
+
expect(savedParty1).toBeDefined()
|
|
1668
|
+
|
|
1669
|
+
const party2: NonPersistedParty = {
|
|
1670
|
+
uri: 'example2.com',
|
|
1671
|
+
partyType: {
|
|
1672
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1673
|
+
origin: PartyOrigin.INTERNAL,
|
|
1674
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1675
|
+
name: 'example_name2',
|
|
1676
|
+
},
|
|
1677
|
+
contact: {
|
|
1678
|
+
firstName: 'example_first_name2',
|
|
1679
|
+
middleName: 'example_middle_name2',
|
|
1680
|
+
lastName: 'example_last_name2',
|
|
1681
|
+
displayName: 'example_display_name2',
|
|
1682
|
+
},
|
|
1683
|
+
}
|
|
1684
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1685
|
+
expect(savedParty2).toBeDefined()
|
|
1686
|
+
|
|
1687
|
+
const relationship: NonPersistedPartyRelationship = {
|
|
1688
|
+
leftId: savedParty1.id,
|
|
1689
|
+
rightId: savedParty2.id,
|
|
1690
|
+
}
|
|
1691
|
+
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1692
|
+
|
|
1693
|
+
const partyId = 'unknownPartyId'
|
|
1694
|
+
const updatedRelationship: PartyRelationship = {
|
|
1695
|
+
...savedRelationship,
|
|
1696
|
+
rightId: partyId,
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
await expect(contactStore.updateRelationship({ relationship: updatedRelationship })).rejects.toThrow(
|
|
1700
|
+
`No party found for right side of the relationship, party id: ${partyId}`,
|
|
1701
|
+
)
|
|
1702
|
+
})
|
|
1703
|
+
|
|
1704
|
+
it('should throw error when updating relationship with unknown left side id', async (): Promise<void> => {
|
|
1705
|
+
const party1: NonPersistedParty = {
|
|
1706
|
+
uri: 'example1.com',
|
|
1707
|
+
partyType: {
|
|
1708
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1709
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1710
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1711
|
+
name: 'example_name1',
|
|
1712
|
+
},
|
|
1713
|
+
contact: {
|
|
1714
|
+
firstName: 'example_first_name1',
|
|
1715
|
+
middleName: 'example_middle_name1',
|
|
1716
|
+
lastName: 'example_last_name1',
|
|
1717
|
+
displayName: 'example_display_name1',
|
|
1718
|
+
},
|
|
1719
|
+
}
|
|
1720
|
+
const savedParty1: Party = await contactStore.addParty(party1)
|
|
1721
|
+
expect(savedParty1).toBeDefined()
|
|
1722
|
+
|
|
1723
|
+
const party2: NonPersistedParty = {
|
|
1724
|
+
uri: 'example2.com',
|
|
1725
|
+
partyType: {
|
|
1726
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1727
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1728
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1729
|
+
name: 'example_name2',
|
|
1730
|
+
},
|
|
1731
|
+
contact: {
|
|
1732
|
+
firstName: 'example_first_name2',
|
|
1733
|
+
middleName: 'example_middle_name2',
|
|
1734
|
+
lastName: 'example_last_name2',
|
|
1735
|
+
displayName: 'example_display_name2',
|
|
1736
|
+
},
|
|
1737
|
+
}
|
|
1738
|
+
const savedParty2: Party = await contactStore.addParty(party2)
|
|
1739
|
+
expect(savedParty2).toBeDefined()
|
|
1740
|
+
|
|
1741
|
+
const relationship: NonPersistedPartyRelationship = {
|
|
1742
|
+
leftId: savedParty1.id,
|
|
1743
|
+
rightId: savedParty2.id,
|
|
1744
|
+
}
|
|
1745
|
+
const savedRelationship: PartyRelationship = await contactStore.addRelationship(relationship)
|
|
1746
|
+
|
|
1747
|
+
const partyId = 'unknownPartyId'
|
|
1748
|
+
const updatedRelationship: PartyRelationship = {
|
|
1749
|
+
...savedRelationship,
|
|
1750
|
+
leftId: partyId,
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
await expect(contactStore.updateRelationship({ relationship: updatedRelationship })).rejects.toThrow(
|
|
1754
|
+
`No party found for left side of the relationship, party id: ${partyId}`,
|
|
1755
|
+
)
|
|
1756
|
+
})
|
|
1757
|
+
|
|
1758
|
+
it('should add party type', async (): Promise<void> => {
|
|
1759
|
+
const partyType: NonPersistedPartyType = {
|
|
1760
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1761
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1762
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1763
|
+
name: 'example_name',
|
|
1764
|
+
description: 'example_description',
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1768
|
+
const result: PartyType = await contactStore.getPartyType({ partyTypeId: savedPartyType.id })
|
|
1769
|
+
|
|
1770
|
+
expect(result).toBeDefined()
|
|
1771
|
+
expect(result.name).toEqual(partyType.name)
|
|
1772
|
+
expect(result.type).toEqual(partyType.type)
|
|
1773
|
+
expect(result.origin).toEqual(partyType.origin)
|
|
1774
|
+
expect(result.tenantId).toEqual(partyType.tenantId)
|
|
1775
|
+
expect(result.description).toEqual(partyType.description)
|
|
1776
|
+
expect(result.lastUpdatedAt).toBeDefined()
|
|
1777
|
+
expect(result.createdAt).toBeDefined()
|
|
1778
|
+
})
|
|
1779
|
+
|
|
1780
|
+
it('should get party types by filter', async (): Promise<void> => {
|
|
1781
|
+
const partyType1: NonPersistedPartyType = {
|
|
1782
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1783
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1784
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1785
|
+
name: 'example_name1',
|
|
1786
|
+
description: 'example_description1',
|
|
1787
|
+
}
|
|
1788
|
+
const savedPartyType1: PartyType = await contactStore.addPartyType(partyType1)
|
|
1789
|
+
expect(savedPartyType1).toBeDefined()
|
|
1790
|
+
|
|
1791
|
+
const partyType2: NonPersistedPartyType = {
|
|
1792
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1793
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1794
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287',
|
|
1795
|
+
name: 'example_name2',
|
|
1796
|
+
description: 'example_description2',
|
|
1797
|
+
}
|
|
1798
|
+
const savedPartyType2: PartyType = await contactStore.addPartyType(partyType2)
|
|
1799
|
+
expect(savedPartyType2).toBeDefined()
|
|
1800
|
+
|
|
1801
|
+
const result: Array<PartyType> = await contactStore.getPartyTypes({
|
|
1802
|
+
filter: [
|
|
1803
|
+
{
|
|
1804
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1805
|
+
name: 'example_name1',
|
|
1806
|
+
description: 'example_description1',
|
|
1807
|
+
},
|
|
1808
|
+
],
|
|
1809
|
+
})
|
|
1810
|
+
|
|
1811
|
+
expect(result).toBeDefined()
|
|
1812
|
+
expect(result.length).toEqual(1)
|
|
1813
|
+
})
|
|
1814
|
+
|
|
1815
|
+
it('should return no party types if filter does not match', async (): Promise<void> => {
|
|
1816
|
+
const partyType1: NonPersistedPartyType = {
|
|
1817
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1818
|
+
origin: PartyOrigin.INTERNAL,
|
|
1819
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1820
|
+
name: 'example_name1',
|
|
1821
|
+
description: 'example_description1',
|
|
1822
|
+
}
|
|
1823
|
+
const savedPartyType1: PartyType = await contactStore.addPartyType(partyType1)
|
|
1824
|
+
expect(savedPartyType1).toBeDefined()
|
|
1825
|
+
|
|
1826
|
+
const partyType2: NonPersistedPartyType = {
|
|
1827
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1828
|
+
origin: PartyOrigin.INTERNAL,
|
|
1829
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287',
|
|
1830
|
+
name: 'example_name2',
|
|
1831
|
+
description: 'example_description2',
|
|
1832
|
+
}
|
|
1833
|
+
const savedPartyType2: PartyType = await contactStore.addPartyType(partyType2)
|
|
1834
|
+
expect(savedPartyType2).toBeDefined()
|
|
1835
|
+
|
|
1836
|
+
const result: Array<PartyType> = await contactStore.getPartyTypes({
|
|
1837
|
+
filter: [
|
|
1838
|
+
{
|
|
1839
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1840
|
+
name: 'unknown_name',
|
|
1841
|
+
description: 'unknown_description',
|
|
1842
|
+
},
|
|
1843
|
+
],
|
|
1844
|
+
})
|
|
1845
|
+
|
|
1846
|
+
expect(result).toBeDefined()
|
|
1847
|
+
expect(result.length).toEqual(0)
|
|
1848
|
+
})
|
|
1849
|
+
|
|
1850
|
+
it('should throw error when updating party type with unknown id', async (): Promise<void> => {
|
|
1851
|
+
const partyType: NonPersistedPartyType = {
|
|
1852
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1853
|
+
origin: PartyOrigin.INTERNAL,
|
|
1854
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1855
|
+
name: 'example_name',
|
|
1856
|
+
description: 'example_description',
|
|
1857
|
+
}
|
|
1858
|
+
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1859
|
+
expect(savedPartyType).toBeDefined()
|
|
1860
|
+
|
|
1861
|
+
const partyTypeId = 'unknownPartyTypeId'
|
|
1862
|
+
const updatedPartyType: PartyType = {
|
|
1863
|
+
...savedPartyType,
|
|
1864
|
+
id: partyTypeId,
|
|
1865
|
+
description: 'new_example_description',
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
await expect(contactStore.updatePartyType({ partyType: updatedPartyType })).rejects.toThrow(`No party type found for id: ${partyTypeId}`)
|
|
1869
|
+
})
|
|
1870
|
+
|
|
1871
|
+
it('should update party type by id', async (): Promise<void> => {
|
|
1872
|
+
const partyType: NonPersistedPartyType = {
|
|
1873
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1874
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1875
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1876
|
+
name: 'example_name',
|
|
1877
|
+
description: 'example_description',
|
|
1878
|
+
}
|
|
1879
|
+
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1880
|
+
expect(savedPartyType).toBeDefined()
|
|
1881
|
+
|
|
1882
|
+
const newDescription = 'new_example_description'
|
|
1883
|
+
const updatedPartyType: PartyType = {
|
|
1884
|
+
...savedPartyType,
|
|
1885
|
+
description: newDescription,
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
const result: PartyType = await contactStore.updatePartyType({ partyType: updatedPartyType })
|
|
1889
|
+
|
|
1890
|
+
expect(result).toBeDefined()
|
|
1891
|
+
expect(result.description).toEqual(newDescription)
|
|
1892
|
+
})
|
|
1893
|
+
|
|
1894
|
+
it('should throw error when removing party type with unknown id', async (): Promise<void> => {
|
|
1895
|
+
const partyTypeId = 'unknownPartyTypeId'
|
|
1896
|
+
|
|
1897
|
+
await expect(contactStore.removePartyType({ partyTypeId })).rejects.toThrow(`No party type found for id: ${partyTypeId}`)
|
|
1898
|
+
})
|
|
1899
|
+
|
|
1900
|
+
it('should remove party type', async (): Promise<void> => {
|
|
1901
|
+
const partyType: NonPersistedPartyType = {
|
|
1902
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1903
|
+
origin: PartyOrigin.INTERNAL,
|
|
1904
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288',
|
|
1905
|
+
name: 'example_name',
|
|
1906
|
+
description: 'example_description',
|
|
1907
|
+
}
|
|
1908
|
+
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1909
|
+
expect(savedPartyType).toBeDefined()
|
|
1910
|
+
|
|
1911
|
+
const resultPartyType: PartyType = await contactStore.getPartyType({ partyTypeId: savedPartyType.id })
|
|
1912
|
+
expect(resultPartyType).toBeDefined()
|
|
1913
|
+
|
|
1914
|
+
const includingMigrationPartyTypes: Array<PartyType> = await contactStore.getPartyTypes()
|
|
1915
|
+
// We are checking for 3 types here as we include the ones from the migrations
|
|
1916
|
+
expect(includingMigrationPartyTypes.length).toEqual(3)
|
|
1917
|
+
|
|
1918
|
+
await contactStore.removePartyType({ partyTypeId: savedPartyType.id })
|
|
1919
|
+
|
|
1920
|
+
const result: Array<PartyType> = await contactStore.getPartyTypes()
|
|
1921
|
+
|
|
1922
|
+
expect(result).toBeDefined()
|
|
1923
|
+
expect(result.length).toEqual(2)
|
|
1924
|
+
})
|
|
1925
|
+
|
|
1926
|
+
it('should throw error when removing party type attached to contact', async (): Promise<void> => {
|
|
1927
|
+
const party: NonPersistedParty = {
|
|
1928
|
+
uri: 'example.com',
|
|
1929
|
+
partyType: {
|
|
1930
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1931
|
+
origin: PartyOrigin.EXTERNAL,
|
|
1932
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1933
|
+
name: 'example_name',
|
|
1934
|
+
},
|
|
1935
|
+
contact: {
|
|
1936
|
+
firstName: 'example_first_name',
|
|
1937
|
+
middleName: 'example_middle_name',
|
|
1938
|
+
lastName: 'example_last_name',
|
|
1939
|
+
displayName: 'example_display_name',
|
|
1940
|
+
},
|
|
1941
|
+
}
|
|
1942
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
1943
|
+
expect(savedParty).toBeDefined()
|
|
1944
|
+
|
|
1945
|
+
await expect(contactStore.removePartyType({ partyTypeId: savedParty.partyType.id })).rejects.toThrow(
|
|
1946
|
+
`Unable to remove party type with id: ${savedParty.partyType.id}. Party type is in use`,
|
|
1947
|
+
)
|
|
1948
|
+
})
|
|
1949
|
+
|
|
1950
|
+
it('Should save party with existing party type', async (): Promise<void> => {
|
|
1951
|
+
const partyType: NonPersistedPartyType = {
|
|
1952
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
1953
|
+
origin: PartyOrigin.INTERNAL,
|
|
1954
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1955
|
+
name: 'example_name',
|
|
1956
|
+
}
|
|
1957
|
+
const savedPartyType: PartyType = await contactStore.addPartyType(partyType)
|
|
1958
|
+
expect(savedPartyType).toBeDefined()
|
|
1959
|
+
|
|
1960
|
+
const party: NonPersistedParty = {
|
|
1961
|
+
uri: 'example.com',
|
|
1962
|
+
partyType: savedPartyType,
|
|
1963
|
+
contact: {
|
|
1964
|
+
firstName: 'example_first_name',
|
|
1965
|
+
middleName: 'example_middle_name',
|
|
1966
|
+
lastName: 'example_last_name',
|
|
1967
|
+
displayName: 'example_display_name',
|
|
1968
|
+
},
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
const result: Party = await contactStore.addParty(party)
|
|
1972
|
+
|
|
1973
|
+
expect(result).toBeDefined()
|
|
1974
|
+
expect(result?.partyType).toBeDefined()
|
|
1975
|
+
expect(result?.partyType.id).toEqual(savedPartyType.id)
|
|
1976
|
+
expect(result?.partyType.type).toEqual(savedPartyType.type)
|
|
1977
|
+
expect(result?.partyType.origin).toEqual(savedPartyType.origin)
|
|
1978
|
+
expect(result?.partyType.tenantId).toEqual(savedPartyType.tenantId)
|
|
1979
|
+
expect(result?.partyType.name).toEqual(savedPartyType.name)
|
|
1980
|
+
})
|
|
1981
|
+
|
|
1982
|
+
it('should throw error when adding person party with wrong contact type', async (): Promise<void> => {
|
|
1983
|
+
const partyType = PartyTypeType.ORGANIZATION
|
|
1984
|
+
const partyTypeOrigin = PartyOrigin.INTERNAL
|
|
1985
|
+
const party: NonPersistedParty = {
|
|
1986
|
+
uri: 'example.com',
|
|
1987
|
+
partyType: {
|
|
1988
|
+
type: partyType,
|
|
1989
|
+
origin: partyTypeOrigin,
|
|
1990
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
1991
|
+
name: 'example_name',
|
|
1992
|
+
},
|
|
1993
|
+
contact: {
|
|
1994
|
+
firstName: 'example_first_name',
|
|
1995
|
+
middleName: 'example_middle_name',
|
|
1996
|
+
lastName: 'example_last_name',
|
|
1997
|
+
displayName: 'example_display_name',
|
|
1998
|
+
},
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
await expect(contactStore.addParty(party)).rejects.toThrow(`Party type ${partyType}, does not match for provided contact`)
|
|
2002
|
+
})
|
|
2003
|
+
|
|
2004
|
+
it('should throw error when adding organization party with wrong contact type', async (): Promise<void> => {
|
|
2005
|
+
const partyType = PartyTypeType.NATURAL_PERSON
|
|
2006
|
+
const partyTypeOrigin = PartyOrigin.EXTERNAL
|
|
2007
|
+
const party: NonPersistedParty = {
|
|
2008
|
+
uri: 'example.com',
|
|
2009
|
+
partyType: {
|
|
2010
|
+
type: partyType,
|
|
2011
|
+
origin: partyTypeOrigin,
|
|
2012
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2013
|
+
name: 'example_name',
|
|
2014
|
+
},
|
|
2015
|
+
contact: {
|
|
2016
|
+
legalName: 'example_legal_name',
|
|
2017
|
+
displayName: 'example_display_name',
|
|
2018
|
+
},
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
await expect(contactStore.addParty(party)).rejects.toThrow(`Party type ${partyType}, does not match for provided contact`)
|
|
2022
|
+
})
|
|
2023
|
+
|
|
2024
|
+
it('should get electronic address by id', async (): Promise<void> => {
|
|
2025
|
+
const party: NonPersistedParty = {
|
|
2026
|
+
uri: 'example.com',
|
|
2027
|
+
partyType: {
|
|
2028
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2029
|
+
origin: PartyOrigin.INTERNAL,
|
|
2030
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2031
|
+
name: 'example_name',
|
|
2032
|
+
},
|
|
2033
|
+
contact: {
|
|
2034
|
+
firstName: 'example_first_name',
|
|
2035
|
+
middleName: 'example_middle_name',
|
|
2036
|
+
lastName: 'example_last_name',
|
|
2037
|
+
displayName: 'example_display_name',
|
|
2038
|
+
},
|
|
2039
|
+
}
|
|
2040
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2041
|
+
expect(savedParty).toBeDefined()
|
|
2042
|
+
|
|
2043
|
+
const electronicAddress: NonPersistedElectronicAddress = {
|
|
2044
|
+
type: 'email',
|
|
2045
|
+
electronicAddress: 'example_electronic_address',
|
|
2046
|
+
}
|
|
2047
|
+
const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
|
|
2048
|
+
expect(savedElectronicAddress).toBeDefined()
|
|
2049
|
+
|
|
2050
|
+
const result: ElectronicAddress = await contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
|
|
2051
|
+
|
|
2052
|
+
expect(result).toBeDefined()
|
|
2053
|
+
})
|
|
2054
|
+
|
|
2055
|
+
it('should throw error when getting electronic address with unknown id', async (): Promise<void> => {
|
|
2056
|
+
const electronicAddressId = 'unknownElectronicAddressId'
|
|
2057
|
+
|
|
2058
|
+
await expect(contactStore.getElectronicAddress({ electronicAddressId })).rejects.toThrow(
|
|
2059
|
+
`No electronic address found for id: ${electronicAddressId}`,
|
|
2060
|
+
)
|
|
2061
|
+
})
|
|
2062
|
+
|
|
2063
|
+
it('should get all electronic addresses for contact', async (): Promise<void> => {
|
|
2064
|
+
const party: NonPersistedParty = {
|
|
2065
|
+
uri: 'example.com',
|
|
2066
|
+
partyType: {
|
|
2067
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2068
|
+
origin: PartyOrigin.EXTERNAL,
|
|
2069
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2070
|
+
name: 'example_name',
|
|
2071
|
+
},
|
|
2072
|
+
contact: {
|
|
2073
|
+
firstName: 'example_first_name',
|
|
2074
|
+
middleName: 'example_middle_name',
|
|
2075
|
+
lastName: 'example_last_name',
|
|
2076
|
+
displayName: 'example_display_name',
|
|
2077
|
+
},
|
|
2078
|
+
}
|
|
2079
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2080
|
+
expect(savedParty).toBeDefined()
|
|
2081
|
+
|
|
2082
|
+
const electronicAddress1: NonPersistedElectronicAddress = {
|
|
2083
|
+
type: 'email',
|
|
2084
|
+
electronicAddress: 'example_electronic_address1',
|
|
2085
|
+
}
|
|
2086
|
+
const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2087
|
+
partyId: savedParty.id,
|
|
2088
|
+
electronicAddress: electronicAddress1,
|
|
2089
|
+
})
|
|
2090
|
+
expect(savedElectronicAddress1).toBeDefined()
|
|
2091
|
+
|
|
2092
|
+
const electronicAddress2: NonPersistedElectronicAddress = {
|
|
2093
|
+
type: 'email',
|
|
2094
|
+
electronicAddress: 'example_electronic_address2',
|
|
2095
|
+
}
|
|
2096
|
+
const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2097
|
+
partyId: savedParty.id,
|
|
2098
|
+
electronicAddress: electronicAddress2,
|
|
2099
|
+
})
|
|
2100
|
+
expect(savedElectronicAddress2).toBeDefined()
|
|
2101
|
+
|
|
2102
|
+
const args: GetElectronicAddressesArgs = {
|
|
2103
|
+
filter: [{ partyId: savedParty.id }],
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses(args)
|
|
2107
|
+
|
|
2108
|
+
expect(result.length).toEqual(2)
|
|
2109
|
+
})
|
|
2110
|
+
|
|
2111
|
+
it('should get all electronic addresses', async (): Promise<void> => {
|
|
2112
|
+
const party: NonPersistedParty = {
|
|
2113
|
+
uri: 'example.com',
|
|
2114
|
+
partyType: {
|
|
2115
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2116
|
+
origin: PartyOrigin.INTERNAL,
|
|
2117
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2118
|
+
name: 'example_name',
|
|
2119
|
+
},
|
|
2120
|
+
contact: {
|
|
2121
|
+
firstName: 'example_first_name',
|
|
2122
|
+
middleName: 'example_middle_name',
|
|
2123
|
+
lastName: 'example_last_name',
|
|
2124
|
+
displayName: 'example_display_name',
|
|
2125
|
+
},
|
|
2126
|
+
}
|
|
2127
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2128
|
+
expect(savedParty).toBeDefined()
|
|
2129
|
+
|
|
2130
|
+
const electronicAddress1: NonPersistedElectronicAddress = {
|
|
2131
|
+
type: 'email',
|
|
2132
|
+
electronicAddress: 'example_electronic_address1',
|
|
2133
|
+
}
|
|
2134
|
+
const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2135
|
+
partyId: savedParty.id,
|
|
2136
|
+
electronicAddress: electronicAddress1,
|
|
2137
|
+
})
|
|
2138
|
+
expect(savedElectronicAddress1).toBeDefined()
|
|
2139
|
+
|
|
2140
|
+
const electronicAddress2: NonPersistedElectronicAddress = {
|
|
2141
|
+
type: 'email',
|
|
2142
|
+
electronicAddress: 'example_electronic_address2',
|
|
2143
|
+
}
|
|
2144
|
+
const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2145
|
+
partyId: savedParty.id,
|
|
2146
|
+
electronicAddress: electronicAddress2,
|
|
2147
|
+
})
|
|
2148
|
+
expect(savedElectronicAddress2).toBeDefined()
|
|
2149
|
+
|
|
2150
|
+
const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses()
|
|
2151
|
+
|
|
2152
|
+
expect(result.length).toEqual(2)
|
|
2153
|
+
})
|
|
2154
|
+
|
|
2155
|
+
it('should get electronic addresses by filter', async (): Promise<void> => {
|
|
2156
|
+
const party: NonPersistedParty = {
|
|
2157
|
+
uri: 'example.com',
|
|
2158
|
+
partyType: {
|
|
2159
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2160
|
+
origin: PartyOrigin.EXTERNAL,
|
|
2161
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2162
|
+
name: 'example_name',
|
|
2163
|
+
},
|
|
2164
|
+
contact: {
|
|
2165
|
+
firstName: 'example_first_name',
|
|
2166
|
+
middleName: 'example_middle_name',
|
|
2167
|
+
lastName: 'example_last_name',
|
|
2168
|
+
displayName: 'example_display_name',
|
|
2169
|
+
},
|
|
2170
|
+
}
|
|
2171
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2172
|
+
expect(savedParty).toBeDefined()
|
|
2173
|
+
|
|
2174
|
+
const electronicAddress = 'example_electronic_address1'
|
|
2175
|
+
const electronicAddress1: NonPersistedElectronicAddress = {
|
|
2176
|
+
type: 'email',
|
|
2177
|
+
electronicAddress,
|
|
2178
|
+
}
|
|
2179
|
+
const savedElectronicAddress1: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2180
|
+
partyId: savedParty.id,
|
|
2181
|
+
electronicAddress: electronicAddress1,
|
|
2182
|
+
})
|
|
2183
|
+
expect(savedElectronicAddress1).toBeDefined()
|
|
2184
|
+
|
|
2185
|
+
const electronicAddress2: NonPersistedElectronicAddress = {
|
|
2186
|
+
type: 'email',
|
|
2187
|
+
electronicAddress: 'example_electronic_address2',
|
|
2188
|
+
}
|
|
2189
|
+
const savedElectronicAddress2: ElectronicAddress = await contactStore.addElectronicAddress({
|
|
2190
|
+
partyId: savedParty.id,
|
|
2191
|
+
electronicAddress: electronicAddress2,
|
|
2192
|
+
})
|
|
2193
|
+
expect(savedElectronicAddress2).toBeDefined()
|
|
2194
|
+
|
|
2195
|
+
const args: GetElectronicAddressesArgs = {
|
|
2196
|
+
filter: [{ electronicAddress }],
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
const result: Array<ElectronicAddress> = await contactStore.getElectronicAddresses(args)
|
|
2200
|
+
|
|
2201
|
+
expect(result.length).toEqual(1)
|
|
2202
|
+
})
|
|
2203
|
+
|
|
2204
|
+
it('should add electronic address to contact', async (): Promise<void> => {
|
|
2205
|
+
const party: NonPersistedParty = {
|
|
2206
|
+
uri: 'example.com',
|
|
2207
|
+
partyType: {
|
|
2208
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2209
|
+
origin: PartyOrigin.INTERNAL,
|
|
2210
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2211
|
+
name: 'example_name',
|
|
2212
|
+
},
|
|
2213
|
+
contact: {
|
|
2214
|
+
firstName: 'example_first_name',
|
|
2215
|
+
middleName: 'example_middle_name',
|
|
2216
|
+
lastName: 'example_last_name',
|
|
2217
|
+
displayName: 'example_display_name',
|
|
2218
|
+
},
|
|
2219
|
+
}
|
|
2220
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2221
|
+
expect(savedParty).toBeDefined()
|
|
2222
|
+
|
|
2223
|
+
const electronicAddress: NonPersistedElectronicAddress = {
|
|
2224
|
+
type: 'email',
|
|
2225
|
+
electronicAddress: 'example_electronic_address',
|
|
2226
|
+
}
|
|
2227
|
+
const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
|
|
2228
|
+
expect(savedElectronicAddress).toBeDefined()
|
|
2229
|
+
|
|
2230
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
2231
|
+
expect(result.electronicAddresses.length).toEqual(1)
|
|
2232
|
+
})
|
|
2233
|
+
|
|
2234
|
+
it('should update electronic address by id', async (): Promise<void> => {
|
|
2235
|
+
const party: NonPersistedParty = {
|
|
2236
|
+
uri: 'example.com',
|
|
2237
|
+
partyType: {
|
|
2238
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2239
|
+
origin: PartyOrigin.EXTERNAL,
|
|
2240
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2241
|
+
name: 'example_name',
|
|
2242
|
+
},
|
|
2243
|
+
contact: {
|
|
2244
|
+
firstName: 'example_first_name',
|
|
2245
|
+
middleName: 'example_middle_name',
|
|
2246
|
+
lastName: 'example_last_name',
|
|
2247
|
+
displayName: 'example_display_name',
|
|
2248
|
+
},
|
|
2249
|
+
}
|
|
2250
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2251
|
+
expect(savedParty).toBeDefined()
|
|
2252
|
+
|
|
2253
|
+
const electronicAddress: NonPersistedElectronicAddress = {
|
|
2254
|
+
type: 'email',
|
|
2255
|
+
electronicAddress: 'example_electronic_address',
|
|
2256
|
+
}
|
|
2257
|
+
const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
|
|
2258
|
+
const newElectronicAddress = 'new_example_electronic_address'
|
|
2259
|
+
savedElectronicAddress.electronicAddress = newElectronicAddress
|
|
2260
|
+
|
|
2261
|
+
await contactStore.updateElectronicAddress({ electronicAddress: savedElectronicAddress })
|
|
2262
|
+
const result: ElectronicAddress = await contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
|
|
2263
|
+
|
|
2264
|
+
expect(result).toBeDefined()
|
|
2265
|
+
expect(result.electronicAddress).toEqual(newElectronicAddress)
|
|
2266
|
+
})
|
|
2267
|
+
|
|
2268
|
+
it('should remove electronic address', async (): Promise<void> => {
|
|
2269
|
+
const party: NonPersistedParty = {
|
|
2270
|
+
uri: 'example.com',
|
|
2271
|
+
partyType: {
|
|
2272
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2273
|
+
origin: PartyOrigin.INTERNAL,
|
|
2274
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2275
|
+
name: 'example_name',
|
|
2276
|
+
},
|
|
2277
|
+
contact: {
|
|
2278
|
+
firstName: 'example_first_name',
|
|
2279
|
+
middleName: 'example_middle_name',
|
|
2280
|
+
lastName: 'example_last_name',
|
|
2281
|
+
displayName: 'example_display_name',
|
|
2282
|
+
},
|
|
2283
|
+
}
|
|
2284
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2285
|
+
expect(savedParty).toBeDefined()
|
|
2286
|
+
|
|
2287
|
+
const electronicAddress: NonPersistedElectronicAddress = {
|
|
2288
|
+
type: 'email',
|
|
2289
|
+
electronicAddress: 'example_electronic_address',
|
|
2290
|
+
}
|
|
2291
|
+
const savedElectronicAddress: ElectronicAddress = await contactStore.addElectronicAddress({ partyId: savedParty.id, electronicAddress })
|
|
2292
|
+
expect(savedElectronicAddress).toBeDefined()
|
|
2293
|
+
|
|
2294
|
+
await contactStore.removeElectronicAddress({ electronicAddressId: savedElectronicAddress.id })
|
|
2295
|
+
|
|
2296
|
+
await expect(contactStore.getElectronicAddress({ electronicAddressId: savedElectronicAddress.id })).rejects.toThrow(
|
|
2297
|
+
`No electronic address found for id: ${savedElectronicAddress.id}`,
|
|
2298
|
+
)
|
|
2299
|
+
})
|
|
2300
|
+
|
|
2301
|
+
it('should throw error when removing electronic address with unknown id', async (): Promise<void> => {
|
|
2302
|
+
const electronicAddressId = 'unknownElectronicAddressId'
|
|
2303
|
+
|
|
2304
|
+
await expect(contactStore.removeElectronicAddress({ electronicAddressId })).rejects.toThrow(
|
|
2305
|
+
`No electronic address found for id: ${electronicAddressId}`,
|
|
2306
|
+
)
|
|
2307
|
+
})
|
|
2308
|
+
|
|
2309
|
+
it('should get physical address by id', async (): Promise<void> => {
|
|
2310
|
+
const party: NonPersistedParty = {
|
|
2311
|
+
uri: 'example.com',
|
|
2312
|
+
partyType: {
|
|
2313
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2314
|
+
origin: PartyOrigin.EXTERNAL,
|
|
2315
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2316
|
+
name: 'example_name',
|
|
2317
|
+
},
|
|
2318
|
+
contact: {
|
|
2319
|
+
firstName: 'example_first_name',
|
|
2320
|
+
middleName: 'example_middle_name',
|
|
2321
|
+
lastName: 'example_last_name',
|
|
2322
|
+
displayName: 'example_display_name',
|
|
2323
|
+
},
|
|
2324
|
+
}
|
|
2325
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2326
|
+
expect(savedParty).toBeDefined()
|
|
2327
|
+
|
|
2328
|
+
const physicalAddress: NonPersistedPhysicalAddress = {
|
|
2329
|
+
type: 'home',
|
|
2330
|
+
streetName: 'example_street_name',
|
|
2331
|
+
streetNumber: 'example_street_number',
|
|
2332
|
+
buildingName: 'example_building_name',
|
|
2333
|
+
postalCode: 'example_postal_code',
|
|
2334
|
+
cityName: 'example_city_name',
|
|
2335
|
+
provinceName: 'example_province_name',
|
|
2336
|
+
countryCode: 'example_country_code',
|
|
2337
|
+
}
|
|
2338
|
+
const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
|
|
2339
|
+
expect(savedPhysicalAddress).toBeDefined()
|
|
2340
|
+
|
|
2341
|
+
const result: PhysicalAddress = await contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
|
|
2342
|
+
|
|
2343
|
+
expect(result).toBeDefined()
|
|
2344
|
+
})
|
|
2345
|
+
|
|
2346
|
+
it('should throw error when getting physical address with unknown id', async (): Promise<void> => {
|
|
2347
|
+
const physicalAddressId = 'unknownPhysicalAddressId'
|
|
2348
|
+
|
|
2349
|
+
await expect(contactStore.getPhysicalAddress({ physicalAddressId })).rejects.toThrow(`No physical address found for id: ${physicalAddressId}`)
|
|
2350
|
+
})
|
|
2351
|
+
|
|
2352
|
+
it('should get all physical addresses for contact', async (): Promise<void> => {
|
|
2353
|
+
const party: NonPersistedParty = {
|
|
2354
|
+
uri: 'example.com',
|
|
2355
|
+
partyType: {
|
|
2356
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2357
|
+
origin: PartyOrigin.INTERNAL,
|
|
2358
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2359
|
+
name: 'example_name',
|
|
2360
|
+
},
|
|
2361
|
+
contact: {
|
|
2362
|
+
firstName: 'example_first_name',
|
|
2363
|
+
middleName: 'example_middle_name',
|
|
2364
|
+
lastName: 'example_last_name',
|
|
2365
|
+
displayName: 'example_display_name',
|
|
2366
|
+
},
|
|
2367
|
+
}
|
|
2368
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2369
|
+
expect(savedParty).toBeDefined()
|
|
2370
|
+
|
|
2371
|
+
const physicalAddress1: NonPersistedPhysicalAddress = {
|
|
2372
|
+
type: 'home',
|
|
2373
|
+
streetName: 'example_street_name',
|
|
2374
|
+
streetNumber: 'example_street_number',
|
|
2375
|
+
buildingName: 'example_building_name',
|
|
2376
|
+
postalCode: 'example_postal_code',
|
|
2377
|
+
cityName: 'example_city_name',
|
|
2378
|
+
provinceName: 'example_province_name',
|
|
2379
|
+
countryCode: 'example_country_code',
|
|
2380
|
+
}
|
|
2381
|
+
const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2382
|
+
partyId: savedParty.id,
|
|
2383
|
+
physicalAddress: physicalAddress1,
|
|
2384
|
+
})
|
|
2385
|
+
expect(savedPhysicalAddress1).toBeDefined()
|
|
2386
|
+
|
|
2387
|
+
const physicalAddress2: NonPersistedPhysicalAddress = {
|
|
2388
|
+
type: 'home',
|
|
2389
|
+
streetName: 'example_street_name',
|
|
2390
|
+
streetNumber: 'example_street_number',
|
|
2391
|
+
buildingName: 'example_building_name',
|
|
2392
|
+
postalCode: 'example_postal_code',
|
|
2393
|
+
cityName: 'example_city_name',
|
|
2394
|
+
provinceName: 'example_province_name',
|
|
2395
|
+
countryCode: 'example_country_code',
|
|
2396
|
+
}
|
|
2397
|
+
const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2398
|
+
partyId: savedParty.id,
|
|
2399
|
+
physicalAddress: physicalAddress2,
|
|
2400
|
+
})
|
|
2401
|
+
expect(savedPhysicalAddress2).toBeDefined()
|
|
2402
|
+
|
|
2403
|
+
const args: GetPhysicalAddressesArgs = {
|
|
2404
|
+
filter: [{ partyId: savedParty.id }],
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses(args)
|
|
2408
|
+
|
|
2409
|
+
expect(result.length).toEqual(2)
|
|
2410
|
+
})
|
|
2411
|
+
|
|
2412
|
+
it('should get all electronic addresses', async (): Promise<void> => {
|
|
2413
|
+
const party: NonPersistedParty = {
|
|
2414
|
+
uri: 'example.com',
|
|
2415
|
+
partyType: {
|
|
2416
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2417
|
+
origin: PartyOrigin.EXTERNAL,
|
|
2418
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2419
|
+
name: 'example_name',
|
|
2420
|
+
},
|
|
2421
|
+
contact: {
|
|
2422
|
+
firstName: 'example_first_name',
|
|
2423
|
+
middleName: 'example_middle_name',
|
|
2424
|
+
lastName: 'example_last_name',
|
|
2425
|
+
displayName: 'example_display_name',
|
|
2426
|
+
},
|
|
2427
|
+
}
|
|
2428
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2429
|
+
expect(savedParty).toBeDefined()
|
|
2430
|
+
|
|
2431
|
+
const physicalAddress1: NonPersistedPhysicalAddress = {
|
|
2432
|
+
type: 'home',
|
|
2433
|
+
streetName: 'example_street_name',
|
|
2434
|
+
streetNumber: 'example_street_number',
|
|
2435
|
+
buildingName: 'example_building_name',
|
|
2436
|
+
postalCode: 'example_postal_code',
|
|
2437
|
+
cityName: 'example_city_name',
|
|
2438
|
+
provinceName: 'example_province_name',
|
|
2439
|
+
countryCode: 'example_country_code',
|
|
2440
|
+
}
|
|
2441
|
+
const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2442
|
+
partyId: savedParty.id,
|
|
2443
|
+
physicalAddress: physicalAddress1,
|
|
2444
|
+
})
|
|
2445
|
+
expect(savedPhysicalAddress1).toBeDefined()
|
|
2446
|
+
|
|
2447
|
+
const physicalAddress2: NonPersistedPhysicalAddress = {
|
|
2448
|
+
type: 'home',
|
|
2449
|
+
streetName: 'example_street_name',
|
|
2450
|
+
streetNumber: 'example_street_number',
|
|
2451
|
+
buildingName: 'example_building_name',
|
|
2452
|
+
postalCode: 'example_postal_code',
|
|
2453
|
+
cityName: 'example_city_name',
|
|
2454
|
+
provinceName: 'example_province_name',
|
|
2455
|
+
countryCode: 'example_country_code',
|
|
2456
|
+
}
|
|
2457
|
+
const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2458
|
+
partyId: savedParty.id,
|
|
2459
|
+
physicalAddress: physicalAddress2,
|
|
2460
|
+
})
|
|
2461
|
+
expect(savedPhysicalAddress2).toBeDefined()
|
|
2462
|
+
|
|
2463
|
+
const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses()
|
|
2464
|
+
|
|
2465
|
+
expect(result.length).toEqual(2)
|
|
2466
|
+
})
|
|
2467
|
+
|
|
2468
|
+
it('should get electronic addresses by filter', async (): Promise<void> => {
|
|
2469
|
+
const party: NonPersistedParty = {
|
|
2470
|
+
uri: 'example.com',
|
|
2471
|
+
partyType: {
|
|
2472
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2473
|
+
origin: PartyOrigin.INTERNAL,
|
|
2474
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2475
|
+
name: 'example_name',
|
|
2476
|
+
},
|
|
2477
|
+
contact: {
|
|
2478
|
+
firstName: 'example_first_name',
|
|
2479
|
+
middleName: 'example_middle_name',
|
|
2480
|
+
lastName: 'example_last_name',
|
|
2481
|
+
displayName: 'example_display_name',
|
|
2482
|
+
},
|
|
2483
|
+
}
|
|
2484
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2485
|
+
expect(savedParty).toBeDefined()
|
|
2486
|
+
|
|
2487
|
+
const streetName = 'example_electronic_address1'
|
|
2488
|
+
const physicalAddress1: NonPersistedPhysicalAddress = {
|
|
2489
|
+
type: 'home',
|
|
2490
|
+
streetName,
|
|
2491
|
+
streetNumber: 'example_street_number1',
|
|
2492
|
+
buildingName: 'example_building_name1',
|
|
2493
|
+
postalCode: 'example_postal_code1',
|
|
2494
|
+
cityName: 'example_city_name1',
|
|
2495
|
+
provinceName: 'example_province_name1',
|
|
2496
|
+
countryCode: 'example_country_code1',
|
|
2497
|
+
}
|
|
2498
|
+
const savedPhysicalAddress1: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2499
|
+
partyId: savedParty.id,
|
|
2500
|
+
physicalAddress: physicalAddress1,
|
|
2501
|
+
})
|
|
2502
|
+
expect(savedPhysicalAddress1).toBeDefined()
|
|
2503
|
+
|
|
2504
|
+
const physicalAddress2: NonPersistedPhysicalAddress = {
|
|
2505
|
+
type: 'home',
|
|
2506
|
+
streetName: 'example_street_name2',
|
|
2507
|
+
streetNumber: 'example_street_number2',
|
|
2508
|
+
buildingName: 'example_building_name2',
|
|
2509
|
+
postalCode: 'example_postal_code2',
|
|
2510
|
+
cityName: 'example_city_name2',
|
|
2511
|
+
provinceName: 'example_province_name2',
|
|
2512
|
+
countryCode: 'example_country_code2',
|
|
2513
|
+
}
|
|
2514
|
+
const savedPhysicalAddress2: PhysicalAddress = await contactStore.addPhysicalAddress({
|
|
2515
|
+
partyId: savedParty.id,
|
|
2516
|
+
physicalAddress: physicalAddress2,
|
|
2517
|
+
})
|
|
2518
|
+
expect(savedPhysicalAddress2).toBeDefined()
|
|
2519
|
+
|
|
2520
|
+
const args: GetPhysicalAddressesArgs = {
|
|
2521
|
+
filter: [{ streetName }],
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
const result: Array<PhysicalAddress> = await contactStore.getPhysicalAddresses(args)
|
|
2525
|
+
|
|
2526
|
+
expect(result.length).toEqual(1)
|
|
2527
|
+
})
|
|
2528
|
+
|
|
2529
|
+
it('should add physical address to contact', async (): Promise<void> => {
|
|
2530
|
+
const party: NonPersistedParty = {
|
|
2531
|
+
uri: 'example.com',
|
|
2532
|
+
partyType: {
|
|
2533
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2534
|
+
origin: PartyOrigin.EXTERNAL,
|
|
2535
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2536
|
+
name: 'example_name',
|
|
2537
|
+
},
|
|
2538
|
+
contact: {
|
|
2539
|
+
firstName: 'example_first_name',
|
|
2540
|
+
middleName: 'example_middle_name',
|
|
2541
|
+
lastName: 'example_last_name',
|
|
2542
|
+
displayName: 'example_display_name',
|
|
2543
|
+
},
|
|
2544
|
+
}
|
|
2545
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2546
|
+
expect(savedParty).toBeDefined()
|
|
2547
|
+
|
|
2548
|
+
const physicalAddress: NonPersistedPhysicalAddress = {
|
|
2549
|
+
type: 'home',
|
|
2550
|
+
streetName: 'example_street_name',
|
|
2551
|
+
streetNumber: 'example_street_number',
|
|
2552
|
+
buildingName: 'example_building_name',
|
|
2553
|
+
postalCode: 'example_postal_code',
|
|
2554
|
+
cityName: 'example_city_name',
|
|
2555
|
+
provinceName: 'example_province_name',
|
|
2556
|
+
countryCode: 'example_country_code',
|
|
2557
|
+
}
|
|
2558
|
+
const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
|
|
2559
|
+
expect(savedPhysicalAddress).toBeDefined()
|
|
2560
|
+
|
|
2561
|
+
const result: Party = await contactStore.getParty({ partyId: savedParty.id })
|
|
2562
|
+
expect(result.physicalAddresses.length).toEqual(1)
|
|
2563
|
+
})
|
|
2564
|
+
|
|
2565
|
+
it('should update physical address by id', async (): Promise<void> => {
|
|
2566
|
+
const party: NonPersistedParty = {
|
|
2567
|
+
uri: 'example.com',
|
|
2568
|
+
partyType: {
|
|
2569
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2570
|
+
origin: PartyOrigin.INTERNAL,
|
|
2571
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2572
|
+
name: 'example_name',
|
|
2573
|
+
},
|
|
2574
|
+
contact: {
|
|
2575
|
+
firstName: 'example_first_name',
|
|
2576
|
+
middleName: 'example_middle_name',
|
|
2577
|
+
lastName: 'example_last_name',
|
|
2578
|
+
displayName: 'example_display_name',
|
|
2579
|
+
},
|
|
2580
|
+
}
|
|
2581
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2582
|
+
expect(savedParty).toBeDefined()
|
|
2583
|
+
|
|
2584
|
+
const physicalAddress: NonPersistedPhysicalAddress = {
|
|
2585
|
+
type: 'home',
|
|
2586
|
+
streetName: 'example_street_name',
|
|
2587
|
+
streetNumber: 'example_street_number',
|
|
2588
|
+
buildingName: 'example_building_name',
|
|
2589
|
+
postalCode: 'example_postal_code',
|
|
2590
|
+
cityName: 'example_city_name',
|
|
2591
|
+
provinceName: 'example_province_name',
|
|
2592
|
+
countryCode: 'example_country_code',
|
|
2593
|
+
}
|
|
2594
|
+
const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
|
|
2595
|
+
const newStreetName = 'new_example_street_name'
|
|
2596
|
+
savedPhysicalAddress.streetName = newStreetName
|
|
2597
|
+
|
|
2598
|
+
await contactStore.updatePhysicalAddress({ physicalAddress: savedPhysicalAddress })
|
|
2599
|
+
const result: PhysicalAddress = await contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
|
|
2600
|
+
|
|
2601
|
+
expect(result).toBeDefined()
|
|
2602
|
+
expect(result.streetName).toEqual(newStreetName)
|
|
2603
|
+
})
|
|
2604
|
+
|
|
2605
|
+
it('should remove physical address', async (): Promise<void> => {
|
|
2606
|
+
const party: NonPersistedParty = {
|
|
2607
|
+
uri: 'example.com',
|
|
2608
|
+
partyType: {
|
|
2609
|
+
type: PartyTypeType.NATURAL_PERSON,
|
|
2610
|
+
origin: PartyOrigin.EXTERNAL,
|
|
2611
|
+
tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289',
|
|
2612
|
+
name: 'example_name',
|
|
2613
|
+
},
|
|
2614
|
+
contact: {
|
|
2615
|
+
firstName: 'example_first_name',
|
|
2616
|
+
middleName: 'example_middle_name',
|
|
2617
|
+
lastName: 'example_last_name',
|
|
2618
|
+
displayName: 'example_display_name',
|
|
2619
|
+
},
|
|
2620
|
+
}
|
|
2621
|
+
const savedParty: Party = await contactStore.addParty(party)
|
|
2622
|
+
expect(savedParty).toBeDefined()
|
|
2623
|
+
|
|
2624
|
+
const physicalAddress: NonPersistedPhysicalAddress = {
|
|
2625
|
+
type: 'home',
|
|
2626
|
+
streetName: 'example_street_name',
|
|
2627
|
+
streetNumber: 'example_street_number',
|
|
2628
|
+
buildingName: 'example_building_name',
|
|
2629
|
+
postalCode: 'example_postal_code',
|
|
2630
|
+
cityName: 'example_city_name',
|
|
2631
|
+
provinceName: 'example_province_name',
|
|
2632
|
+
countryCode: 'example_country_code',
|
|
2633
|
+
}
|
|
2634
|
+
const savedPhysicalAddress: PhysicalAddress = await contactStore.addPhysicalAddress({ partyId: savedParty.id, physicalAddress })
|
|
2635
|
+
expect(savedPhysicalAddress).toBeDefined()
|
|
2636
|
+
|
|
2637
|
+
await contactStore.removePhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })
|
|
2638
|
+
|
|
2639
|
+
await expect(contactStore.getPhysicalAddress({ physicalAddressId: savedPhysicalAddress.id })).rejects.toThrow(
|
|
2640
|
+
`No physical address found for id: ${savedPhysicalAddress.id}`,
|
|
2641
|
+
)
|
|
2642
|
+
})
|
|
2643
|
+
|
|
2644
|
+
it('should throw error when removing physical address with unknown id', async (): Promise<void> => {
|
|
2645
|
+
const physicalAddressId = 'unknownPhysicalAddressId'
|
|
2646
|
+
|
|
2647
|
+
await expect(contactStore.removePhysicalAddress({ physicalAddressId })).rejects.toThrow(`No physical address found for id: ${physicalAddressId}`)
|
|
2648
|
+
})
|
|
2649
|
+
})
|