From 07d8c1f7cdec110ced10277abd4d70edeb15c2d3 Mon Sep 17 00:00:00 2001 From: Maikel Maas Date: Wed, 20 Mar 2024 17:23:39 +0100 Subject: [PATCH] feat: Added PartyOriginEnum to PartyType, wrote migrations and updated tests and updated the contact manager plugin --- .../shared/contactManagerAgentLogic.ts | 20 ++++- .../src/types/IContactManager.ts | 2 + .../src/__tests__/contact.entities.test.ts | 82 +++++++++++++++---- .../src/__tests__/contact.store.test.ts | 79 +++++++++++++++++- .../src/entities/contact/PartyTypeEntity.ts | 5 +- .../migrations/generic/9-CreateContacts.ts | 66 +++++++++++++++ .../src/migrations/generic/index.ts | 3 +- .../postgres/1710941091795-CreateContacts.ts | 15 ++++ .../sqlite/1710941197348-CreateContacts.ts | 14 ++++ .../types/contact/IAbstractContactStore.ts | 2 + .../data-store/src/types/contact/contact.ts | 6 ++ .../src/utils/contact/MappingUtils.ts | 2 + 12 files changed, 273 insertions(+), 23 deletions(-) create mode 100644 packages/data-store/src/migrations/generic/9-CreateContacts.ts create mode 100644 packages/data-store/src/migrations/postgres/1710941091795-CreateContacts.ts create mode 100644 packages/data-store/src/migrations/sqlite/1710941197348-CreateContacts.ts diff --git a/packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts b/packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts index cf194ab93..a38c16fec 100644 --- a/packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts +++ b/packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts @@ -1,4 +1,4 @@ -import { TAgent } from '@veramo/core' +import {TAgent} from '@veramo/core' import { CorrelationIdentifierEnum, ElectronicAddress, @@ -10,11 +10,12 @@ import { NonPersistedIdentity, NonPersistedPhysicalAddress, Party, + PartyOriginEnum, PartyRelationship, PartyTypeEnum, PhysicalAddress, } from '../../../data-store/src' -import { AddContactArgs, IContactManager } from '../../src' +import {AddContactArgs, IContactManager} from '../../src' type ConfiguredAgent = TAgent @@ -35,6 +36,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'default_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -142,6 +144,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'new_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'new_name', description: 'new_description', @@ -170,6 +173,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro const result: Party = await agent.cmAddContact(contact) expect(result.partyType.type).toEqual(contact.contactType.type) + expect(result.partyType.origin).toEqual(contact.contactType.origin) expect(result.partyType.name).toEqual(contact.contactType.name) expect(result.partyType.description).toEqual(contact.contactType.description) expect((result.contact).firstName).toEqual(contact.firstName) @@ -317,6 +321,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'relation_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d285', name: 'relation_contact_type_name', description: 'new_description', @@ -361,6 +366,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'remove_relation_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d286', name: 'remove_relation_contact_type_name', description: 'new_description', @@ -410,6 +416,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'add_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: 'a85a8aa0-fdeb-4c00-b22e-60423f52a873', name: 'add_electronic_address_name', description: 'add_electronic_address_description', @@ -438,6 +445,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'get_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: 'f2947075-53eb-4176-b155-ab4b18715288', name: 'get_electronic_address_name', description: 'get_electronic_address_description', @@ -465,6 +473,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'get_all_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '5c0157ec-4678-4273-8f53-413bc6435134', name: 'get_all_electronic_address_name', description: 'get_all_electronic_address_description', @@ -493,6 +502,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'update_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '6b64c3dd-cf40-4919-b8b8-2ec3c510c5b7', name: 'update_electronic_address_name', description: 'update_electronic_address_description', @@ -528,6 +538,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'remove_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '41b45c65-971e-4c26-8115-cb8bc7c67cf3', name: 'remove_electronic_address_name', description: 'remove_electronic_address_description', @@ -561,6 +572,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'add_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '5aeb828e-16d6-4244-95a7-e12424474eb7', name: 'add_physical_address_name', description: 'add_physical_address_description', @@ -595,6 +607,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'get_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '7c5dbbd9-1721-4246-b261-44e237560a15', name: 'get_physical_address_name', description: 'get_physical_address_description', @@ -628,6 +641,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'get_all_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0c0eafd8-1e8c-44bf-8e0d-768fb11a40c3', name: 'get_all_physical_address_name', description: 'get_all_physical_address_description', @@ -662,6 +676,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'update_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: 'f2b4eb1c-e36f-4863-90b3-90720471c397', name: 'update_physical_address_name', description: 'update_physical_address_description', @@ -715,6 +730,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'remove_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '20b11d1e-6489-4258-af33-32a2cfa4dc85', name: 'remove_physical_address_name', description: 'remove_physical_address_description', diff --git a/packages/contact-manager/src/types/IContactManager.ts b/packages/contact-manager/src/types/IContactManager.ts index c88de78e7..37416e8c3 100644 --- a/packages/contact-manager/src/types/IContactManager.ts +++ b/packages/contact-manager/src/types/IContactManager.ts @@ -15,6 +15,7 @@ import { NonPersistedPartyType as NonPersistedContactType, NonPersistedPhysicalAddress, Party as Contact, + PartyOriginEnum, PartyRelationship as ContactRelationship, PartyType as ContactType, PartyTypeEnum as ContactTypeEnum, @@ -119,6 +120,7 @@ export type UpdateRelationshipArgs = { export type AddContactTypeArgs = { type: ContactTypeEnum + origin: PartyOriginEnum name: string tenantId: string description?: string diff --git a/packages/data-store/src/__tests__/contact.entities.test.ts b/packages/data-store/src/__tests__/contact.entities.test.ts index 582823f39..7d210ff2b 100644 --- a/packages/data-store/src/__tests__/contact.entities.test.ts +++ b/packages/data-store/src/__tests__/contact.entities.test.ts @@ -1,19 +1,19 @@ -import { DataSource, FindOptionsWhere } from 'typeorm' -import { DataStoreContactEntities, DataStoreMigrations } from '../index' -import { BaseContactEntity } from '../entities/contact/BaseContactEntity' -import { ConnectionEntity } from '../entities/contact/ConnectionEntity' -import { CorrelationIdentifierEntity } from '../entities/contact/CorrelationIdentifierEntity' -import { DidAuthConfigEntity } from '../entities/contact/DidAuthConfigEntity' -import { ElectronicAddressEntity } from '../entities/contact/ElectronicAddressEntity' -import { IdentityEntity } from '../entities/contact/IdentityEntity' -import { IdentityMetadataItemEntity } from '../entities/contact/IdentityMetadataItemEntity' -import { NaturalPersonEntity } from '../entities/contact/NaturalPersonEntity' -import { OpenIdConfigEntity } from '../entities/contact/OpenIdConfigEntity' -import { OrganizationEntity } from '../entities/contact/OrganizationEntity' -import { PartyEntity } from '../entities/contact/PartyEntity' -import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity' -import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity' -import { PhysicalAddressEntity } from '../entities/contact/PhysicalAddressEntity' +import {DataSource, FindOptionsWhere} from 'typeorm' +import {DataStoreContactEntities, DataStoreMigrations, PartyOriginEnum} from '../index' +import {BaseContactEntity} from '../entities/contact/BaseContactEntity' +import {ConnectionEntity} from '../entities/contact/ConnectionEntity' +import {CorrelationIdentifierEntity} from '../entities/contact/CorrelationIdentifierEntity' +import {DidAuthConfigEntity} from '../entities/contact/DidAuthConfigEntity' +import {ElectronicAddressEntity} from '../entities/contact/ElectronicAddressEntity' +import {IdentityEntity} from '../entities/contact/IdentityEntity' +import {IdentityMetadataItemEntity} from '../entities/contact/IdentityMetadataItemEntity' +import {NaturalPersonEntity} from '../entities/contact/NaturalPersonEntity' +import {OpenIdConfigEntity} from '../entities/contact/OpenIdConfigEntity' +import {OrganizationEntity} from '../entities/contact/OrganizationEntity' +import {PartyEntity} from '../entities/contact/PartyEntity' +import {PartyRelationshipEntity} from '../entities/contact/PartyRelationshipEntity' +import {PartyTypeEntity} from '../entities/contact/PartyTypeEntity' +import {PhysicalAddressEntity} from '../entities/contact/PhysicalAddressEntity' import { ConnectionTypeEnum, CorrelationIdentifierEnum, @@ -74,6 +74,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -99,6 +100,7 @@ describe('Database entities tests', (): void => { expect(fromDb?.uri).toEqual(party.uri) expect(fromDb?.partyType).toBeDefined() expect(fromDb?.partyType.type).toEqual(party.partyType.type) + expect(fromDb?.partyType.origin).toEqual(party.partyType.origin) expect(fromDb?.partyType.tenantId).toEqual(party.partyType.tenantId) expect(fromDb?.partyType.name).toEqual(party.partyType.name) expect(fromDb?.contact).toBeDefined() @@ -113,6 +115,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.ORGANIZATION, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -136,6 +139,7 @@ describe('Database entities tests', (): void => { expect(fromDb?.uri).toEqual(party.uri) expect(fromDb?.partyType).toBeDefined() expect(fromDb?.partyType.type).toEqual(party.partyType.type) + expect(fromDb?.partyType.origin).toEqual(party.partyType.origin) expect(fromDb?.partyType.tenantId).toEqual(party.partyType.tenantId) expect(fromDb?.partyType.name).toEqual(party.partyType.name) expect(fromDb?.contact).toBeDefined() @@ -148,6 +152,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -168,6 +173,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -212,6 +218,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -233,6 +240,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -254,6 +262,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -275,6 +284,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -296,6 +306,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.ORGANIZATION, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -315,6 +326,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.ORGANIZATION, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -334,6 +346,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: '', }, @@ -355,6 +368,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', description: '', @@ -377,6 +391,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '', name: 'example_name', }, @@ -772,6 +787,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -792,6 +808,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -951,6 +968,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1051,6 +1069,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1126,6 +1145,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1153,6 +1173,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1248,6 +1269,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1275,6 +1297,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1317,6 +1340,7 @@ describe('Database entities tests', (): void => { it('Should set last updated date when saving party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -1335,6 +1359,7 @@ describe('Database entities tests', (): void => { it('Should set last creation date when saving party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -1381,6 +1406,7 @@ describe('Database entities tests', (): void => { const name = 'non_unique_value' const partyType1: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId, name, } @@ -1392,6 +1418,7 @@ describe('Database entities tests', (): void => { const partyType2: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId, name, } @@ -1406,6 +1433,7 @@ describe('Database entities tests', (): void => { const name = 'non_unique_value' const partyType1: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin:PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name, } @@ -1417,6 +1445,7 @@ describe('Database entities tests', (): void => { const partyType2: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name, } @@ -1482,6 +1511,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1504,6 +1534,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1544,6 +1575,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1564,6 +1596,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1602,6 +1635,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1622,6 +1656,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1660,6 +1695,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1682,6 +1718,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1734,6 +1771,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1756,6 +1794,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1798,6 +1837,7 @@ describe('Database entities tests', (): void => { it('Should save party type to database', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -1933,6 +1973,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1966,6 +2007,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.ORGANIZATION, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1996,6 +2038,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2029,6 +2072,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -2051,6 +2095,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -2092,6 +2137,7 @@ describe('Database entities tests', (): void => { it('Should delete party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -2115,6 +2161,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2141,6 +2188,7 @@ describe('Database entities tests', (): void => { it('Should save party with existing party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -2173,6 +2221,7 @@ describe('Database entities tests', (): void => { expect(fromDb?.partyType).toBeDefined() expect(fromDb?.partyType.id).toEqual(savedPartyType.id) expect(fromDb?.partyType.type).toEqual(savedPartyType.type) + expect(fromDb?.partyType.origin).toEqual(savedPartyType.origin) expect(fromDb?.partyType.tenantId).toEqual(savedPartyType.tenantId) expect(fromDb?.partyType.name).toEqual(savedPartyType.name) }) @@ -2180,6 +2229,7 @@ describe('Database entities tests', (): void => { it('Should not update creation date when saving party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } diff --git a/packages/data-store/src/__tests__/contact.store.test.ts b/packages/data-store/src/__tests__/contact.store.test.ts index d7ba709ab..e0116d49e 100644 --- a/packages/data-store/src/__tests__/contact.store.test.ts +++ b/packages/data-store/src/__tests__/contact.store.test.ts @@ -1,6 +1,6 @@ -import { DataSource } from 'typeorm' -import { DataStoreMigrations, DataStoreContactEntities } from '../index' -import { ContactStore } from '../contact/ContactStore' +import {DataSource} from 'typeorm' +import {DataStoreContactEntities, DataStoreMigrations, PartyOriginEnum} from '../index' +import {ContactStore} from '../contact/ContactStore' import { CorrelationIdentifierEnum, ElectronicAddress, @@ -54,6 +54,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -84,6 +85,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -101,6 +103,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -125,6 +128,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -172,6 +176,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -239,6 +244,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'something', }, @@ -282,6 +288,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -315,6 +322,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -366,6 +374,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -391,6 +400,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -434,6 +444,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'something', }, @@ -471,6 +482,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -528,6 +540,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -560,6 +573,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -594,6 +608,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -634,6 +649,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -683,6 +699,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -728,6 +745,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -778,6 +796,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -828,6 +847,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -867,6 +887,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -900,6 +921,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -935,6 +957,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -972,6 +995,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1022,6 +1046,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1039,6 +1064,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1071,6 +1097,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1088,6 +1115,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1125,6 +1153,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1142,6 +1171,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1178,6 +1208,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1195,6 +1226,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1240,6 +1272,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1257,6 +1290,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1309,6 +1343,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1326,6 +1361,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1343,6 +1379,7 @@ describe('Contact store tests', (): void => { uri: 'example3.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287', name: 'example_name3', }, @@ -1382,6 +1419,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1399,6 +1437,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1435,6 +1474,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1452,6 +1492,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1487,6 +1528,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1504,6 +1546,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1537,6 +1580,7 @@ describe('Contact store tests', (): void => { it('should add party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name', description: 'example_description', @@ -1548,6 +1592,7 @@ describe('Contact store tests', (): void => { expect(result).toBeDefined() expect(result.name).toEqual(partyType.name) expect(result.type).toEqual(partyType.type) + expect(result.origin).toEqual(partyType.origin) expect(result.tenantId).toEqual(partyType.tenantId) expect(result.description).toEqual(partyType.description) expect(result.lastUpdatedAt).toBeDefined() @@ -1557,6 +1602,7 @@ describe('Contact store tests', (): void => { it('should get party types by filter', async (): Promise => { const partyType1: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name1', description: 'example_description1', @@ -1566,6 +1612,7 @@ describe('Contact store tests', (): void => { const partyType2: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287', name: 'example_name2', description: 'example_description2', @@ -1590,6 +1637,7 @@ describe('Contact store tests', (): void => { it('should return no party types if filter does not match', async (): Promise => { const partyType1: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name1', description: 'example_description1', @@ -1599,6 +1647,7 @@ describe('Contact store tests', (): void => { const partyType2: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287', name: 'example_name2', description: 'example_description2', @@ -1623,6 +1672,7 @@ describe('Contact store tests', (): void => { it('should throw error when updating party type with unknown id', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name', description: 'example_description', @@ -1643,6 +1693,7 @@ describe('Contact store tests', (): void => { it('should update party type by id', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name', description: 'example_description', @@ -1671,6 +1722,7 @@ describe('Contact store tests', (): void => { it('should remove party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name', description: 'example_description', @@ -1698,6 +1750,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1719,6 +1772,7 @@ describe('Contact store tests', (): void => { it('Should save party with existing party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -1742,16 +1796,19 @@ describe('Contact store tests', (): void => { expect(result?.partyType).toBeDefined() expect(result?.partyType.id).toEqual(savedPartyType.id) expect(result?.partyType.type).toEqual(savedPartyType.type) + expect(result?.partyType.origin).toEqual(savedPartyType.origin) expect(result?.partyType.tenantId).toEqual(savedPartyType.tenantId) expect(result?.partyType.name).toEqual(savedPartyType.name) }) it('should throw error when adding person party with wrong contact type', async (): Promise => { const partyType = PartyTypeEnum.ORGANIZATION + const partyTypeOrigin = PartyOriginEnum.INTERNAL const party: NonPersistedParty = { uri: 'example.com', partyType: { type: partyType, + origin: partyTypeOrigin, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1768,10 +1825,12 @@ describe('Contact store tests', (): void => { it('should throw error when adding organization party with wrong contact type', async (): Promise => { const partyType = PartyTypeEnum.NATURAL_PERSON + const partyTypeOrigin = PartyOriginEnum.EXTERNAL const party: NonPersistedParty = { uri: 'example.com', partyType: { type: partyType, + origin: partyTypeOrigin, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1789,6 +1848,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1827,6 +1887,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1874,6 +1935,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1917,6 +1979,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1965,6 +2028,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1994,6 +2058,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2027,6 +2092,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2067,6 +2133,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2109,6 +2176,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2168,6 +2236,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2223,6 +2292,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2283,6 +2353,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2318,6 +2389,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.INTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2357,6 +2429,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOriginEnum.EXTERNAL, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, diff --git a/packages/data-store/src/entities/contact/PartyTypeEntity.ts b/packages/data-store/src/entities/contact/PartyTypeEntity.ts index 8436b615d..94d9c8fe4 100644 --- a/packages/data-store/src/entities/contact/PartyTypeEntity.ts +++ b/packages/data-store/src/entities/contact/PartyTypeEntity.ts @@ -1,6 +1,6 @@ import { Entity, PrimaryGeneratedColumn, Column, Index, CreateDateColumn, UpdateDateColumn, OneToMany, BeforeInsert, BeforeUpdate } from 'typeorm' import { PartyEntity } from './PartyEntity' -import { PartyTypeEnum, ValidationConstraint } from '../../types' +import { PartyTypeEnum, PartyOriginEnum, ValidationConstraint } from '../../types' import { IsNotEmpty, Validate, validate, ValidationError } from 'class-validator' import { IsNonEmptyStringConstraint } from '../validators' import { getConstraint } from '../../utils/ValidatorUtils' @@ -14,6 +14,9 @@ export class PartyTypeEntity { @Column('simple-enum', { name: 'type', enum: PartyTypeEnum, nullable: false, unique: false }) type!: PartyTypeEnum + @Column('simple-enum', { name: 'type', enum: PartyOriginEnum, nullable: false, unique: false }) + origin!: PartyOriginEnum + @Column({ name: 'name', length: 255, nullable: false, unique: true }) @IsNotEmpty({ message: 'Blank names are not allowed' }) name!: string diff --git a/packages/data-store/src/migrations/generic/9-CreateContacts.ts b/packages/data-store/src/migrations/generic/9-CreateContacts.ts new file mode 100644 index 000000000..8011c8f00 --- /dev/null +++ b/packages/data-store/src/migrations/generic/9-CreateContacts.ts @@ -0,0 +1,66 @@ +import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm' +import Debug from 'debug' +import { CreateContacts1710941091795 } from '../postgres/1710941091795-CreateContacts' +import { CreateContacts1710941197348 } from '../sqlite/1710941197348-CreateContacts' + +const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations') + +export class CreateContacts1710942112855 implements MigrationInterface { + name = 'CreateContacts1710949828195' + + public async up(queryRunner: QueryRunner): Promise { + debug('migration: updating contact tables') + const dbType: DatabaseType = queryRunner.connection.driver.options.type + + switch (dbType) { + case 'postgres': { + debug('using postgres migration file') + const mig: CreateContacts1710941091795 = new CreateContacts1710941091795() + await mig.up(queryRunner) + debug('Migration statements executed') + return + } + case 'sqlite': + case 'expo': + case 'react-native': { + debug('using sqlite/react-native migration file') + const mig: CreateContacts1710941197348 = new CreateContacts1710941197348() + await mig.up(queryRunner) + debug('Migration statements executed') + return + } + default: + return Promise.reject( + `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now` + ) + } + } + + public async down(queryRunner: QueryRunner): Promise { + debug('migration: reverting machine state tables') + const dbType: DatabaseType = queryRunner.connection.driver.options.type + + switch (dbType) { + case 'postgres': { + debug('using postgres migration file') + const mig: CreateContacts1710941091795 = new CreateContacts1710941091795() + await mig.down(queryRunner) + debug('Migration statements executed') + return + } + case 'sqlite': + case 'expo': + case 'react-native': { + debug('using sqlite/react-native migration file') + const mig: CreateContacts1710941197348 = new CreateContacts1710941197348() + await mig.down(queryRunner) + debug('Migration statements executed') + return + } + default: + return Promise.reject( + `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now` + ) + } + } +} diff --git a/packages/data-store/src/migrations/generic/index.ts b/packages/data-store/src/migrations/generic/index.ts index 9769074fb..322ec0cf8 100644 --- a/packages/data-store/src/migrations/generic/index.ts +++ b/packages/data-store/src/migrations/generic/index.ts @@ -5,6 +5,7 @@ import { CreateStatusList1693866470000 } from './4-CreateStatusList' import { CreateAuditEvents1701635835330 } from './5-CreateAuditEvents' import { CreateDigitalCredential1708525189000 } from './6-CreateDigitalCredential' import { CreateMachineStateStore1708098041262 } from './7-CreateMachineStateStore' +import { CreateContacts1710942112855 } from './9-CreateContacts' /** * The migrations array that SHOULD be used when initializing a TypeORM database connection. @@ -15,7 +16,7 @@ import { CreateMachineStateStore1708098041262 } from './7-CreateMachineStateStor */ // Individual migrations per purpose. Allows parties to not run migrations and thus create/update tables if they are not using a particular feature (yet) -export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318] +export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318, CreateContacts1710942112855] export const DataStoreIssuanceBrandingMigrations = [CreateIssuanceBranding1659463079429] export const DataStoreStatusListMigrations = [CreateStatusList1693866470000] export const DataStoreEventLoggerMigrations = [CreateAuditEvents1701635835330] diff --git a/packages/data-store/src/migrations/postgres/1710941091795-CreateContacts.ts b/packages/data-store/src/migrations/postgres/1710941091795-CreateContacts.ts new file mode 100644 index 000000000..a1f315103 --- /dev/null +++ b/packages/data-store/src/migrations/postgres/1710941091795-CreateContacts.ts @@ -0,0 +1,15 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class CreateContacts1710941091795 implements MigrationInterface { + name = 'CreateContacts1710941091795' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TYPE "public"."partyOrigin_type_enum" AS ENUM('INTERNAL', 'EXTERNAL')`) + await queryRunner.query(`ALTER TABLE "PartyType" ADD COLUMN "origin" "public"."partyOrigin_type_enum" NOT NULL`) + } + + public async down(queryRunner: QueryRunner): Promise { + // TODO DPP-27 implement downgrade + return Promise.reject(Error(`Downgrade is not yet implemented for ${this.name}`)) + } +} diff --git a/packages/data-store/src/migrations/sqlite/1710941197348-CreateContacts.ts b/packages/data-store/src/migrations/sqlite/1710941197348-CreateContacts.ts new file mode 100644 index 000000000..71ff03557 --- /dev/null +++ b/packages/data-store/src/migrations/sqlite/1710941197348-CreateContacts.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class CreateContacts1710941197348 implements MigrationInterface { + name = 'CreateContacts1710941197348' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "PartyType" ADD COLUMN "origin" varchar CHECK( "origin" IN ('internal', 'external') ) NOT NULL`) + } + + public async down(queryRunner: QueryRunner): Promise { + // TODO DPP-27 implement downgrade + return Promise.reject(Error(`Downgrade is not yet implemented for ${this.name}`)) + } +} diff --git a/packages/data-store/src/types/contact/IAbstractContactStore.ts b/packages/data-store/src/types/contact/IAbstractContactStore.ts index 6ad3eddfe..287a99b0e 100644 --- a/packages/data-store/src/types/contact/IAbstractContactStore.ts +++ b/packages/data-store/src/types/contact/IAbstractContactStore.ts @@ -13,6 +13,7 @@ import { PartialPartyType, PartialPhysicalAddress, Party, + PartyOriginEnum, PartyRelationship, PartyType, PartyTypeEnum, @@ -95,6 +96,7 @@ export type UpdateRelationshipArgs = { export type AddPartyTypeArgs = { type: PartyTypeEnum + origin: PartyOriginEnum name: string tenantId: string description?: string diff --git a/packages/data-store/src/types/contact/contact.ts b/packages/data-store/src/types/contact/contact.ts index 3d42dd873..7008f26ff 100644 --- a/packages/data-store/src/types/contact/contact.ts +++ b/packages/data-store/src/types/contact/contact.ts @@ -150,9 +150,15 @@ export type Contact = NaturalPerson | Organization export type NonPersistedContact = NonPersistedNaturalPerson | NonPersistedOrganization export type PartialContact = PartialNaturalPerson | PartialOrganization +export enum PartyOriginEnum { + INTERNAL = 'internal', + EXTERNAL = 'external', +} + export type PartyType = { id: string type: PartyTypeEnum + origin: PartyOriginEnum name: string tenantId: string description?: string diff --git a/packages/data-store/src/utils/contact/MappingUtils.ts b/packages/data-store/src/utils/contact/MappingUtils.ts index 59c85810d..7347f4205 100644 --- a/packages/data-store/src/utils/contact/MappingUtils.ts +++ b/packages/data-store/src/utils/contact/MappingUtils.ts @@ -324,6 +324,7 @@ export const partyTypeEntityFrom = (args: NonPersistedPartyType): PartyTypeEntit partyTypeEntity.id = args.id } partyTypeEntity.type = args.type + partyTypeEntity.origin = args.origin partyTypeEntity.name = args.name partyTypeEntity.description = args.description partyTypeEntity.tenantId = args.tenantId @@ -335,6 +336,7 @@ export const partyTypeFrom = (partyType: PartyTypeEntity): PartyType => { return { id: partyType.id, type: partyType.type, + origin: partyType.origin, name: partyType.name, tenantId: partyType.tenantId, description: partyType.description,