diff --git a/packages/data-store/src/__tests__/contact.entities.test.ts b/packages/data-store/src/__tests__/contact.entities.test.ts index 689f82b6b..846d609a1 100644 --- a/packages/data-store/src/__tests__/contact.entities.test.ts +++ b/packages/data-store/src/__tests__/contact.entities.test.ts @@ -1,70 +1,58 @@ -import { DataSource, FindOptionsWhere } from 'typeorm' +import { DataSource, + // FindOptionsWhere +} from 'typeorm' import { DataStoreContactEntities, - // , DataStoreMigrations + DataStoreMigrations } from '../index' -import { NaturalPersonEntity } from '../entities/contact/NaturalPersonEntity' -import { OrganizationEntity } from '../entities/contact/OrganizationEntity' -import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity' -import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity' +//import { NaturalPersonEntity } from '../entities/contact/NaturalPersonEntity' +// import { OrganizationEntity } from '../entities/contact/OrganizationEntity' +// import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity' +// import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity' import { PartyEntity } from '../entities/contact/PartyEntity' -import { IdentityEntity } from '../entities/contact/IdentityEntity' -import { OpenIdConfigEntity } from '../entities/contact/OpenIdConfigEntity' -import { DidAuthConfigEntity } from '../entities/contact/DidAuthConfigEntity' -import { ConnectionEntity } from '../entities/contact/ConnectionEntity' -import { CorrelationIdentifierEntity } from '../entities/contact/CorrelationIdentifierEntity' -import { IdentityMetadataItemEntity } from '../entities/contact/IdentityMetadataItemEntity' -import { BaseContactEntity } from '../entities/contact/BaseContactEntity' +// import { IdentityEntity } from '../entities/contact/IdentityEntity' +// import { OpenIdConfigEntity } from '../entities/contact/OpenIdConfigEntity' +// import { DidAuthConfigEntity } from '../entities/contact/DidAuthConfigEntity' +// import { ConnectionEntity } from '../entities/contact/ConnectionEntity' +// import { CorrelationIdentifierEntity } from '../entities/contact/CorrelationIdentifierEntity' +// import { IdentityMetadataItemEntity } from '../entities/contact/IdentityMetadataItemEntity' +// import { BaseContactEntity } from '../entities/contact/BaseContactEntity' import { NonPersistedParty, PartyTypeEnum, - NaturalPerson, - Organization, - IdentityRoleEnum, - CorrelationIdentifierEnum, - ConnectionTypeEnum, - NonPersistedPartyType, - NonPersistedOrganization, - NonPersistedNaturalPerson, - NonPersistedConnection, - NonPersistedIdentity, - NonPersistedDidAuthConfig, - NonPersistedOpenIdConfig, + //NaturalPerson, + // Organization, + // IdentityRoleEnum, + // CorrelationIdentifierEnum, + // ConnectionTypeEnum, + // NonPersistedPartyType, + // NonPersistedOrganization, + // NonPersistedNaturalPerson, + // NonPersistedConnection, + // NonPersistedIdentity, + // NonPersistedDidAuthConfig, + // NonPersistedOpenIdConfig, } from '../types' import { - connectionEntityFrom, - didAuthConfigEntityFrom, - identityEntityFrom, - naturalPersonEntityFrom, - openIdConfigEntityFrom, - organizationEntityFrom, + // connectionEntityFrom, + // didAuthConfigEntityFrom, + // identityEntityFrom, + // naturalPersonEntityFrom, + // openIdConfigEntityFrom, + // organizationEntityFrom, partyEntityFrom, - partyRelationshipEntityFrom, - partyTypeEntityFrom, + // partyRelationshipEntityFrom, + // partyTypeEntityFrom, } from '../utils/contact/MappingUtils' describe('Database entities tests', (): void => { let dbConnection: DataSource - beforeEach(async (): Promise => { - dbConnection = await new DataSource({ - type: 'sqlite', - database: ':memory:', - logging: 'all', - migrationsRun: false, - // migrations: DataStoreMigrations, - synchronize: true, //false - entities: DataStoreContactEntities, - }).initialize() - // await dbConnection.runMigrations() - // expect(await dbConnection.showMigrations()).toBeFalsy() - }) - // beforeEach(async (): Promise => { // dbConnection = await new DataSource({ // type: 'sqlite', - // database: './database.sqlite', + // database: ':memory:', // logging: 'all', // migrationsRun: false, // // migrations: DataStoreMigrations, @@ -78,221 +66,235 @@ describe('Database entities tests', (): void => { // beforeEach(async (): Promise => { // dbConnection = await new DataSource({ // type: 'sqlite', - // database: ':memory:',//'./database.sqlite', + // database: './database.sqlite', // logging: 'all', // migrationsRun: false, - // migrations: DataStoreMigrations, - // synchronize: false, //false + // // migrations: DataStoreMigrations, + // synchronize: true, //false // entities: DataStoreContactEntities, // }).initialize() - // await dbConnection.runMigrations() - // expect(await dbConnection.showMigrations()).toBeFalsy() + // // await dbConnection.runMigrations() + // // expect(await dbConnection.showMigrations()).toBeFalsy() // }) - afterEach(async (): Promise => { - await (await dbConnection).destroy() - }) - - it('Should save person party to database', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - await dbConnection.getRepository(PartyEntity).save(partyEntity, { - transaction: true, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: partyEntity.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.identities?.length).toEqual(0) - expect(fromDb?.uri).toEqual(party.uri) - expect(fromDb?.partyType).toBeDefined() - expect(fromDb?.partyType.type).toEqual(party.partyType.type) - expect(fromDb?.partyType.tenantId).toEqual(party.partyType.tenantId) - expect(fromDb?.partyType.name).toEqual(party.partyType.name) - expect(fromDb?.contact).toBeDefined() - expect((fromDb?.contact).firstName).toEqual((party.contact).firstName) - expect((fromDb?.contact).middleName).toEqual((party.contact).middleName) - expect((fromDb?.contact).lastName).toEqual((party.contact).lastName) - expect((fromDb?.contact).displayName).toEqual((party.contact).displayName) - }) - - it('Should save organization party to database', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.ORGANIZATION, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - legalName: 'example_legal_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - await dbConnection.getRepository(PartyEntity).save(partyEntity, { - transaction: true, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: partyEntity.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.identities?.length).toEqual(0) - expect(fromDb?.uri).toEqual(party.uri) - expect(fromDb?.partyType).toBeDefined() - expect(fromDb?.partyType.type).toEqual(party.partyType.type) - expect(fromDb?.partyType.tenantId).toEqual(party.partyType.tenantId) - expect(fromDb?.partyType.name).toEqual(party.partyType.name) - expect(fromDb?.contact).toBeDefined() - expect((fromDb?.contact).legalName).toEqual((party.contact).legalName) - expect((fromDb?.contact).displayName).toEqual((party.contact).displayName) - }) - - it('Should result in party relationship for the owner side only', async (): Promise => { - const party1: NonPersistedParty = { - uri: 'example1.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name1', - }, - contact: { - firstName: 'example_first_name1', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity1: PartyEntity = partyEntityFrom(party1) - const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { - transaction: true, - }) - - const party2: NonPersistedParty = { - uri: 'example2.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name: 'example_name2', - }, - contact: { - firstName: 'example_first_name2', - middleName: 'example_middle_name2', - lastName: 'example_last_name2', - displayName: 'example_display_name2', - }, - } - - const partyEntity2: PartyEntity = partyEntityFrom(party2) - const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { - transaction: true, - }) - - const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { - transaction: true, - }) - - const fromDb1: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty1.id }, - }) - - const fromDb2: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty2.id }, - }) - - expect(fromDb1).toBeDefined() - expect(fromDb1?.relationships.length).toEqual(1) - expect(fromDb2).toBeDefined() - expect(fromDb2?.relationships.length).toEqual(0) - }) - - it('should throw error when saving person party with blank first name', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: '', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - - await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank first names are not allowed') + beforeEach(async (): Promise => { + dbConnection = await new DataSource({ + type: 'sqlite', + database: './database.sqlite', + logging: 'all', + migrationsRun: false, + migrations: DataStoreMigrations, + synchronize: false, //false + entities: DataStoreContactEntities, + }).initialize() + await dbConnection.runMigrations() + expect(await dbConnection.showMigrations()).toBeFalsy() }) - it('should throw error when saving person party with blank middle name', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: '', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - - await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank middle names are not allowed') + afterEach(async (): Promise => { + await (await dbConnection).destroy() }) - it('should throw error when saving person party with blank last name', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: '', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) + // it('Should save person party to database', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // await dbConnection.getRepository(PartyEntity).save(partyEntity, { + // transaction: true, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: partyEntity.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.identities?.length).toEqual(0) + // expect(fromDb?.uri).toEqual(party.uri) + // expect(fromDb?.partyType).toBeDefined() + // expect(fromDb?.partyType.type).toEqual(party.partyType.type) + // expect(fromDb?.partyType.tenantId).toEqual(party.partyType.tenantId) + // expect(fromDb?.partyType.name).toEqual(party.partyType.name) + // expect(fromDb?.contact).toBeDefined() + // expect((fromDb?.contact).firstName).toEqual((party.contact).firstName) + // expect((fromDb?.contact).middleName).toEqual((party.contact).middleName) + // expect((fromDb?.contact).lastName).toEqual((party.contact).lastName) + // expect((fromDb?.contact).displayName).toEqual((party.contact).displayName) + // }) - await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank last names are not allowed') - }) + // it('Should save organization party to database', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.ORGANIZATION, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // legalName: 'example_legal_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // await dbConnection.getRepository(PartyEntity).save(partyEntity, { + // transaction: true, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: partyEntity.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.identities?.length).toEqual(0) + // expect(fromDb?.uri).toEqual(party.uri) + // expect(fromDb?.partyType).toBeDefined() + // expect(fromDb?.partyType.type).toEqual(party.partyType.type) + // expect(fromDb?.partyType.tenantId).toEqual(party.partyType.tenantId) + // expect(fromDb?.partyType.name).toEqual(party.partyType.name) + // expect(fromDb?.contact).toBeDefined() + // expect((fromDb?.contact).legalName).toEqual((party.contact).legalName) + // expect((fromDb?.contact).displayName).toEqual((party.contact).displayName) + // }) + // + // it('Should result in party relationship for the owner side only', async (): Promise => { + // const party1: NonPersistedParty = { + // uri: 'example1.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name1', + // }, + // contact: { + // firstName: 'example_first_name1', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity1: PartyEntity = partyEntityFrom(party1) + // const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { + // transaction: true, + // }) + // + // const party2: NonPersistedParty = { + // uri: 'example2.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name: 'example_name2', + // }, + // contact: { + // firstName: 'example_first_name2', + // middleName: 'example_middle_name2', + // lastName: 'example_last_name2', + // displayName: 'example_display_name2', + // }, + // } + // + // const partyEntity2: PartyEntity = partyEntityFrom(party2) + // const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { + // transaction: true, + // }) + // + // const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { + // transaction: true, + // }) + // + // const fromDb1: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty1.id }, + // }) + // + // const fromDb2: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty2.id }, + // }) + // + // expect(fromDb1).toBeDefined() + // expect(fromDb1?.relationships.length).toEqual(1) + // expect(fromDb2).toBeDefined() + // expect(fromDb2?.relationships.length).toEqual(0) + // }) + // + // it('should throw error when saving person party with blank first name', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: '', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // + // await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank first names are not allowed') + // }) + // + // it('should throw error when saving person party with blank middle name', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: '', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // + // await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank middle names are not allowed') + // }) + // + // it('should throw error when saving person party with blank last name', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: '', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // + // await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank last names are not allowed') + // }) it('should throw error when saving person party with blank display name', async (): Promise => { const party: NonPersistedParty = { @@ -315,1890 +317,1890 @@ describe('Database entities tests', (): void => { await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank display names are not allowed') }) - it('should throw error when saving organization party with blank legal name', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.ORGANIZATION, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - legalName: '', - displayName: 'example_legal_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - - await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank legal names are not allowed') - }) - - it('should throw error when saving organization party with blank display name', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.ORGANIZATION, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - legalName: 'example_first_name', - displayName: '', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - - await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank display names are not allowed') - }) - - it('should throw error when saving party with blank party type name', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: '', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - - await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank names are not allowed') - }) - - it('should throw error when saving party with blank party type description', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - description: '', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - - await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank descriptions are not allowed') - }) - - it('should throw error when saving party with blank party type tenant id', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - - await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError("Blank tenant id's are not allowed") - }) - - it('Should enforce unique alias for an identity', async (): Promise => { - const alias = 'non_unique_alias' - const identity1: NonPersistedIdentity = { - alias, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId: 'unique_correlationId1', - }, - } - const identity1Entity: IdentityEntity = identityEntityFrom(identity1) - await dbConnection.getRepository(IdentityEntity).save(identity1Entity) - - const identity2: NonPersistedIdentity = { - alias: alias, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId: 'unique_correlationId2', - }, - } - const identity2Entity: IdentityEntity = identityEntityFrom(identity2) - await expect(dbConnection.getRepository(IdentityEntity).save(identity2Entity)).rejects.toThrowError( - 'SQLITE_CONSTRAINT: UNIQUE constraint failed: Identity.alias' - ) - }) - - it('Should enforce unique correlationId for a identity', async (): Promise => { - const correlationId = 'non_unique_correlationId' - const identity1: NonPersistedIdentity = { - alias: 'unique_alias1', - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId, - }, - } - const identity1Entity: IdentityEntity = identityEntityFrom(identity1) - await dbConnection.getRepository(IdentityEntity).save(identity1Entity) - - const identity2: NonPersistedIdentity = { - alias: 'unique_alias2', - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId, - }, - } - const identity2Entity: IdentityEntity = identityEntityFrom(identity2) - await expect(dbConnection.getRepository(IdentityEntity).save(identity2Entity)).rejects.toThrowError( - 'SQLITE_CONSTRAINT: UNIQUE constraint failed: CorrelationIdentifier.correlation_id' - ) - }) - - it('Should save identity to database', async (): Promise => { - const correlationId = 'example_did' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId, - }, - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - - await dbConnection.getRepository(IdentityEntity).save(identityEntity) - - const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ - where: { - identifier: { - correlationId, - }, - }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.connection).toBeNull() - expect(fromDb?.identifier).toBeDefined() - expect(fromDb?.identifier.correlationId).toEqual(identity.identifier.correlationId) - expect(fromDb?.identifier.type).toEqual(identity.identifier.type) - }) - - it('should throw error when saving identity with blank alias', async (): Promise => { - const identity: NonPersistedIdentity = { - alias: '', - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId: 'example_did', - }, - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - - await expect(dbConnection.getRepository(IdentityEntity).save(identityEntity)).rejects.toThrowError('Blank aliases are not allowed') - }) - - it('should throw error when saving identity with blank correlation id', async (): Promise => { - const identity: NonPersistedIdentity = { - alias: 'example_did', - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId: '', - }, - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - - await expect(dbConnection.getRepository(IdentityEntity).save(identityEntity)).rejects.toThrowError('Blank correlation ids are not allowed') - }) - - it('should throw error when saving identity with blank metadata label', async (): Promise => { - const correlationId = 'example_did' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId, - }, - metadata: [ - { - label: '', - value: 'example_value', - }, - ], - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - - await expect(dbConnection.getRepository(IdentityEntity).save(identityEntity)).rejects.toThrowError('Blank metadata labels are not allowed') - }) - - it('should throw error when saving identity with blank metadata value', async (): Promise => { - const correlationId = 'example_did' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId, - }, - metadata: [ - { - label: 'example_label', - value: '', - }, - ], - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - - await expect(dbConnection.getRepository(IdentityEntity).save(identityEntity)).rejects.toThrowError('Blank metadata values are not allowed') - }) - - it('Should save identity with openid connection to database', async (): Promise => { - const correlationId = 'example.com' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.URL, - correlationId, - }, - connection: { - type: ConnectionTypeEnum.OPENID_CONNECT, - config: { - clientId: '138d7bf8-c930-4c6e-b928-97d3a4928b01', - clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0', - scopes: ['auth'], - issuer: 'https://example.com/app-test', - redirectUrl: 'app:/callback', - dangerouslyAllowInsecureHttpRequests: true, - clientAuthMethod: 'post', - }, - }, - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - - await dbConnection.getRepository(IdentityEntity).save(identityEntity) - - const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ - where: { - identifier: { - correlationId, - }, - }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.connection).toBeDefined() - expect(fromDb?.identifier).toBeDefined() - expect(fromDb?.identifier.correlationId).toEqual(identity.identifier.correlationId) - expect(fromDb?.identifier.type).toEqual(identity.identifier.type) - expect(fromDb?.connection?.type).toEqual(identity.connection?.type) - expect(fromDb?.connection?.config).toBeDefined() - expect((fromDb?.connection?.config).clientId).toEqual((identity.connection?.config).clientId) - }) - - it('Should save identity with didauth connection to database', async (): Promise => { - const correlationId = 'example.com' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.URL, - correlationId, - }, - connection: { - type: ConnectionTypeEnum.SIOPv2, - config: { - identifier: { - did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - provider: 'test_provider', - keys: [], - services: [], - }, - redirectUrl: 'https://example.com', - stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', - sessionId: 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - }, - }, - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - - await dbConnection.getRepository(IdentityEntity).save(identityEntity) - - const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ - where: { - identifier: { - correlationId, - }, - }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.connection).toBeDefined() - expect(fromDb?.identifier).toBeDefined() - expect(fromDb?.identifier.correlationId).toEqual(identity.identifier.correlationId) - expect(fromDb?.identifier.type).toEqual(identity.identifier.type) - expect(fromDb?.connection?.type).toEqual(identity.connection?.type) - expect(fromDb?.connection?.config).toBeDefined() - expect((fromDb?.connection?.config).identifier).toEqual( - (identity.connection?.config).identifier.did - ) - }) - - it('Should save connection with openid config to database', async (): Promise => { - const connection: NonPersistedConnection = { - type: ConnectionTypeEnum.OPENID_CONNECT, - config: { - clientId: '138d7bf8-c930-4c6e-b928-97d3a4928b01', - clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0', - scopes: ['auth'], - issuer: 'https://example.com/app-test', - redirectUrl: 'app:/callback', - dangerouslyAllowInsecureHttpRequests: true, - clientAuthMethod: 'post', - }, - } - const connectionEntity: ConnectionEntity = connectionEntityFrom(connection) - await dbConnection.getRepository(ConnectionEntity).save(connectionEntity, { - transaction: true, - }) - - const fromDb: ConnectionEntity | null = await dbConnection.getRepository(ConnectionEntity).findOne({ - where: { type: connection.type }, - }) - - expect(fromDb).toBeDefined() - - const fromDbConfig: OpenIdConfigEntity | null = await dbConnection.getRepository(OpenIdConfigEntity).findOne({ - where: { id: fromDb?.id }, - }) - - expect(fromDbConfig).toBeDefined() - expect(fromDb?.type).toEqual(connection.type) - expect(fromDb?.config).toBeDefined() - expect((fromDb?.config).clientId).toEqual((connection.config).clientId) - }) - - it('Should save connection with didauth config to database', async (): Promise => { - const connection: NonPersistedConnection = { - type: ConnectionTypeEnum.SIOPv2, - config: { - identifier: { - did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - provider: 'test_provider', - keys: [], - services: [], - }, - redirectUrl: 'https://example.com', - stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', - sessionId: 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - }, - } - const connectionEntity: ConnectionEntity = connectionEntityFrom(connection) - await dbConnection.getRepository(ConnectionEntity).save(connectionEntity, { - transaction: true, - }) - - const fromDb: ConnectionEntity | null = await dbConnection.getRepository(ConnectionEntity).findOne({ - where: { type: connection.type }, - }) - - expect(fromDb).toBeDefined() - - const fromDbConfig: DidAuthConfigEntity | null = await dbConnection.getRepository(DidAuthConfigEntity).findOne({ - where: { id: fromDb?.id }, - }) - - expect(fromDbConfig).toBeDefined() - expect(fromDb?.type).toEqual(connection.type) - expect(fromDb?.config).toBeDefined() - expect((fromDb?.config).identifier).toEqual((connection.config).identifier.did) - }) - - it('Should save openid config to database', async (): Promise => { - const clientId = '138d7bf8-c930-4c6e-b928-97d3a4928b01' - const config: NonPersistedOpenIdConfig = { - clientId, - clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0', - scopes: ['auth'], - issuer: 'https://example.com/app-test', - redirectUrl: 'app:/callback', - dangerouslyAllowInsecureHttpRequests: true, - clientAuthMethod: 'post', - } - - const configEntity: OpenIdConfigEntity = openIdConfigEntityFrom(config) - await dbConnection.getRepository(OpenIdConfigEntity).save(configEntity, { - transaction: true, - }) - - const fromDb: OpenIdConfigEntity | null = await dbConnection.getRepository(OpenIdConfigEntity).findOne({ - where: { clientId: config.clientId }, - }) - - expect(fromDb).toBeDefined() - expect((fromDb).clientId).toEqual(config.clientId) - }) - - it('Should save didauth config to database', async (): Promise => { - const sessionId = 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01' - const config: NonPersistedDidAuthConfig = { - identifier: { - did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - provider: 'test_provider', - keys: [], - services: [], - }, - redirectUrl: 'https://example.com', - stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', - sessionId, - } - - const configEntity: DidAuthConfigEntity = didAuthConfigEntityFrom(config) - await dbConnection.getRepository(DidAuthConfigEntity).save(configEntity, { - transaction: true, - }) - - const fromDb: DidAuthConfigEntity | null = await dbConnection.getRepository(DidAuthConfigEntity).findOne({ - where: { sessionId: config.sessionId }, - }) - - expect(fromDb).toBeDefined() - expect((fromDb).identifier).toEqual(config.identifier.did) - }) - - it('Should delete party and all child relations', async (): Promise => { - const party1: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name1', - }, - contact: { - firstName: 'example_first_name1', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity1: PartyEntity = partyEntityFrom(party1) - const savedParty1: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity1) - - expect(savedParty1).toBeDefined() - - const party2: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name: 'example_name2', - }, - contact: { - firstName: 'example_first_name2', - middleName: 'example_middle_name2', - lastName: 'example_last_name2', - displayName: 'example_display_name2', - }, - } - - const partyEntity2: PartyEntity = partyEntityFrom(party2) - const savedParty2: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity2) - - expect(savedParty2).toBeDefined() - - const correlationId = 'relation_example.com' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.URL, - correlationId, - }, - connection: { - type: ConnectionTypeEnum.OPENID_CONNECT, - config: { - clientId: '138d7bf8-c930-4c6e-b928-97d3a4928b01', - clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0', - scopes: ['auth'], - issuer: 'https://example.com/app-test', - redirectUrl: 'app:/callback', - dangerouslyAllowInsecureHttpRequests: true, - clientAuthMethod: 'post', - }, - }, - metadata: [ - { - label: 'example_label', - value: 'example_value', - }, - ], - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - identityEntity.party = savedParty1 - - const savedIdentity: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).save(identityEntity) - - expect(savedIdentity).toBeDefined() - - const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - const savedRelationship: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { - transaction: true, - }) - - expect(savedRelationship).toBeDefined() - - expect( - await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty1.id }, - }) - ).toBeDefined() - - await dbConnection.getRepository(PartyEntity).delete({ id: savedParty1.id }) - - // check party - await expect( - await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty1.id }, - }) - ).toBeNull() - - // check identity - expect( - await dbConnection.getRepository(IdentityEntity).findOne({ - where: { id: savedParty1.id }, - }) - ).toBeNull() - - // check identity identifier - expect( - await dbConnection.getRepository(CorrelationIdentifierEntity).findOne({ - where: { id: savedIdentity.identifier.id }, - }) - ).toBeNull() - - // check identity connection - expect( - await dbConnection.getRepository(ConnectionEntity).findOne({ - where: { id: savedIdentity.connection!.id }, - }) - ).toBeNull() - - // check connection config - expect( - await dbConnection.getRepository(OpenIdConfigEntity).findOne({ - where: { id: savedIdentity.connection!.config.id }, - }) - ).toBeNull() - - // check identity metadata - expect( - await dbConnection.getRepository(IdentityMetadataItemEntity).findOne({ - where: { id: savedIdentity.metadata![0].id }, - }) - ).toBeNull() - - // check contact - expect( - await dbConnection.getRepository(BaseContactEntity).findOne({ - where: { id: savedParty1.contact.id }, - }) - ).toBeNull() - - // check party type - expect( - await dbConnection.getRepository(PartyTypeEntity).findOne({ - where: { id: savedParty1.partyType.id }, - }) - ).toBeDefined() - - // check relation - expect( - await dbConnection.getRepository(PartyRelationshipEntity).findOne({ - where: { id: savedRelationship.id }, - }) - ).toBeNull() - }) - - it('Should delete identity and all child relations', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) - - expect(savedParty).toBeDefined() - - const correlationId = 'relation_example.com' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.URL, - correlationId, - }, - connection: { - type: ConnectionTypeEnum.SIOPv2, - config: { - identifier: { - did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - provider: 'test_provider', - keys: [], - services: [], - }, - redirectUrl: 'https://example.com', - stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', - sessionId: 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - }, - }, - metadata: [ - { - label: 'example_label', - value: 'example_value', - }, - ], - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - identityEntity.party = savedParty - - const savedIdentity: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).save(identityEntity) - - expect( - await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty.id }, - }) - ).toBeDefined() - - await dbConnection.getRepository(IdentityEntity).delete({ id: savedIdentity.id }) - - // check identity - expect( - await dbConnection.getRepository(IdentityEntity).findOne({ - where: { alias: correlationId }, - }) - ).toBeNull() - - // check identity identifier - expect( - await dbConnection.getRepository(CorrelationIdentifierEntity).findOne({ - where: { id: savedIdentity.identifier.id }, - }) - ).toBeNull() - - // check identity connection - expect( - await dbConnection.getRepository(ConnectionEntity).findOne({ - where: { id: savedIdentity.connection!.id }, - }) - ).toBeNull() - - // check connection config - expect( - await dbConnection.getRepository(OpenIdConfigEntity).findOne({ - where: { id: savedIdentity.connection!.config.id }, - }) - ).toBeNull() - - // check identity metadata - expect( - await dbConnection.getRepository(IdentityMetadataItemEntity).findOne({ - where: { id: savedIdentity.metadata![0].id }, - }) - ).toBeNull() - }) - - it('Should not delete party when deleting identity', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) - - expect(savedParty).toBeDefined() - - const correlationId = 'relation_example.com' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.URL, - correlationId, - }, - connection: { - type: ConnectionTypeEnum.SIOPv2, - config: { - identifier: { - did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - provider: 'test_provider', - keys: [], - services: [], - }, - redirectUrl: 'https://example.com', - stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', - sessionId: 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', - }, - }, - metadata: [ - { - label: 'example_label', - value: 'example_value', - }, - ], - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - identityEntity.party = savedParty - - const savedIdentity: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).save(identityEntity) - - expect(savedIdentity).toBeDefined() - - await dbConnection.getRepository(IdentityEntity).delete({ id: savedIdentity.id }) - - // check identity - expect( - await dbConnection.getRepository(IdentityEntity).findOne({ - where: { id: savedIdentity.id }, - }) - ).toBeNull() - - // check party - expect( - await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty.id }, - }) - ).toBeDefined() - }) - - it('Should set creation date when saving party', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.createdAt).toBeDefined() - }) - - it('Should not update creation date when updating party', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) - - expect(savedParty).toBeDefined() - - const newContactFirstName = 'new_first_name' - await dbConnection.getRepository(PartyEntity).save({ - ...savedParty, - contact: { - ...savedParty.contact, - firstName: newContactFirstName, - }, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty.id }, - }) - - expect(fromDb).toBeDefined() - expect((fromDb?.contact).firstName).toEqual(newContactFirstName) - expect(fromDb?.createdAt).toEqual(savedParty?.createdAt) - }) - - it('Should set creation date when saving identity', async (): Promise => { - const correlationId = 'example_did' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId, - }, - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - await dbConnection.getRepository(IdentityEntity).save(identityEntity) - - const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ - where: { - identifier: { - correlationId, - }, - }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.createdAt).toBeDefined() - }) - - it('Should not update creation date when saving identity', async (): Promise => { - const correlationId = 'example_did' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId, - }, - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - const savedIdentity: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).save(identityEntity) - const newCorrelationId = 'new_example_did' - await dbConnection - .getRepository(IdentityEntity) - .save({ ...savedIdentity, identifier: { ...savedIdentity.identifier, correlationId: newCorrelationId } }) - - const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ - where: { - identifier: { - correlationId: newCorrelationId, - }, - }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.createdAt).toEqual(savedIdentity?.createdAt) - }) - - it('Should set last updated date when saving party', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.lastUpdatedAt).toBeDefined() - }) - - it('Should update last updated date when updating party', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) - expect(savedParty).toBeDefined() - - // waiting here to get a different timestamp - await new Promise((resolve) => setTimeout(resolve, 2000)) - - const newContactFirstName = 'new_first_name' - await dbConnection.getRepository(PartyEntity).save({ - ...savedParty, - // FIXME there is still an issue when updating nested objects, the parent does not update - // https://github.com/typeorm/typeorm/issues/5378 - uri: 'new uri', // TODO remove this to trigger the bug - contact: { - ...savedParty.contact, - firstName: newContactFirstName, - }, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: savedParty.id }, - }) - - expect(fromDb).toBeDefined() - expect((fromDb?.contact).firstName).toEqual(newContactFirstName) - expect(fromDb?.lastUpdatedAt).not.toEqual(savedParty?.lastUpdatedAt) - }) - - it('Should set last updated date when saving party type', async (): Promise => { - const partyType: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - } - - const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) - const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) - - const fromDb: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).findOne({ - where: { id: savedPartyType.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.lastUpdatedAt).toBeDefined() - }) - - it('Should set last creation date when saving party type', async (): Promise => { - const partyType: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - } - - const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) - const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) - - const fromDb: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).findOne({ - where: { id: savedPartyType.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.createdAt).toBeDefined() - }) - - it('Should set last updated date when saving identity', async (): Promise => { - const correlationId = 'example_did' - const identity: NonPersistedIdentity = { - alias: correlationId, - roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], - identifier: { - type: CorrelationIdentifierEnum.DID, - correlationId, - }, - } - - const identityEntity: IdentityEntity = identityEntityFrom(identity) - await dbConnection.getRepository(IdentityEntity).save(identityEntity) - - const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ - where: { - identifier: { - correlationId, - }, - }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.lastUpdatedAt).toBeDefined() - }) - - it('Should enforce unique type and tenant id combination when saving party type', async (): Promise => { - const tenantId = 'non_unique_value' - const name = 'non_unique_value' - const partyType1: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId, - name, - } - - const partyTypeEntity1: PartyTypeEntity = partyTypeEntityFrom(partyType1) - const savedPartyType1: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity1) - - expect(savedPartyType1).toBeDefined() - - const partyType2: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId, - name, - } - - const partyTypeEntity2: PartyTypeEntity = partyTypeEntityFrom(partyType2) - await expect(dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity2)).rejects.toThrowError( - 'SQLITE_CONSTRAINT: UNIQUE constraint failed: PartyType.type, PartyType.tenant_id' - ) - }) - - it('Should enforce unique name when saving party type', async (): Promise => { - const name = 'non_unique_value' - const partyType1: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name, - } - - const partyTypeEntity1: PartyTypeEntity = partyTypeEntityFrom(partyType1) - const savedPartyType1: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity1) - - expect(savedPartyType1).toBeDefined() - - const partyType2: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name, - } - - const partyTypeEntity2: PartyTypeEntity = partyTypeEntityFrom(partyType2) - await expect(dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity2)).rejects.toThrowError( - 'SQLITE_CONSTRAINT: UNIQUE constraint failed: PartyType.name' - ) - }) - - it('Should enforce unique legal name when saving organization', async (): Promise => { - const legalName = 'non_unique_value' - const organization1: NonPersistedOrganization = { - legalName, - displayName: 'example_display_name', - } - - const organizationEntity1: OrganizationEntity = organizationEntityFrom(organization1) - const savedOrganization1: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity1, { - transaction: true, - }) - - expect(savedOrganization1).toBeDefined() - - const organization2: NonPersistedOrganization = { - legalName, - displayName: 'example_display_name', - } - - const organizationEntity2: OrganizationEntity = organizationEntityFrom(organization2) - await expect(dbConnection.getRepository(OrganizationEntity).save(organizationEntity2)).rejects.toThrowError( - 'SQLITE_CONSTRAINT: UNIQUE constraint failed: BaseContact.legal_name' - ) - }) - - it('Should enforce unique legal name when saving organization', async (): Promise => { - const legalName = 'example_legal_name' - const organization1: NonPersistedOrganization = { - legalName, - displayName: 'example_display_name', - } - - const organizationEntity1: OrganizationEntity = organizationEntityFrom(organization1) - const savedOrganization1: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity1, { - transaction: true, - }) - - expect(savedOrganization1).toBeDefined() - - const organization2: NonPersistedOrganization = { - legalName, - displayName: 'example_display_name', - } - - const organizationEntity2: OrganizationEntity = organizationEntityFrom(organization2) - await expect(dbConnection.getRepository(OrganizationEntity).save(organizationEntity2)).rejects.toThrowError( - 'SQLITE_CONSTRAINT: UNIQUE constraint failed: BaseContact.legal_name' - ) - }) - - it('Should save party relationship to database', async (): Promise => { - const party1: NonPersistedParty = { - uri: 'example1.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name1', - }, - contact: { - firstName: 'example_first_name1', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity1: PartyEntity = partyEntityFrom(party1) - const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { - transaction: true, - }) - - expect(savedParty1).toBeDefined() - - const party2: NonPersistedParty = { - uri: 'example2.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name: 'example_name2', - }, - contact: { - firstName: 'example_first_name2', - middleName: 'example_middle_name2', - lastName: 'example_last_name2', - displayName: 'example_display_name2', - }, - } - - const partyEntity2: PartyEntity = partyEntityFrom(party2) - const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { - transaction: true, - }) - - expect(savedParty2).toBeDefined() - - const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { - transaction: true, - }) - - // TODO check the relation field - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: partyEntity1.id }, - }) - - expect(fromDb).toBeDefined() - }) - - it('Should set last updated date when saving party relationship', async (): Promise => { - const party1: NonPersistedParty = { - uri: 'example1.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name1', - }, - contact: { - firstName: 'example_first_name1', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity1: PartyEntity = partyEntityFrom(party1) - const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { - transaction: true, - }) - - const party2: NonPersistedParty = { - uri: 'example2.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name: 'example_name2', - }, - contact: { - firstName: 'example_first_name2', - middleName: 'example_middle_name2', - lastName: 'example_last_name2', - displayName: 'example_display_name2', - }, - } - - const partyEntity2: PartyEntity = partyEntityFrom(party2) - const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { - transaction: true, - }) - - const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { - transaction: true, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: partyEntity1.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.lastUpdatedAt).toBeDefined() - }) - - it('Should set creation date when saving party relationship', async (): Promise => { - const party1: NonPersistedParty = { - uri: 'example1.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name1', - }, - contact: { - firstName: 'example_first_name1', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity1: PartyEntity = partyEntityFrom(party1) - const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { - transaction: true, - }) - - const party2: NonPersistedParty = { - uri: 'example2.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name: 'example_name2', - }, - contact: { - firstName: 'example_first_name2', - middleName: 'example_middle_name2', - lastName: 'example_last_name2', - displayName: 'example_display_name2', - }, - } - - const partyEntity2: PartyEntity = partyEntityFrom(party2) - const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { - transaction: true, - }) - - const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { - transaction: true, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: partyEntity1.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.createdAt).toBeDefined() - }) - - it('Should save bidirectional party relationships to database', async (): Promise => { - const party1: NonPersistedParty = { - uri: 'example1.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name1', - }, - contact: { - firstName: 'example_first_name1', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity1: PartyEntity = partyEntityFrom(party1) - const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { - transaction: true, - }) - - expect(savedParty1).toBeDefined() - - const party2: NonPersistedParty = { - uri: 'example2.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name: 'example_name2', - }, - contact: { - firstName: 'example_first_name2', - middleName: 'example_middle_name2', - lastName: 'example_last_name2', - displayName: 'example_display_name2', - }, - } - - const partyEntity2: PartyEntity = partyEntityFrom(party2) - const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { - transaction: true, - }) - - expect(savedParty2).toBeDefined() - - const relationship1: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - const savedRelationship1: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship1, { - transaction: true, - }) - - expect(savedRelationship1).toBeDefined() - - const relationship2: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty2.id, - rightId: savedParty1.id, - }) - - const savedRelationship2: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship2, { - transaction: true, - }) - - expect(savedRelationship2).toBeDefined() - - const fromDb: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).findOne({ - where: { id: savedRelationship2.id }, - }) - - expect(fromDb).toBeDefined() - }) - - it('Should enforce unique owner combination for party relationship', async (): Promise => { - const party1: NonPersistedParty = { - uri: 'example1.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name1', - }, - contact: { - firstName: 'example_first_name1', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity1: PartyEntity = partyEntityFrom(party1) - const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { - transaction: true, - }) - - expect(savedParty1).toBeDefined() - - const party2: NonPersistedParty = { - uri: 'example2.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name: 'example_name2', - }, - contact: { - firstName: 'example_first_name2', - middleName: 'example_middle_name2', - lastName: 'example_last_name2', - displayName: 'example_display_name2', - }, - } - - const partyEntity2: PartyEntity = partyEntityFrom(party2) - const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { - transaction: true, - }) - - expect(savedParty2).toBeDefined() - - const relationship1: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - const savedRelationship1: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship1, { - transaction: true, - }) - - expect(savedRelationship1).toBeDefined() - - const relationship2: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - await expect(dbConnection.getRepository(PartyRelationshipEntity).save(relationship2)).rejects.toThrowError( - 'SQLITE_CONSTRAINT: UNIQUE constraint failed: PartyRelationship.left_id, PartyRelationship.right_id' - ) - }) - - it('Should save party type to database', async (): Promise => { - const partyType: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - } - - const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) - const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) - - const fromDb: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).findOne({ - where: { id: savedPartyType.id }, - }) - - expect(fromDb).toBeDefined() - }) - - it('Should save person to database', async (): Promise => { - const person: NonPersistedNaturalPerson = { - firstName: 'example_first_name', - lastName: 'lastName2', - displayName: 'displayName', - } - - const personEntity: NaturalPersonEntity = naturalPersonEntityFrom(person) - const savedPerson: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).save(personEntity, { - transaction: true, - }) - - const fromDb: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).findOne({ - where: { id: savedPerson.id }, - }) - - expect(fromDb).toBeDefined() - }) - - it('Should set last updated date when saving person', async (): Promise => { - const person: NonPersistedNaturalPerson = { - firstName: 'example_first_name', - lastName: 'lastName2', - displayName: 'displayName', - } - - const personEntity: NaturalPersonEntity = naturalPersonEntityFrom(person) - const savedPerson: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).save(personEntity, { - transaction: true, - }) - - const fromDb: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).findOne({ - where: { id: savedPerson.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.lastUpdatedAt).toBeDefined() - }) - - it('Should set creation date when saving person', async (): Promise => { - const person: NonPersistedNaturalPerson = { - firstName: 'example_first_name', - lastName: 'lastName2', - displayName: 'displayName', - } - - const personEntity: NaturalPersonEntity = naturalPersonEntityFrom(person) - const savedPerson: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).save(personEntity, { - transaction: true, - }) - - const fromDb: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).findOne({ - where: { id: savedPerson.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.createdAt).toBeDefined() - }) - - it('Should save organization to database', async (): Promise => { - const organization: NonPersistedOrganization = { - legalName: 'example_legal_name', - displayName: 'example_display_name', - } - - const organizationEntity: OrganizationEntity = organizationEntityFrom(organization) - const savedOrganization: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity, { - transaction: true, - }) - - const fromDb: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).findOne({ - where: { id: savedOrganization.id }, - }) - - expect(fromDb).toBeDefined() - }) - - it('Should set last updated date when saving organization', async (): Promise => { - const organization: NonPersistedOrganization = { - legalName: 'example_legal_name', - displayName: 'example_display_name', - } - - const organizationEntity: OrganizationEntity = organizationEntityFrom(organization) - const savedOrganization: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity, { - transaction: true, - }) - - const fromDb: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).findOne({ - where: { id: savedOrganization.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.lastUpdatedAt).toBeDefined() - }) - - it('Should set creation date when saving organization', async (): Promise => { - const organization: NonPersistedOrganization = { - legalName: 'example_legal_name', - displayName: 'example_display_name', - } - - const organizationEntity: OrganizationEntity = organizationEntityFrom(organization) - const savedOrganization: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity, { - transaction: true, - }) - - const fromDb: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).findOne({ - where: { id: savedOrganization.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.createdAt).toBeDefined() - }) - - it('Should get party based on person information', async (): Promise => { - const firstName = 'example_first_name' - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName, - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - await dbConnection.getRepository(PartyEntity).save(partyEntity, { - transaction: true, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { - contact: { - firstName, - } as FindOptionsWhere, //NaturalPersonEntity | OrganizationEntity - }, - }) - - expect(fromDb).toBeDefined() - }) - - it('Should get party based on organization information', async (): Promise => { - const legalName = 'example_legal_name' - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.ORGANIZATION, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - legalName, - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - await dbConnection.getRepository(PartyEntity).save(partyEntity, { - transaction: true, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { - contact: { - legalName, - } as FindOptionsWhere, //NaturalPersonEntity | OrganizationEntity - }, - }) - - expect(fromDb).toBeDefined() - }) - - it("Should enforce unique party id's for relationship sides", async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - const savedParty: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity, { - transaction: true, - }) - - expect(savedParty).toBeDefined() - - const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty.id, - rightId: savedParty.id, - }) - - await expect(dbConnection.getRepository(PartyRelationshipEntity).save(relationship)).rejects.toThrowError( - 'Cannot use the same id for both sides of the relationship' - ) - }) - - it('Should delete party relationship', async (): Promise => { - const party1: NonPersistedParty = { - uri: 'example1.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name1', - }, - contact: { - firstName: 'example_first_name1', - middleName: 'example_middle_name1', - lastName: 'example_last_name1', - displayName: 'example_display_name1', - }, - } - - const partyEntity1: PartyEntity = partyEntityFrom(party1) - const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { - transaction: true, - }) - - expect(savedParty1).toBeDefined() - - const party2: NonPersistedParty = { - uri: 'example2.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', - name: 'example_name2', - }, - contact: { - firstName: 'example_first_name2', - middleName: 'example_middle_name2', - lastName: 'example_last_name2', - displayName: 'example_display_name2', - }, - } - - const partyEntity2: PartyEntity = partyEntityFrom(party2) - const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { - transaction: true, - }) - - expect(savedParty2).toBeDefined() - - const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ - leftId: savedParty1.id, - rightId: savedParty2.id, - }) - - const savedRelationship: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { - transaction: true, - }) - - expect(savedRelationship).toBeDefined() - - await dbConnection.getRepository(PartyRelationshipEntity).delete({ id: savedRelationship.id }) - - await expect( - await dbConnection.getRepository(PartyRelationshipEntity).findOne({ - where: { id: savedRelationship.id }, - }) - ).toBeNull() - }) - - it('Should delete party type', async (): Promise => { - const partyType: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - } - - const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) - const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) - - expect(savedPartyType).toBeDefined() - - await dbConnection.getRepository(PartyTypeEntity).delete({ id: savedPartyType.id }) - - await expect( - await dbConnection.getRepository(PartyTypeEntity).findOne({ - where: { id: savedPartyType.id }, - }) - ).toBeNull() - }) - - it('Should not be able to remove party type when used by parties', async (): Promise => { - const party: NonPersistedParty = { - uri: 'example.com', - partyType: { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - }, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity, { - transaction: true, - }) - - expect(savedParty).toBeDefined() - - await expect(dbConnection.getRepository(PartyTypeEntity).delete({ id: savedParty.partyType.id })).rejects.toThrowError( - 'FOREIGN KEY constraint failed' - ) - }) - - it('Should save party with existing party type', async (): Promise => { - const partyType: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - } - - const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) - const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) - - const party: NonPersistedParty = { - uri: 'example.com', - partyType: savedPartyType, - contact: { - firstName: 'example_first_name', - middleName: 'example_middle_name', - lastName: 'example_last_name', - displayName: 'example_display_name', - }, - } - - const partyEntity: PartyEntity = partyEntityFrom(party) - partyEntity.partyType = savedPartyType - await dbConnection.getRepository(PartyEntity).save(partyEntity, { - transaction: true, - }) - - const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ - where: { id: partyEntity.id }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.partyType).toBeDefined() - expect(fromDb?.partyType.id).toEqual(savedPartyType.id) - expect(fromDb?.partyType.type).toEqual(savedPartyType.type) - expect(fromDb?.partyType.tenantId).toEqual(savedPartyType.tenantId) - expect(fromDb?.partyType.name).toEqual(savedPartyType.name) - }) - - it('Should not update creation date when saving party type', async (): Promise => { - const partyType: NonPersistedPartyType = { - type: PartyTypeEnum.NATURAL_PERSON, - tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', - name: 'example_name', - } - - const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) - const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) - await dbConnection.getRepository(PartyTypeEntity).save({ ...savedPartyType, type: PartyTypeEnum.ORGANIZATION }) - - const fromDb: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).findOne({ - where: { - type: PartyTypeEnum.ORGANIZATION, - }, - }) - - expect(fromDb).toBeDefined() - expect(fromDb?.createdAt).toEqual(savedPartyType?.createdAt) - }) + // it('should throw error when saving organization party with blank legal name', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.ORGANIZATION, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // legalName: '', + // displayName: 'example_legal_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // + // await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank legal names are not allowed') + // }) + // + // it('should throw error when saving organization party with blank display name', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.ORGANIZATION, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // legalName: 'example_first_name', + // displayName: '', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // + // await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank display names are not allowed') + // }) + // + // it('should throw error when saving party with blank party type name', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: '', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // + // await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank names are not allowed') + // }) + // + // it('should throw error when saving party with blank party type description', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // description: '', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // + // await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError('Blank descriptions are not allowed') + // }) + // + // it('should throw error when saving party with blank party type tenant id', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // + // await expect(dbConnection.getRepository(PartyEntity).save(partyEntity)).rejects.toThrowError("Blank tenant id's are not allowed") + // }) + // + // it('Should enforce unique alias for an identity', async (): Promise => { + // const alias = 'non_unique_alias' + // const identity1: NonPersistedIdentity = { + // alias, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId: 'unique_correlationId1', + // }, + // } + // const identity1Entity: IdentityEntity = identityEntityFrom(identity1) + // await dbConnection.getRepository(IdentityEntity).save(identity1Entity) + // + // const identity2: NonPersistedIdentity = { + // alias: alias, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId: 'unique_correlationId2', + // }, + // } + // const identity2Entity: IdentityEntity = identityEntityFrom(identity2) + // await expect(dbConnection.getRepository(IdentityEntity).save(identity2Entity)).rejects.toThrowError( + // 'SQLITE_CONSTRAINT: UNIQUE constraint failed: Identity.alias' + // ) + // }) + // + // it('Should enforce unique correlationId for a identity', async (): Promise => { + // const correlationId = 'non_unique_correlationId' + // const identity1: NonPersistedIdentity = { + // alias: 'unique_alias1', + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId, + // }, + // } + // const identity1Entity: IdentityEntity = identityEntityFrom(identity1) + // await dbConnection.getRepository(IdentityEntity).save(identity1Entity) + // + // const identity2: NonPersistedIdentity = { + // alias: 'unique_alias2', + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId, + // }, + // } + // const identity2Entity: IdentityEntity = identityEntityFrom(identity2) + // await expect(dbConnection.getRepository(IdentityEntity).save(identity2Entity)).rejects.toThrowError( + // 'SQLITE_CONSTRAINT: UNIQUE constraint failed: CorrelationIdentifier.correlation_id' + // ) + // }) + // + // it('Should save identity to database', async (): Promise => { + // const correlationId = 'example_did' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId, + // }, + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // + // await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // + // const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { + // identifier: { + // correlationId, + // }, + // }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.connection).toBeNull() + // expect(fromDb?.identifier).toBeDefined() + // expect(fromDb?.identifier.correlationId).toEqual(identity.identifier.correlationId) + // expect(fromDb?.identifier.type).toEqual(identity.identifier.type) + // }) + // + // it('should throw error when saving identity with blank alias', async (): Promise => { + // const identity: NonPersistedIdentity = { + // alias: '', + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId: 'example_did', + // }, + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // + // await expect(dbConnection.getRepository(IdentityEntity).save(identityEntity)).rejects.toThrowError('Blank aliases are not allowed') + // }) + // + // it('should throw error when saving identity with blank correlation id', async (): Promise => { + // const identity: NonPersistedIdentity = { + // alias: 'example_did', + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId: '', + // }, + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // + // await expect(dbConnection.getRepository(IdentityEntity).save(identityEntity)).rejects.toThrowError('Blank correlation ids are not allowed') + // }) + // + // it('should throw error when saving identity with blank metadata label', async (): Promise => { + // const correlationId = 'example_did' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId, + // }, + // metadata: [ + // { + // label: '', + // value: 'example_value', + // }, + // ], + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // + // await expect(dbConnection.getRepository(IdentityEntity).save(identityEntity)).rejects.toThrowError('Blank metadata labels are not allowed') + // }) + // + // it('should throw error when saving identity with blank metadata value', async (): Promise => { + // const correlationId = 'example_did' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId, + // }, + // metadata: [ + // { + // label: 'example_label', + // value: '', + // }, + // ], + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // + // await expect(dbConnection.getRepository(IdentityEntity).save(identityEntity)).rejects.toThrowError('Blank metadata values are not allowed') + // }) + // + // it('Should save identity with openid connection to database', async (): Promise => { + // const correlationId = 'example.com' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.URL, + // correlationId, + // }, + // connection: { + // type: ConnectionTypeEnum.OPENID_CONNECT, + // config: { + // clientId: '138d7bf8-c930-4c6e-b928-97d3a4928b01', + // clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0', + // scopes: ['auth'], + // issuer: 'https://example.com/app-test', + // redirectUrl: 'app:/callback', + // dangerouslyAllowInsecureHttpRequests: true, + // clientAuthMethod: 'post', + // }, + // }, + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // + // await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // + // const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { + // identifier: { + // correlationId, + // }, + // }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.connection).toBeDefined() + // expect(fromDb?.identifier).toBeDefined() + // expect(fromDb?.identifier.correlationId).toEqual(identity.identifier.correlationId) + // expect(fromDb?.identifier.type).toEqual(identity.identifier.type) + // expect(fromDb?.connection?.type).toEqual(identity.connection?.type) + // expect(fromDb?.connection?.config).toBeDefined() + // expect((fromDb?.connection?.config).clientId).toEqual((identity.connection?.config).clientId) + // }) + // + // it('Should save identity with didauth connection to database', async (): Promise => { + // const correlationId = 'example.com' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.URL, + // correlationId, + // }, + // connection: { + // type: ConnectionTypeEnum.SIOPv2, + // config: { + // identifier: { + // did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // provider: 'test_provider', + // keys: [], + // services: [], + // }, + // redirectUrl: 'https://example.com', + // stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', + // sessionId: 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // }, + // }, + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // + // await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // + // const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { + // identifier: { + // correlationId, + // }, + // }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.connection).toBeDefined() + // expect(fromDb?.identifier).toBeDefined() + // expect(fromDb?.identifier.correlationId).toEqual(identity.identifier.correlationId) + // expect(fromDb?.identifier.type).toEqual(identity.identifier.type) + // expect(fromDb?.connection?.type).toEqual(identity.connection?.type) + // expect(fromDb?.connection?.config).toBeDefined() + // expect((fromDb?.connection?.config).identifier).toEqual( + // (identity.connection?.config).identifier.did + // ) + // }) + // + // it('Should save connection with openid config to database', async (): Promise => { + // const connection: NonPersistedConnection = { + // type: ConnectionTypeEnum.OPENID_CONNECT, + // config: { + // clientId: '138d7bf8-c930-4c6e-b928-97d3a4928b01', + // clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0', + // scopes: ['auth'], + // issuer: 'https://example.com/app-test', + // redirectUrl: 'app:/callback', + // dangerouslyAllowInsecureHttpRequests: true, + // clientAuthMethod: 'post', + // }, + // } + // const connectionEntity: ConnectionEntity = connectionEntityFrom(connection) + // await dbConnection.getRepository(ConnectionEntity).save(connectionEntity, { + // transaction: true, + // }) + // + // const fromDb: ConnectionEntity | null = await dbConnection.getRepository(ConnectionEntity).findOne({ + // where: { type: connection.type }, + // }) + // + // expect(fromDb).toBeDefined() + // + // const fromDbConfig: OpenIdConfigEntity | null = await dbConnection.getRepository(OpenIdConfigEntity).findOne({ + // where: { id: fromDb?.id }, + // }) + // + // expect(fromDbConfig).toBeDefined() + // expect(fromDb?.type).toEqual(connection.type) + // expect(fromDb?.config).toBeDefined() + // expect((fromDb?.config).clientId).toEqual((connection.config).clientId) + // }) + // + // it('Should save connection with didauth config to database', async (): Promise => { + // const connection: NonPersistedConnection = { + // type: ConnectionTypeEnum.SIOPv2, + // config: { + // identifier: { + // did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // provider: 'test_provider', + // keys: [], + // services: [], + // }, + // redirectUrl: 'https://example.com', + // stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', + // sessionId: 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // }, + // } + // const connectionEntity: ConnectionEntity = connectionEntityFrom(connection) + // await dbConnection.getRepository(ConnectionEntity).save(connectionEntity, { + // transaction: true, + // }) + // + // const fromDb: ConnectionEntity | null = await dbConnection.getRepository(ConnectionEntity).findOne({ + // where: { type: connection.type }, + // }) + // + // expect(fromDb).toBeDefined() + // + // const fromDbConfig: DidAuthConfigEntity | null = await dbConnection.getRepository(DidAuthConfigEntity).findOne({ + // where: { id: fromDb?.id }, + // }) + // + // expect(fromDbConfig).toBeDefined() + // expect(fromDb?.type).toEqual(connection.type) + // expect(fromDb?.config).toBeDefined() + // expect((fromDb?.config).identifier).toEqual((connection.config).identifier.did) + // }) + // + // it('Should save openid config to database', async (): Promise => { + // const clientId = '138d7bf8-c930-4c6e-b928-97d3a4928b01' + // const config: NonPersistedOpenIdConfig = { + // clientId, + // clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0', + // scopes: ['auth'], + // issuer: 'https://example.com/app-test', + // redirectUrl: 'app:/callback', + // dangerouslyAllowInsecureHttpRequests: true, + // clientAuthMethod: 'post', + // } + // + // const configEntity: OpenIdConfigEntity = openIdConfigEntityFrom(config) + // await dbConnection.getRepository(OpenIdConfigEntity).save(configEntity, { + // transaction: true, + // }) + // + // const fromDb: OpenIdConfigEntity | null = await dbConnection.getRepository(OpenIdConfigEntity).findOne({ + // where: { clientId: config.clientId }, + // }) + // + // expect(fromDb).toBeDefined() + // expect((fromDb).clientId).toEqual(config.clientId) + // }) + // + // it('Should save didauth config to database', async (): Promise => { + // const sessionId = 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01' + // const config: NonPersistedDidAuthConfig = { + // identifier: { + // did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // provider: 'test_provider', + // keys: [], + // services: [], + // }, + // redirectUrl: 'https://example.com', + // stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', + // sessionId, + // } + // + // const configEntity: DidAuthConfigEntity = didAuthConfigEntityFrom(config) + // await dbConnection.getRepository(DidAuthConfigEntity).save(configEntity, { + // transaction: true, + // }) + // + // const fromDb: DidAuthConfigEntity | null = await dbConnection.getRepository(DidAuthConfigEntity).findOne({ + // where: { sessionId: config.sessionId }, + // }) + // + // expect(fromDb).toBeDefined() + // expect((fromDb).identifier).toEqual(config.identifier.did) + // }) + // + // it('Should delete party and all child relations', async (): Promise => { + // const party1: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name1', + // }, + // contact: { + // firstName: 'example_first_name1', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity1: PartyEntity = partyEntityFrom(party1) + // const savedParty1: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity1) + // + // expect(savedParty1).toBeDefined() + // + // const party2: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name: 'example_name2', + // }, + // contact: { + // firstName: 'example_first_name2', + // middleName: 'example_middle_name2', + // lastName: 'example_last_name2', + // displayName: 'example_display_name2', + // }, + // } + // + // const partyEntity2: PartyEntity = partyEntityFrom(party2) + // const savedParty2: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity2) + // + // expect(savedParty2).toBeDefined() + // + // const correlationId = 'relation_example.com' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.URL, + // correlationId, + // }, + // connection: { + // type: ConnectionTypeEnum.OPENID_CONNECT, + // config: { + // clientId: '138d7bf8-c930-4c6e-b928-97d3a4928b01', + // clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0', + // scopes: ['auth'], + // issuer: 'https://example.com/app-test', + // redirectUrl: 'app:/callback', + // dangerouslyAllowInsecureHttpRequests: true, + // clientAuthMethod: 'post', + // }, + // }, + // metadata: [ + // { + // label: 'example_label', + // value: 'example_value', + // }, + // ], + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // identityEntity.party = savedParty1 + // + // const savedIdentity: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // + // expect(savedIdentity).toBeDefined() + // + // const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // const savedRelationship: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { + // transaction: true, + // }) + // + // expect(savedRelationship).toBeDefined() + // + // expect( + // await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty1.id }, + // }) + // ).toBeDefined() + // + // await dbConnection.getRepository(PartyEntity).delete({ id: savedParty1.id }) + // + // // check party + // await expect( + // await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty1.id }, + // }) + // ).toBeNull() + // + // // check identity + // expect( + // await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { id: savedParty1.id }, + // }) + // ).toBeNull() + // + // // check identity identifier + // expect( + // await dbConnection.getRepository(CorrelationIdentifierEntity).findOne({ + // where: { id: savedIdentity.identifier.id }, + // }) + // ).toBeNull() + // + // // check identity connection + // expect( + // await dbConnection.getRepository(ConnectionEntity).findOne({ + // where: { id: savedIdentity.connection!.id }, + // }) + // ).toBeNull() + // + // // check connection config + // expect( + // await dbConnection.getRepository(OpenIdConfigEntity).findOne({ + // where: { id: savedIdentity.connection!.config.id }, + // }) + // ).toBeNull() + // + // // check identity metadata + // expect( + // await dbConnection.getRepository(IdentityMetadataItemEntity).findOne({ + // where: { id: savedIdentity.metadata![0].id }, + // }) + // ).toBeNull() + // + // // check contact + // expect( + // await dbConnection.getRepository(BaseContactEntity).findOne({ + // where: { id: savedParty1.contact.id }, + // }) + // ).toBeNull() + // + // // check party type + // expect( + // await dbConnection.getRepository(PartyTypeEntity).findOne({ + // where: { id: savedParty1.partyType.id }, + // }) + // ).toBeDefined() + // + // // check relation + // expect( + // await dbConnection.getRepository(PartyRelationshipEntity).findOne({ + // where: { id: savedRelationship.id }, + // }) + // ).toBeNull() + // }) + // + // it('Should delete identity and all child relations', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) + // + // expect(savedParty).toBeDefined() + // + // const correlationId = 'relation_example.com' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.URL, + // correlationId, + // }, + // connection: { + // type: ConnectionTypeEnum.SIOPv2, + // config: { + // identifier: { + // did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // provider: 'test_provider', + // keys: [], + // services: [], + // }, + // redirectUrl: 'https://example.com', + // stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', + // sessionId: 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // }, + // }, + // metadata: [ + // { + // label: 'example_label', + // value: 'example_value', + // }, + // ], + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // identityEntity.party = savedParty + // + // const savedIdentity: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // + // expect( + // await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty.id }, + // }) + // ).toBeDefined() + // + // await dbConnection.getRepository(IdentityEntity).delete({ id: savedIdentity.id }) + // + // // check identity + // expect( + // await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { alias: correlationId }, + // }) + // ).toBeNull() + // + // // check identity identifier + // expect( + // await dbConnection.getRepository(CorrelationIdentifierEntity).findOne({ + // where: { id: savedIdentity.identifier.id }, + // }) + // ).toBeNull() + // + // // check identity connection + // expect( + // await dbConnection.getRepository(ConnectionEntity).findOne({ + // where: { id: savedIdentity.connection!.id }, + // }) + // ).toBeNull() + // + // // check connection config + // expect( + // await dbConnection.getRepository(OpenIdConfigEntity).findOne({ + // where: { id: savedIdentity.connection!.config.id }, + // }) + // ).toBeNull() + // + // // check identity metadata + // expect( + // await dbConnection.getRepository(IdentityMetadataItemEntity).findOne({ + // where: { id: savedIdentity.metadata![0].id }, + // }) + // ).toBeNull() + // }) + // + // it('Should not delete party when deleting identity', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) + // + // expect(savedParty).toBeDefined() + // + // const correlationId = 'relation_example.com' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.URL, + // correlationId, + // }, + // connection: { + // type: ConnectionTypeEnum.SIOPv2, + // config: { + // identifier: { + // did: 'did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // provider: 'test_provider', + // keys: [], + // services: [], + // }, + // redirectUrl: 'https://example.com', + // stateId: 'e91f3510-5ce9-42ee-83b7-fa68ff323d27', + // sessionId: 'https://example.com/did:test:138d7bf8-c930-4c6e-b928-97d3a4928b01', + // }, + // }, + // metadata: [ + // { + // label: 'example_label', + // value: 'example_value', + // }, + // ], + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // identityEntity.party = savedParty + // + // const savedIdentity: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // + // expect(savedIdentity).toBeDefined() + // + // await dbConnection.getRepository(IdentityEntity).delete({ id: savedIdentity.id }) + // + // // check identity + // expect( + // await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { id: savedIdentity.id }, + // }) + // ).toBeNull() + // + // // check party + // expect( + // await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty.id }, + // }) + // ).toBeDefined() + // }) + // + // it('Should set creation date when saving party', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.createdAt).toBeDefined() + // }) + // + // it('Should not update creation date when updating party', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) + // + // expect(savedParty).toBeDefined() + // + // const newContactFirstName = 'new_first_name' + // await dbConnection.getRepository(PartyEntity).save({ + // ...savedParty, + // contact: { + // ...savedParty.contact, + // firstName: newContactFirstName, + // }, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect((fromDb?.contact).firstName).toEqual(newContactFirstName) + // expect(fromDb?.createdAt).toEqual(savedParty?.createdAt) + // }) + // + // it('Should set creation date when saving identity', async (): Promise => { + // const correlationId = 'example_did' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId, + // }, + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // + // const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { + // identifier: { + // correlationId, + // }, + // }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.createdAt).toBeDefined() + // }) + // + // it('Should not update creation date when saving identity', async (): Promise => { + // const correlationId = 'example_did' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId, + // }, + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // const savedIdentity: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // const newCorrelationId = 'new_example_did' + // await dbConnection + // .getRepository(IdentityEntity) + // .save({ ...savedIdentity, identifier: { ...savedIdentity.identifier, correlationId: newCorrelationId } }) + // + // const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { + // identifier: { + // correlationId: newCorrelationId, + // }, + // }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.createdAt).toEqual(savedIdentity?.createdAt) + // }) + // + // it('Should set last updated date when saving party', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.lastUpdatedAt).toBeDefined() + // }) + // + // it('Should update last updated date when updating party', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity) + // expect(savedParty).toBeDefined() + // + // // waiting here to get a different timestamp + // await new Promise((resolve) => setTimeout(resolve, 2000)) + // + // const newContactFirstName = 'new_first_name' + // await dbConnection.getRepository(PartyEntity).save({ + // ...savedParty, + // // FIXME there is still an issue when updating nested objects, the parent does not update + // // https://github.com/typeorm/typeorm/issues/5378 + // uri: 'new uri', // TODO remove this to trigger the bug + // contact: { + // ...savedParty.contact, + // firstName: newContactFirstName, + // }, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: savedParty.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect((fromDb?.contact).firstName).toEqual(newContactFirstName) + // expect(fromDb?.lastUpdatedAt).not.toEqual(savedParty?.lastUpdatedAt) + // }) + // + // it('Should set last updated date when saving party type', async (): Promise => { + // const partyType: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // } + // + // const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) + // const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) + // + // const fromDb: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).findOne({ + // where: { id: savedPartyType.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.lastUpdatedAt).toBeDefined() + // }) + // + // it('Should set last creation date when saving party type', async (): Promise => { + // const partyType: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // } + // + // const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) + // const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) + // + // const fromDb: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).findOne({ + // where: { id: savedPartyType.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.createdAt).toBeDefined() + // }) + // + // it('Should set last updated date when saving identity', async (): Promise => { + // const correlationId = 'example_did' + // const identity: NonPersistedIdentity = { + // alias: correlationId, + // roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER], + // identifier: { + // type: CorrelationIdentifierEnum.DID, + // correlationId, + // }, + // } + // + // const identityEntity: IdentityEntity = identityEntityFrom(identity) + // await dbConnection.getRepository(IdentityEntity).save(identityEntity) + // + // const fromDb: IdentityEntity | null = await dbConnection.getRepository(IdentityEntity).findOne({ + // where: { + // identifier: { + // correlationId, + // }, + // }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.lastUpdatedAt).toBeDefined() + // }) + // + // it('Should enforce unique type and tenant id combination when saving party type', async (): Promise => { + // const tenantId = 'non_unique_value' + // const name = 'non_unique_value' + // const partyType1: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId, + // name, + // } + // + // const partyTypeEntity1: PartyTypeEntity = partyTypeEntityFrom(partyType1) + // const savedPartyType1: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity1) + // + // expect(savedPartyType1).toBeDefined() + // + // const partyType2: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId, + // name, + // } + // + // const partyTypeEntity2: PartyTypeEntity = partyTypeEntityFrom(partyType2) + // await expect(dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity2)).rejects.toThrowError( + // 'SQLITE_CONSTRAINT: UNIQUE constraint failed: PartyType.type, PartyType.tenant_id' + // ) + // }) + // + // it('Should enforce unique name when saving party type', async (): Promise => { + // const name = 'non_unique_value' + // const partyType1: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name, + // } + // + // const partyTypeEntity1: PartyTypeEntity = partyTypeEntityFrom(partyType1) + // const savedPartyType1: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity1) + // + // expect(savedPartyType1).toBeDefined() + // + // const partyType2: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name, + // } + // + // const partyTypeEntity2: PartyTypeEntity = partyTypeEntityFrom(partyType2) + // await expect(dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity2)).rejects.toThrowError( + // 'SQLITE_CONSTRAINT: UNIQUE constraint failed: PartyType.name' + // ) + // }) + // + // it('Should enforce unique legal name when saving organization', async (): Promise => { + // const legalName = 'non_unique_value' + // const organization1: NonPersistedOrganization = { + // legalName, + // displayName: 'example_display_name', + // } + // + // const organizationEntity1: OrganizationEntity = organizationEntityFrom(organization1) + // const savedOrganization1: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity1, { + // transaction: true, + // }) + // + // expect(savedOrganization1).toBeDefined() + // + // const organization2: NonPersistedOrganization = { + // legalName, + // displayName: 'example_display_name', + // } + // + // const organizationEntity2: OrganizationEntity = organizationEntityFrom(organization2) + // await expect(dbConnection.getRepository(OrganizationEntity).save(organizationEntity2)).rejects.toThrowError( + // 'SQLITE_CONSTRAINT: UNIQUE constraint failed: BaseContact.legal_name' + // ) + // }) + // + // it('Should enforce unique legal name when saving organization', async (): Promise => { + // const legalName = 'example_legal_name' + // const organization1: NonPersistedOrganization = { + // legalName, + // displayName: 'example_display_name', + // } + // + // const organizationEntity1: OrganizationEntity = organizationEntityFrom(organization1) + // const savedOrganization1: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity1, { + // transaction: true, + // }) + // + // expect(savedOrganization1).toBeDefined() + // + // const organization2: NonPersistedOrganization = { + // legalName, + // displayName: 'example_display_name', + // } + // + // const organizationEntity2: OrganizationEntity = organizationEntityFrom(organization2) + // await expect(dbConnection.getRepository(OrganizationEntity).save(organizationEntity2)).rejects.toThrowError( + // 'SQLITE_CONSTRAINT: UNIQUE constraint failed: BaseContact.legal_name' + // ) + // }) + // + // it('Should save party relationship to database', async (): Promise => { + // const party1: NonPersistedParty = { + // uri: 'example1.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name1', + // }, + // contact: { + // firstName: 'example_first_name1', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity1: PartyEntity = partyEntityFrom(party1) + // const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { + // transaction: true, + // }) + // + // expect(savedParty1).toBeDefined() + // + // const party2: NonPersistedParty = { + // uri: 'example2.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name: 'example_name2', + // }, + // contact: { + // firstName: 'example_first_name2', + // middleName: 'example_middle_name2', + // lastName: 'example_last_name2', + // displayName: 'example_display_name2', + // }, + // } + // + // const partyEntity2: PartyEntity = partyEntityFrom(party2) + // const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { + // transaction: true, + // }) + // + // expect(savedParty2).toBeDefined() + // + // const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { + // transaction: true, + // }) + // + // // TODO check the relation field + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: partyEntity1.id }, + // }) + // + // expect(fromDb).toBeDefined() + // }) + // + // it('Should set last updated date when saving party relationship', async (): Promise => { + // const party1: NonPersistedParty = { + // uri: 'example1.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name1', + // }, + // contact: { + // firstName: 'example_first_name1', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity1: PartyEntity = partyEntityFrom(party1) + // const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { + // transaction: true, + // }) + // + // const party2: NonPersistedParty = { + // uri: 'example2.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name: 'example_name2', + // }, + // contact: { + // firstName: 'example_first_name2', + // middleName: 'example_middle_name2', + // lastName: 'example_last_name2', + // displayName: 'example_display_name2', + // }, + // } + // + // const partyEntity2: PartyEntity = partyEntityFrom(party2) + // const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { + // transaction: true, + // }) + // + // const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { + // transaction: true, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: partyEntity1.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.lastUpdatedAt).toBeDefined() + // }) + // + // it('Should set creation date when saving party relationship', async (): Promise => { + // const party1: NonPersistedParty = { + // uri: 'example1.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name1', + // }, + // contact: { + // firstName: 'example_first_name1', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity1: PartyEntity = partyEntityFrom(party1) + // const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { + // transaction: true, + // }) + // + // const party2: NonPersistedParty = { + // uri: 'example2.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name: 'example_name2', + // }, + // contact: { + // firstName: 'example_first_name2', + // middleName: 'example_middle_name2', + // lastName: 'example_last_name2', + // displayName: 'example_display_name2', + // }, + // } + // + // const partyEntity2: PartyEntity = partyEntityFrom(party2) + // const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { + // transaction: true, + // }) + // + // const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { + // transaction: true, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: partyEntity1.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.createdAt).toBeDefined() + // }) + // + // it('Should save bidirectional party relationships to database', async (): Promise => { + // const party1: NonPersistedParty = { + // uri: 'example1.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name1', + // }, + // contact: { + // firstName: 'example_first_name1', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity1: PartyEntity = partyEntityFrom(party1) + // const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { + // transaction: true, + // }) + // + // expect(savedParty1).toBeDefined() + // + // const party2: NonPersistedParty = { + // uri: 'example2.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name: 'example_name2', + // }, + // contact: { + // firstName: 'example_first_name2', + // middleName: 'example_middle_name2', + // lastName: 'example_last_name2', + // displayName: 'example_display_name2', + // }, + // } + // + // const partyEntity2: PartyEntity = partyEntityFrom(party2) + // const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { + // transaction: true, + // }) + // + // expect(savedParty2).toBeDefined() + // + // const relationship1: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // const savedRelationship1: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship1, { + // transaction: true, + // }) + // + // expect(savedRelationship1).toBeDefined() + // + // const relationship2: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty2.id, + // rightId: savedParty1.id, + // }) + // + // const savedRelationship2: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship2, { + // transaction: true, + // }) + // + // expect(savedRelationship2).toBeDefined() + // + // const fromDb: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).findOne({ + // where: { id: savedRelationship2.id }, + // }) + // + // expect(fromDb).toBeDefined() + // }) + // + // it('Should enforce unique owner combination for party relationship', async (): Promise => { + // const party1: NonPersistedParty = { + // uri: 'example1.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name1', + // }, + // contact: { + // firstName: 'example_first_name1', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity1: PartyEntity = partyEntityFrom(party1) + // const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { + // transaction: true, + // }) + // + // expect(savedParty1).toBeDefined() + // + // const party2: NonPersistedParty = { + // uri: 'example2.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name: 'example_name2', + // }, + // contact: { + // firstName: 'example_first_name2', + // middleName: 'example_middle_name2', + // lastName: 'example_last_name2', + // displayName: 'example_display_name2', + // }, + // } + // + // const partyEntity2: PartyEntity = partyEntityFrom(party2) + // const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { + // transaction: true, + // }) + // + // expect(savedParty2).toBeDefined() + // + // const relationship1: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // const savedRelationship1: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship1, { + // transaction: true, + // }) + // + // expect(savedRelationship1).toBeDefined() + // + // const relationship2: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // await expect(dbConnection.getRepository(PartyRelationshipEntity).save(relationship2)).rejects.toThrowError( + // 'SQLITE_CONSTRAINT: UNIQUE constraint failed: PartyRelationship.left_id, PartyRelationship.right_id' + // ) + // }) + // + // it('Should save party type to database', async (): Promise => { + // const partyType: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // } + // + // const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) + // const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) + // + // const fromDb: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).findOne({ + // where: { id: savedPartyType.id }, + // }) + // + // expect(fromDb).toBeDefined() + // }) + // + // it('Should save person to database', async (): Promise => { + // const person: NonPersistedNaturalPerson = { + // firstName: 'example_first_name', + // lastName: 'lastName2', + // displayName: 'displayName', + // } + // + // const personEntity: NaturalPersonEntity = naturalPersonEntityFrom(person) + // const savedPerson: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).save(personEntity, { + // transaction: true, + // }) + // + // const fromDb: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).findOne({ + // where: { id: savedPerson.id }, + // }) + // + // expect(fromDb).toBeDefined() + // }) + // + // it('Should set last updated date when saving person', async (): Promise => { + // const person: NonPersistedNaturalPerson = { + // firstName: 'example_first_name', + // lastName: 'lastName2', + // displayName: 'displayName', + // } + // + // const personEntity: NaturalPersonEntity = naturalPersonEntityFrom(person) + // const savedPerson: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).save(personEntity, { + // transaction: true, + // }) + // + // const fromDb: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).findOne({ + // where: { id: savedPerson.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.lastUpdatedAt).toBeDefined() + // }) + // + // it('Should set creation date when saving person', async (): Promise => { + // const person: NonPersistedNaturalPerson = { + // firstName: 'example_first_name', + // lastName: 'lastName2', + // displayName: 'displayName', + // } + // + // const personEntity: NaturalPersonEntity = naturalPersonEntityFrom(person) + // const savedPerson: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).save(personEntity, { + // transaction: true, + // }) + // + // const fromDb: NaturalPersonEntity | null = await dbConnection.getRepository(NaturalPersonEntity).findOne({ + // where: { id: savedPerson.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.createdAt).toBeDefined() + // }) + // + // it('Should save organization to database', async (): Promise => { + // const organization: NonPersistedOrganization = { + // legalName: 'example_legal_name', + // displayName: 'example_display_name', + // } + // + // const organizationEntity: OrganizationEntity = organizationEntityFrom(organization) + // const savedOrganization: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity, { + // transaction: true, + // }) + // + // const fromDb: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).findOne({ + // where: { id: savedOrganization.id }, + // }) + // + // expect(fromDb).toBeDefined() + // }) + // + // it('Should set last updated date when saving organization', async (): Promise => { + // const organization: NonPersistedOrganization = { + // legalName: 'example_legal_name', + // displayName: 'example_display_name', + // } + // + // const organizationEntity: OrganizationEntity = organizationEntityFrom(organization) + // const savedOrganization: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity, { + // transaction: true, + // }) + // + // const fromDb: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).findOne({ + // where: { id: savedOrganization.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.lastUpdatedAt).toBeDefined() + // }) + // + // it('Should set creation date when saving organization', async (): Promise => { + // const organization: NonPersistedOrganization = { + // legalName: 'example_legal_name', + // displayName: 'example_display_name', + // } + // + // const organizationEntity: OrganizationEntity = organizationEntityFrom(organization) + // const savedOrganization: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).save(organizationEntity, { + // transaction: true, + // }) + // + // const fromDb: OrganizationEntity | null = await dbConnection.getRepository(OrganizationEntity).findOne({ + // where: { id: savedOrganization.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.createdAt).toBeDefined() + // }) + // + // it('Should get party based on person information', async (): Promise => { + // const firstName = 'example_first_name' + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName, + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // await dbConnection.getRepository(PartyEntity).save(partyEntity, { + // transaction: true, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { + // contact: { + // firstName, + // } as FindOptionsWhere, //NaturalPersonEntity | OrganizationEntity + // }, + // }) + // + // expect(fromDb).toBeDefined() + // }) + // + // it('Should get party based on organization information', async (): Promise => { + // const legalName = 'example_legal_name' + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.ORGANIZATION, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // legalName, + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // await dbConnection.getRepository(PartyEntity).save(partyEntity, { + // transaction: true, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { + // contact: { + // legalName, + // } as FindOptionsWhere, //NaturalPersonEntity | OrganizationEntity + // }, + // }) + // + // expect(fromDb).toBeDefined() + // }) + // + // it("Should enforce unique party id's for relationship sides", async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // const savedParty: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity, { + // transaction: true, + // }) + // + // expect(savedParty).toBeDefined() + // + // const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty.id, + // rightId: savedParty.id, + // }) + // + // await expect(dbConnection.getRepository(PartyRelationshipEntity).save(relationship)).rejects.toThrowError( + // 'Cannot use the same id for both sides of the relationship' + // ) + // }) + // + // it('Should delete party relationship', async (): Promise => { + // const party1: NonPersistedParty = { + // uri: 'example1.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name1', + // }, + // contact: { + // firstName: 'example_first_name1', + // middleName: 'example_middle_name1', + // lastName: 'example_last_name1', + // displayName: 'example_display_name1', + // }, + // } + // + // const partyEntity1: PartyEntity = partyEntityFrom(party1) + // const savedParty1: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity1, { + // transaction: true, + // }) + // + // expect(savedParty1).toBeDefined() + // + // const party2: NonPersistedParty = { + // uri: 'example2.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', + // name: 'example_name2', + // }, + // contact: { + // firstName: 'example_first_name2', + // middleName: 'example_middle_name2', + // lastName: 'example_last_name2', + // displayName: 'example_display_name2', + // }, + // } + // + // const partyEntity2: PartyEntity = partyEntityFrom(party2) + // const savedParty2: PartyEntity = await dbConnection.getRepository(PartyEntity).save(partyEntity2, { + // transaction: true, + // }) + // + // expect(savedParty2).toBeDefined() + // + // const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({ + // leftId: savedParty1.id, + // rightId: savedParty2.id, + // }) + // + // const savedRelationship: PartyRelationshipEntity | null = await dbConnection.getRepository(PartyRelationshipEntity).save(relationship, { + // transaction: true, + // }) + // + // expect(savedRelationship).toBeDefined() + // + // await dbConnection.getRepository(PartyRelationshipEntity).delete({ id: savedRelationship.id }) + // + // await expect( + // await dbConnection.getRepository(PartyRelationshipEntity).findOne({ + // where: { id: savedRelationship.id }, + // }) + // ).toBeNull() + // }) + // + // it('Should delete party type', async (): Promise => { + // const partyType: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // } + // + // const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) + // const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) + // + // expect(savedPartyType).toBeDefined() + // + // await dbConnection.getRepository(PartyTypeEntity).delete({ id: savedPartyType.id }) + // + // await expect( + // await dbConnection.getRepository(PartyTypeEntity).findOne({ + // where: { id: savedPartyType.id }, + // }) + // ).toBeNull() + // }) + // + // it('Should not be able to remove party type when used by parties', async (): Promise => { + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // }, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // const savedParty: PartyEntity | null = await dbConnection.getRepository(PartyEntity).save(partyEntity, { + // transaction: true, + // }) + // + // expect(savedParty).toBeDefined() + // + // await expect(dbConnection.getRepository(PartyTypeEntity).delete({ id: savedParty.partyType.id })).rejects.toThrowError( + // 'FOREIGN KEY constraint failed' + // ) + // }) + // + // it('Should save party with existing party type', async (): Promise => { + // const partyType: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // } + // + // const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) + // const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) + // + // const party: NonPersistedParty = { + // uri: 'example.com', + // partyType: savedPartyType, + // contact: { + // firstName: 'example_first_name', + // middleName: 'example_middle_name', + // lastName: 'example_last_name', + // displayName: 'example_display_name', + // }, + // } + // + // const partyEntity: PartyEntity = partyEntityFrom(party) + // partyEntity.partyType = savedPartyType + // await dbConnection.getRepository(PartyEntity).save(partyEntity, { + // transaction: true, + // }) + // + // const fromDb: PartyEntity | null = await dbConnection.getRepository(PartyEntity).findOne({ + // where: { id: partyEntity.id }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.partyType).toBeDefined() + // expect(fromDb?.partyType.id).toEqual(savedPartyType.id) + // expect(fromDb?.partyType.type).toEqual(savedPartyType.type) + // expect(fromDb?.partyType.tenantId).toEqual(savedPartyType.tenantId) + // expect(fromDb?.partyType.name).toEqual(savedPartyType.name) + // }) + // + // it('Should not update creation date when saving party type', async (): Promise => { + // const partyType: NonPersistedPartyType = { + // type: PartyTypeEnum.NATURAL_PERSON, + // tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', + // name: 'example_name', + // } + // + // const partyTypeEntity: PartyTypeEntity = partyTypeEntityFrom(partyType) + // const savedPartyType: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).save(partyTypeEntity) + // await dbConnection.getRepository(PartyTypeEntity).save({ ...savedPartyType, type: PartyTypeEnum.ORGANIZATION }) + // + // const fromDb: PartyTypeEntity | null = await dbConnection.getRepository(PartyTypeEntity).findOne({ + // where: { + // type: PartyTypeEnum.ORGANIZATION, + // }, + // }) + // + // expect(fromDb).toBeDefined() + // expect(fromDb?.createdAt).toEqual(savedPartyType?.createdAt) + // }) }) diff --git a/packages/data-store/src/entities/contact/IdentityEntity.ts b/packages/data-store/src/entities/contact/IdentityEntity.ts index c81dcad19..72dccc41a 100644 --- a/packages/data-store/src/entities/contact/IdentityEntity.ts +++ b/packages/data-store/src/entities/contact/IdentityEntity.ts @@ -58,7 +58,7 @@ export class IdentityEntity extends BaseEntity { eager: true, nullable: false, }) - @JoinColumn({ name: 'metadata_id' }) + @JoinColumn({ name: 'metadata_id' }) // TODO check in db file metadata!: Array @CreateDateColumn({ name: 'created_at', nullable: false }) diff --git a/packages/data-store/src/entities/contact/OrganizationEntity.ts b/packages/data-store/src/entities/contact/OrganizationEntity.ts index e20a38ec7..a48e9d4b1 100644 --- a/packages/data-store/src/entities/contact/OrganizationEntity.ts +++ b/packages/data-store/src/entities/contact/OrganizationEntity.ts @@ -16,8 +16,8 @@ export class OrganizationEntity extends BaseContactEntity { displayName!: string @OneToOne(() => PartyEntity) - @JoinColumn({ name: 'contact_id' }) - contact!: PartyEntity + @JoinColumn({ name: 'party_id' }) + party!: PartyEntity @BeforeInsert() @BeforeUpdate() diff --git a/packages/data-store/src/entities/contact/PartyEntity.ts b/packages/data-store/src/entities/contact/PartyEntity.ts index db7adc9de..fe41d1572 100644 --- a/packages/data-store/src/entities/contact/PartyEntity.ts +++ b/packages/data-store/src/entities/contact/PartyEntity.ts @@ -35,7 +35,7 @@ export class PartyEntity extends BaseEntity { eager: true, nullable: false, }) - @JoinColumn({ name: 'identity_id' }) + @JoinColumn({ name: 'identity_id' }) // TODO check this in the db file identities!: Array @OneToMany(() => ElectronicAddressEntity, (electronicAddress: ElectronicAddressEntity) => electronicAddress.party, { @@ -44,7 +44,7 @@ export class PartyEntity extends BaseEntity { eager: true, nullable: false, }) - @JoinColumn({ name: 'electronic_address_id' }) + @JoinColumn({ name: 'electronic_address_id' }) // TODO check this in the db file electronicAddresses!: Array @ManyToOne(() => PartyTypeEntity, (contactType: PartyTypeEntity) => contactType.parties, { diff --git a/packages/data-store/src/migrations/generic/index.ts b/packages/data-store/src/migrations/generic/index.ts index cb9034231..f81e36086 100644 --- a/packages/data-store/src/migrations/generic/index.ts +++ b/packages/data-store/src/migrations/generic/index.ts @@ -1,6 +1,6 @@ import { CreateContacts1659463079429 } from './1-CreateContacts' import { CreateContacts1690925872318 } from './2-CreateContacts' -import { CreateIssuanceBranding1659463079429 } from './1-CreateIssuanceBranding' +//import { CreateIssuanceBranding1659463079429 } from './1-CreateIssuanceBranding' /** * The migrations array that SHOULD be used when initializing a TypeORM database connection. @@ -9,4 +9,4 @@ import { CreateIssuanceBranding1659463079429 } from './1-CreateIssuanceBranding' * * @public */ -export const DataStoreMigrations = [CreateContacts1659463079429, CreateContacts1690925872318, CreateIssuanceBranding1659463079429] +export const DataStoreMigrations = [CreateContacts1659463079429, CreateContacts1690925872318] //CreateIssuanceBranding1659463079429 diff --git a/packages/data-store/src/migrations/sqlite/1690925872693-CreateContacts.ts b/packages/data-store/src/migrations/sqlite/1690925872693-CreateContacts.ts index ccfe15f81..a68dd5322 100644 --- a/packages/data-store/src/migrations/sqlite/1690925872693-CreateContacts.ts +++ b/packages/data-store/src/migrations/sqlite/1690925872693-CreateContacts.ts @@ -4,160 +4,244 @@ export class CreateContacts1690925872693 implements MigrationInterface { name = 'CreateContacts1690925872693' public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP INDEX "IDX_BaseConfigEntity_type"`) - await queryRunner.query( - `CREATE TABLE "temporary_BaseConfigEntity" ("id" varchar PRIMARY KEY NOT NULL, "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "redirect_url" text, "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "identifier" varchar(255), "session_id" varchar(255), "type" varchar NOT NULL, "connectionId" varchar, CONSTRAINT "REL_BaseConfig_connectionId" UNIQUE ("connectionId"))` - ) - await queryRunner.query( - `INSERT INTO "temporary_BaseConfigEntity"("id", "client_id", "client_secret", "scopes", "issuer", "redirect_url", "dangerously_allow_insecure_http_requests", "client_auth_method", "identifier", "session_id", "type", "connectionId") SELECT "id", "client_id", "client_secret", "scopes", "issuer", "redirect_url", "dangerously_allow_insecure_http_requests", "client_auth_method", "identifier", "session_id", "type", "connectionId" FROM "BaseConfigEntity"` - ) - await queryRunner.query(`DROP TABLE "BaseConfigEntity"`) - await queryRunner.query(`ALTER TABLE "temporary_BaseConfigEntity" RENAME TO "BaseConfigEntity"`) - await queryRunner.query(`CREATE INDEX "IDX_BaseConfigEntity_type" ON "BaseConfigEntity" ("type")`) - await queryRunner.query( - `CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identityId" varchar, CONSTRAINT "REL_CorrelationIdentifier_identityId" UNIQUE ("identityId"), CONSTRAINT "UQ_Correlation_id" UNIQUE ("correlation_id"))` - ) - await queryRunner.query( - `INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identityId") SELECT "id", "type", "correlation_id", "identityId" FROM "CorrelationIdentifier"` - ) + await queryRunner.query(`CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identityId" varchar, CONSTRAINT "REL_28945c1d57c5feee1d5d1f5451" UNIQUE ("identityId"), CONSTRAINT "UQ_775cbf83c248bc73c42aef55664" UNIQUE ("correlation_id"))`) + await queryRunner.query(`INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identityId") SELECT "id", "type", "correlation_id", "identityId" FROM "CorrelationIdentifier"`) await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`) await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`) - await queryRunner.query( - `CREATE TABLE "temporary_IdentityMetadata" ("id" varchar PRIMARY KEY NOT NULL, "label" varchar(255) NOT NULL, "value" varchar(255) NOT NULL, "identityId" varchar)` - ) - await queryRunner.query( - `INSERT INTO "temporary_IdentityMetadata"("id", "label", "value", "identityId") SELECT "id", "label", "value", "identityId" FROM "IdentityMetadata"` - ) - await queryRunner.query(`DROP TABLE "IdentityMetadata"`) - await queryRunner.query(`ALTER TABLE "temporary_IdentityMetadata" RENAME TO "IdentityMetadata"`) - await queryRunner.query( - `CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Alias" UNIQUE ("alias"))` - ) - await queryRunner.query( - `INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"` - ) + await queryRunner.query(`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_cbeaf6b68b6dbc9eb8dc3503499" UNIQUE ("alias"))`) + await queryRunner.query(`INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"`) await queryRunner.query(`DROP TABLE "Identity"`) await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`) - await queryRunner.query( - `CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identityId" varchar, CONSTRAINT "REL_Connection_identityId" UNIQUE ("identityId"))` - ) + await queryRunner.query(`CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identityId" varchar, CONSTRAINT "REL_fff3668c112a6863bb8c37519a" UNIQUE ("identityId"))`) await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identityId") SELECT "id", "type", "identityId" FROM "Connection"`) await queryRunner.query(`DROP TABLE "Connection"`) await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`) - await queryRunner.query(`DROP INDEX "IDX_BaseConfigEntity_type"`) - await queryRunner.query( - `CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Alias" UNIQUE ("alias"))` - ) - await queryRunner.query( - `INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"` - ) - await queryRunner.query(`DROP TABLE "Identity"`) - await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`) - await queryRunner.query( - `CREATE TABLE "ContactType" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('person','organization') ) NOT NULL, "name" varchar(255) NOT NULL, "description" varchar(255), "tenantId" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_2229e0d8c1e6817efcc982a6dde" UNIQUE ("name"))` - ) - await queryRunner.query(`CREATE UNIQUE INDEX "IDX_1a1fa2aa0a56649427e427a41f" ON "ContactType" ("type", "tenantId")`) - await queryRunner.query( - `CREATE TABLE "ContactOwner" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "firstName" varchar(255), "middleName" varchar(255), "lastName" varchar(255), "displayName" varchar(255), "legalName" varchar(255), "type" varchar NOT NULL, "contactId" varchar, CONSTRAINT "UQ_9177af8a51a2a0598d3a8c68e1e" UNIQUE ("displayName"), CONSTRAINT "UQ_91bf22d2597ff429ece6ae807aa" UNIQUE ("legalName"), CONSTRAINT "UQ_9177af8a51a2a0598d3a8c68e1e" UNIQUE ("displayName"), CONSTRAINT "REL_26ce21b29da1426fa1198b947e" UNIQUE ("contactId"))` - ) - await queryRunner.query(`CREATE INDEX "IDX_e50c368daf85e7ae54585b0f7b" ON "ContactOwner" ("type")`) - await queryRunner.query( - `CREATE TABLE "ContactRelationship" ("id" varchar PRIMARY KEY NOT NULL, "leftId" varchar NOT NULL, "rightId" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))` - ) - await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ContactRelationshipEntity_left_right" ON "ContactRelationship" ("leftId", "rightId")`) - await queryRunner.query( - `CREATE TABLE "temporary_Contact" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))` - ) - await queryRunner.query( - `INSERT INTO "temporary_Contact"("id", "uri", "created_at", "last_updated_at") SELECT "id", "uri", "created_at", "last_updated_at" FROM "Contact"` - ) - await queryRunner.query(`DROP TABLE "Contact"`) - await queryRunner.query(`ALTER TABLE "temporary_Contact" RENAME TO "Contact"`) - await queryRunner.query( - `CREATE TABLE "temporary_Contact" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactTypeId" varchar NOT NULL)` - ) - await queryRunner.query( - `INSERT INTO "temporary_Contact"("id", "uri", "created_at", "last_updated_at") SELECT "id", "uri", "created_at", "last_updated_at" FROM "Contact"` - ) - await queryRunner.query(`DROP TABLE "Contact"`) - await queryRunner.query(`ALTER TABLE "temporary_Contact" RENAME TO "Contact"`) - await queryRunner.query( - `CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Alias" UNIQUE ("alias"))` - ) - await queryRunner.query( - `INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"` - ) + await queryRunner.query(`CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identity_id" varchar, CONSTRAINT "REL_28945c1d57c5feee1d5d1f5451" UNIQUE ("identity_id"), CONSTRAINT "UQ_775cbf83c248bc73c42aef55664" UNIQUE ("correlation_id"))`) + await queryRunner.query(`INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identity_id") SELECT "id", "type", "correlation_id", "identityId" FROM "CorrelationIdentifier"`) + await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`) + await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`) + await queryRunner.query(`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "UQ_cbeaf6b68b6dbc9eb8dc3503499" UNIQUE ("alias"))`) + await queryRunner.query(`INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "partyId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"`) await queryRunner.query(`DROP TABLE "Identity"`) await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`) - await queryRunner.query(`CREATE INDEX "IDX_228953a09ee91bbac6e28b7345" ON "BaseConfigEntity" ("type")`) - await queryRunner.query(`DROP INDEX "IDX_228953a09ee91bbac6e28b7345"`) - await queryRunner.query( - `CREATE TABLE "temporary_BaseConfigEntity" ("id" varchar PRIMARY KEY NOT NULL, "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "redirect_url" text, "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "identifier" varchar(255), "session_id" varchar(255), "type" varchar NOT NULL, "connectionId" varchar, CONSTRAINT "REL_BaseConfig_connectionId" UNIQUE ("connectionId"), CONSTRAINT "FK_0ab3b33e0a87e1706025e63d8a9" FOREIGN KEY ("connectionId") REFERENCES "Connection" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` - ) - await queryRunner.query( - `INSERT INTO "temporary_BaseConfigEntity"("id", "client_id", "client_secret", "scopes", "issuer", "redirect_url", "dangerously_allow_insecure_http_requests", "client_auth_method", "identifier", "session_id", "type", "connectionId") SELECT "id", "client_id", "client_secret", "scopes", "issuer", "redirect_url", "dangerously_allow_insecure_http_requests", "client_auth_method", "identifier", "session_id", "type", "connectionId" FROM "BaseConfigEntity"` - ) - await queryRunner.query(`DROP TABLE "BaseConfigEntity"`) - await queryRunner.query(`ALTER TABLE "temporary_BaseConfigEntity" RENAME TO "BaseConfigEntity"`) - await queryRunner.query(`CREATE INDEX "IDX_228953a09ee91bbac6e28b7345" ON "BaseConfigEntity" ("type")`) - await queryRunner.query( - `CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identityId" varchar, CONSTRAINT "REL_CorrelationIdentifier_identityId" UNIQUE ("identityId"), CONSTRAINT "UQ_Correlation_id" UNIQUE ("correlation_id"), CONSTRAINT "FK_28945c1d57c5feee1d5d1f54510" FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` - ) - await queryRunner.query( - `INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identityId") SELECT "id", "type", "correlation_id", "identityId" FROM "CorrelationIdentifier"` - ) + await queryRunner.query(`CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identity_id" varchar, CONSTRAINT "REL_fff3668c112a6863bb8c37519a" UNIQUE ("identity_id"))`) + await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identity_id") SELECT "id", "type", "identityId" FROM "Connection"`) + await queryRunner.query(`DROP TABLE "Connection"`) + await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`) + await queryRunner.query(`CREATE TABLE "PartyType" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('naturalPerson','organization') ) NOT NULL, "name" varchar(255) NOT NULL, "description" varchar(255), "tenant_id" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_06658931a9c40b5c1f7371210a7" UNIQUE ("name"))`) + await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyTypeEntity_type_tenantId" ON "PartyType" ("type", "tenant_id")`) + await queryRunner.query(`CREATE TABLE "BaseContact" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "legal_name" varchar(255), "display_name" varchar(255), "first_name" varchar(255), "middle_name" varchar(255), "last_name" varchar(255), "type" varchar NOT NULL, "party_id" varchar, CONSTRAINT "UQ_b8c8005251433839dfc2babf9f8" UNIQUE ("legal_name"), CONSTRAINT "REL_be0b2a601d6a71b07e2a8a5b61" UNIQUE ("party_id"))`) + await queryRunner.query(`CREATE INDEX "IDX_d265e69d45aa55a9e197f5e626" ON "BaseContact" ("type")`) + await queryRunner.query(`CREATE TABLE "PartyRelationship" ("id" varchar PRIMARY KEY NOT NULL, "left_id" varchar NOT NULL, "right_id" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`) + await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyRelationshipEntity_left_right" ON "PartyRelationship" ("left_id", "right_id")`) + await queryRunner.query(`CREATE TABLE "ElectronicAddress" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar(255) NOT NULL, "electronic_address" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar)`) + await queryRunner.query(`CREATE TABLE "Party" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "party_type_id" varchar NOT NULL)`) + await queryRunner.query(`CREATE TABLE "BaseConfig" ("id" varchar PRIMARY KEY NOT NULL, "identifier" varchar(255), "redirect_url" varchar(255), "session_id" varchar(255), "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "type" varchar NOT NULL, "connection_id" varchar, CONSTRAINT "REL_4b10e0398e0bc003b479a21f53" UNIQUE ("connection_id"))`) + await queryRunner.query(`CREATE INDEX "IDX_5624e2253276217cf609b044b1" ON "BaseConfig" ("type")`) + await queryRunner.query(`CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identity_id" varchar, CONSTRAINT "REL_28945c1d57c5feee1d5d1f5451" UNIQUE ("identity_id"), CONSTRAINT "UQ_775cbf83c248bc73c42aef55664" UNIQUE ("correlation_id"), CONSTRAINT "FK_d98b8f355649e9d090ee2a915ca" FOREIGN KEY ("identity_id") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`) + await queryRunner.query(`INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identity_id") SELECT "id", "type", "correlation_id", "identity_id" FROM "CorrelationIdentifier"`) await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`) await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`) - await queryRunner.query( - `CREATE TABLE "temporary_IdentityMetadata" ("id" varchar PRIMARY KEY NOT NULL, "label" varchar(255) NOT NULL, "value" varchar(255) NOT NULL, "identityId" varchar, CONSTRAINT "FK_e22568cc3d201c0131b87186117" FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` - ) - await queryRunner.query( - `INSERT INTO "temporary_IdentityMetadata"("id", "label", "value", "identityId") SELECT "id", "label", "value", "identityId" FROM "IdentityMetadata"` - ) - await queryRunner.query(`DROP TABLE "IdentityMetadata"`) - await queryRunner.query(`ALTER TABLE "temporary_IdentityMetadata" RENAME TO "IdentityMetadata"`) - await queryRunner.query(`DROP INDEX "IDX_e50c368daf85e7ae54585b0f7b"`) - await queryRunner.query( - `CREATE TABLE "temporary_ContactOwner" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "firstName" varchar(255), "middleName" varchar(255), "lastName" varchar(255), "displayName" varchar(255), "legalName" varchar(255), "type" varchar NOT NULL, "contactId" varchar, CONSTRAINT "UQ_9177af8a51a2a0598d3a8c68e1e" UNIQUE ("displayName"), CONSTRAINT "UQ_91bf22d2597ff429ece6ae807aa" UNIQUE ("legalName"), CONSTRAINT "UQ_9177af8a51a2a0598d3a8c68e1e" UNIQUE ("displayName"), CONSTRAINT "REL_26ce21b29da1426fa1198b947e" UNIQUE ("contactId"), CONSTRAINT "FK_26ce21b29da1426fa1198b947e1" FOREIGN KEY ("contactId") REFERENCES "Contact" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` - ) - await queryRunner.query( - `INSERT INTO "temporary_ContactOwner"("id", "created_at", "last_updated_at", "firstName", "middleName", "lastName", "displayName", "legalName", "type", "contactId") SELECT "id", "created_at", "last_updated_at", "firstName", "middleName", "lastName", "displayName", "legalName", "type", "contactId" FROM "ContactOwner"` - ) - await queryRunner.query(`DROP TABLE "ContactOwner"`) - await queryRunner.query(`ALTER TABLE "temporary_ContactOwner" RENAME TO "ContactOwner"`) - await queryRunner.query(`CREATE INDEX "IDX_e50c368daf85e7ae54585b0f7b" ON "ContactOwner" ("type")`) - await queryRunner.query(`DROP INDEX "IDX_ContactRelationshipEntity_left_right"`) - await queryRunner.query( - `CREATE TABLE "temporary_ContactRelationship" ("id" varchar PRIMARY KEY NOT NULL, "leftId" varchar NOT NULL, "rightId" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_24a7bc0595cc5da51c91e1bee62" FOREIGN KEY ("leftId") REFERENCES "Contact" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_e673c9f78f3c7670a75c0ea7710" FOREIGN KEY ("rightId") REFERENCES "Contact" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` - ) - await queryRunner.query( - `INSERT INTO "temporary_ContactRelationship"("id", "leftId", "rightId", "created_at", "last_updated_at") SELECT "id", "leftId", "rightId", "created_at", "last_updated_at" FROM "ContactRelationship"` - ) - await queryRunner.query(`DROP TABLE "ContactRelationship"`) - await queryRunner.query(`ALTER TABLE "temporary_ContactRelationship" RENAME TO "ContactRelationship"`) - await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ContactRelationshipEntity_left_right" ON "ContactRelationship" ("leftId", "rightId")`) - await queryRunner.query( - `CREATE TABLE "temporary_Contact" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactTypeId" varchar NOT NULL, CONSTRAINT "FK_a992c5cdc48d0bc105d0338f982" FOREIGN KEY ("contactTypeId") REFERENCES "ContactType" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)` - ) - await queryRunner.query( - `INSERT INTO "temporary_Contact"("id", "uri", "created_at", "last_updated_at", "contactTypeId") SELECT "id", "uri", "created_at", "last_updated_at", "contactTypeId" FROM "Contact"` - ) - await queryRunner.query(`DROP TABLE "Contact"`) - await queryRunner.query(`ALTER TABLE "temporary_Contact" RENAME TO "Contact"`) - await queryRunner.query( - `CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Alias" UNIQUE ("alias"), CONSTRAINT "FK_70ac2a54e2041b7914613204e3d" FOREIGN KEY ("contactId") REFERENCES "Contact" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` - ) - await queryRunner.query( - `INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"` - ) + await queryRunner.query(`DROP INDEX "IDX_d265e69d45aa55a9e197f5e626"`) + await queryRunner.query(`CREATE TABLE "temporary_BaseContact" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "legal_name" varchar(255), "display_name" varchar(255), "first_name" varchar(255), "middle_name" varchar(255), "last_name" varchar(255), "type" varchar NOT NULL, "party_id" varchar, CONSTRAINT "UQ_b8c8005251433839dfc2babf9f8" UNIQUE ("legal_name"), CONSTRAINT "REL_be0b2a601d6a71b07e2a8a5b61" UNIQUE ("party_id"), CONSTRAINT "FK_be0b2a601d6a71b07e2a8a5b61e" FOREIGN KEY ("party_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`) + await queryRunner.query(`INSERT INTO "temporary_BaseContact"("id", "created_at", "last_updated_at", "legal_name", "display_name", "first_name", "middle_name", "last_name", "type", "party_id") SELECT "id", "created_at", "last_updated_at", "legal_name", "display_name", "first_name", "middle_name", "last_name", "type", "party_id" FROM "BaseContact"`) + await queryRunner.query(`DROP TABLE "BaseContact"`) + await queryRunner.query(`ALTER TABLE "temporary_BaseContact" RENAME TO "BaseContact"`) + await queryRunner.query(`CREATE INDEX "IDX_d265e69d45aa55a9e197f5e626" ON "BaseContact" ("type")`) + await queryRunner.query(`DROP INDEX "IDX_PartyRelationshipEntity_left_right"`) + await queryRunner.query(`CREATE TABLE "temporary_PartyRelationship" ("id" varchar PRIMARY KEY NOT NULL, "left_id" varchar NOT NULL, "right_id" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_c3db1bd42ed96c5164b2e6276bf" FOREIGN KEY ("left_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_f366006d2ad5adbe3632277f1c0" FOREIGN KEY ("right_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`) + await queryRunner.query(`INSERT INTO "temporary_PartyRelationship"("id", "left_id", "right_id", "created_at", "last_updated_at") SELECT "id", "left_id", "right_id", "created_at", "last_updated_at" FROM "PartyRelationship"`) + await queryRunner.query(`DROP TABLE "PartyRelationship"`) + await queryRunner.query(`ALTER TABLE "temporary_PartyRelationship" RENAME TO "PartyRelationship"`) + await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyRelationshipEntity_left_right" ON "PartyRelationship" ("left_id", "right_id")`) + await queryRunner.query(`CREATE TABLE "temporary_ElectronicAddress" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar(255) NOT NULL, "electronic_address" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "FK_672ac311680d9c366405bb5737c" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`) + await queryRunner.query(`INSERT INTO "temporary_ElectronicAddress"("id", "type", "electronic_address", "created_at", "last_updated_at", "partyId") SELECT "id", "type", "electronic_address", "created_at", "last_updated_at", "partyId" FROM "ElectronicAddress"`) + await queryRunner.query(`DROP TABLE "ElectronicAddress"`) + await queryRunner.query(`ALTER TABLE "temporary_ElectronicAddress" RENAME TO "ElectronicAddress"`) + await queryRunner.query(`CREATE TABLE "temporary_Party" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "party_type_id" varchar NOT NULL, CONSTRAINT "FK_d6b87c0830068c6d396a501e3d1" FOREIGN KEY ("party_type_id") REFERENCES "PartyType" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`) + await queryRunner.query(`INSERT INTO "temporary_Party"("id", "uri", "created_at", "last_updated_at", "party_type_id") SELECT "id", "uri", "created_at", "last_updated_at", "party_type_id" FROM "Party"`) + await queryRunner.query(`DROP TABLE "Party"`) + await queryRunner.query(`ALTER TABLE "temporary_Party" RENAME TO "Party"`) + await queryRunner.query(`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "UQ_cbeaf6b68b6dbc9eb8dc3503499" UNIQUE ("alias"), CONSTRAINT "FK_916e4ef6ee2f24c5c88bdc9dfbb" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`) + await queryRunner.query(`INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "partyId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "partyId" FROM "Identity"`) await queryRunner.query(`DROP TABLE "Identity"`) await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`) - await queryRunner.query( - `CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identityId" varchar, CONSTRAINT "REL_Connection_identityId" UNIQUE ("identityId"), CONSTRAINT "FK_fff3668c112a6863bb8c37519a0" FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` - ) - await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identityId") SELECT "id", "type", "identityId" FROM "Connection"`) + await queryRunner.query(`CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identity_id" varchar, CONSTRAINT "REL_fff3668c112a6863bb8c37519a" UNIQUE ("identity_id"), CONSTRAINT "FK_360ccf2d714878339680a197d26" FOREIGN KEY ("identity_id") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`) + await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identity_id") SELECT "id", "type", "identity_id" FROM "Connection"`) await queryRunner.query(`DROP TABLE "Connection"`) await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`) + await queryRunner.query(`DROP INDEX "IDX_5624e2253276217cf609b044b1"`) + await queryRunner.query(`CREATE TABLE "temporary_BaseConfig" ("id" varchar PRIMARY KEY NOT NULL, "identifier" varchar(255), "redirect_url" varchar(255), "session_id" varchar(255), "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "type" varchar NOT NULL, "connection_id" varchar, CONSTRAINT "REL_4b10e0398e0bc003b479a21f53" UNIQUE ("connection_id"), CONSTRAINT "FK_4b10e0398e0bc003b479a21f53e" FOREIGN KEY ("connection_id") REFERENCES "Connection" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`) + await queryRunner.query(`INSERT INTO "temporary_BaseConfig"("id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id") SELECT "id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id" FROM "BaseConfig"`) + await queryRunner.query(`DROP TABLE "BaseConfig"`) + await queryRunner.query(`ALTER TABLE "temporary_BaseConfig" RENAME TO "BaseConfig"`) + await queryRunner.query(`CREATE INDEX "IDX_5624e2253276217cf609b044b1" ON "BaseConfig" ("type")`) + + // migrate existing data + await queryRunner.query(`INSERT INTO "BaseConfig"("id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id") SELECT "id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id" FROM "BaseConfigEntity"`) + await queryRunner.query(`DROP TABLE "BaseConfigEntity"`) + await queryRunner.query(`INSERT INTO "PartyType"(id, type, name, description, tenant_id, created_at, last_updated_at) VALUES ('3875c12e-fdaa-4ef6-a340-c936e054b627', 'organization', 'Sphereon_default_type', 'sphereon_default_organization', '95e09cfc-c974-4174-86aa-7bf1d5251fb4', datetime('now'), datetime('now'))`) + await queryRunner.query(`INSERT INTO "Party"(id, uri, created_at, last_updated_at, party_type_id) SELECT id, uri, created_at, last_updated_at, '3875c12e-fdaa-4ef6-a340-c936e054b627' FROM Contact`) + await queryRunner.query(`INSERT INTO "BaseContact"(id, legal_name, display_name, party_id, created_at, last_updated_at, type) SELECT id, name, alias, id, created_at, last_updated_at, 'Organization' FROM Contact`) + await queryRunner.query(`DROP TABLE "Contact"`) + + + + + // await queryRunner.query(`DROP INDEX "IDX_BaseConfigEntity_type"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_BaseConfigEntity" ("id" varchar PRIMARY KEY NOT NULL, "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "redirect_url" text, "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "identifier" varchar(255), "session_id" varchar(255), "type" varchar NOT NULL, "connectionId" varchar, CONSTRAINT "REL_BaseConfig_connectionId" UNIQUE ("connectionId"))` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_BaseConfigEntity"("id", "client_id", "client_secret", "scopes", "issuer", "redirect_url", "dangerously_allow_insecure_http_requests", "client_auth_method", "identifier", "session_id", "type", "connectionId") SELECT "id", "client_id", "client_secret", "scopes", "issuer", "redirect_url", "dangerously_allow_insecure_http_requests", "client_auth_method", "identifier", "session_id", "type", "connectionId" FROM "BaseConfigEntity"` + // ) + // await queryRunner.query(`DROP TABLE "BaseConfigEntity"`) + // await queryRunner.query(`ALTER TABLE "temporary_BaseConfigEntity" RENAME TO "BaseConfigEntity"`) + // await queryRunner.query(`CREATE INDEX "IDX_BaseConfigEntity_type" ON "BaseConfigEntity" ("type")`) + // await queryRunner.query( + // `CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identityId" varchar, CONSTRAINT "REL_CorrelationIdentifier_identityId" UNIQUE ("identityId"), CONSTRAINT "UQ_Correlation_id" UNIQUE ("correlation_id"))` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identityId") SELECT "id", "type", "correlation_id", "identityId" FROM "CorrelationIdentifier"` + // ) + // await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`) + // await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_IdentityMetadata" ("id" varchar PRIMARY KEY NOT NULL, "label" varchar(255) NOT NULL, "value" varchar(255) NOT NULL, "identityId" varchar)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_IdentityMetadata"("id", "label", "value", "identityId") SELECT "id", "label", "value", "identityId" FROM "IdentityMetadata"` + // ) + // await queryRunner.query(`DROP TABLE "IdentityMetadata"`) + // await queryRunner.query(`ALTER TABLE "temporary_IdentityMetadata" RENAME TO "IdentityMetadata"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Alias" UNIQUE ("alias"))` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"` + // ) + // await queryRunner.query(`DROP TABLE "Identity"`) + // await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identityId" varchar, CONSTRAINT "REL_Connection_identityId" UNIQUE ("identityId"))` + // ) + // await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identityId") SELECT "id", "type", "identityId" FROM "Connection"`) + // await queryRunner.query(`DROP TABLE "Connection"`) + // await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`) + // await queryRunner.query(`DROP INDEX "IDX_BaseConfigEntity_type"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Alias" UNIQUE ("alias"))` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"` + // ) + // await queryRunner.query(`DROP TABLE "Identity"`) + // await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`) + // await queryRunner.query( + // `CREATE TABLE "ContactType" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('person','organization') ) NOT NULL, "name" varchar(255) NOT NULL, "description" varchar(255), "tenantId" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_2229e0d8c1e6817efcc982a6dde" UNIQUE ("name"))` + // ) + // await queryRunner.query(`CREATE UNIQUE INDEX "IDX_1a1fa2aa0a56649427e427a41f" ON "ContactType" ("type", "tenantId")`) + // await queryRunner.query( + // `CREATE TABLE "ContactOwner" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "firstName" varchar(255), "middleName" varchar(255), "lastName" varchar(255), "displayName" varchar(255), "legalName" varchar(255), "type" varchar NOT NULL, "contactId" varchar, CONSTRAINT "UQ_9177af8a51a2a0598d3a8c68e1e" UNIQUE ("displayName"), CONSTRAINT "UQ_91bf22d2597ff429ece6ae807aa" UNIQUE ("legalName"), CONSTRAINT "UQ_9177af8a51a2a0598d3a8c68e1e" UNIQUE ("displayName"), CONSTRAINT "REL_26ce21b29da1426fa1198b947e" UNIQUE ("contactId"))` + // ) + // await queryRunner.query(`CREATE INDEX "IDX_e50c368daf85e7ae54585b0f7b" ON "ContactOwner" ("type")`) + // await queryRunner.query( + // `CREATE TABLE "ContactRelationship" ("id" varchar PRIMARY KEY NOT NULL, "leftId" varchar NOT NULL, "rightId" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))` + // ) + // await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ContactRelationshipEntity_left_right" ON "ContactRelationship" ("leftId", "rightId")`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Contact" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_Contact"("id", "uri", "created_at", "last_updated_at") SELECT "id", "uri", "created_at", "last_updated_at" FROM "Contact"` + // ) + // await queryRunner.query(`DROP TABLE "Contact"`) + // await queryRunner.query(`ALTER TABLE "temporary_Contact" RENAME TO "Contact"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Contact" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactTypeId" varchar NOT NULL)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_Contact"("id", "uri", "created_at", "last_updated_at") SELECT "id", "uri", "created_at", "last_updated_at" FROM "Contact"` + // ) + // await queryRunner.query(`DROP TABLE "Contact"`) + // await queryRunner.query(`ALTER TABLE "temporary_Contact" RENAME TO "Contact"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Alias" UNIQUE ("alias"))` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"` + // ) + // await queryRunner.query(`DROP TABLE "Identity"`) + // await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`) + // await queryRunner.query(`CREATE INDEX "IDX_228953a09ee91bbac6e28b7345" ON "BaseConfigEntity" ("type")`) + // await queryRunner.query(`DROP INDEX "IDX_228953a09ee91bbac6e28b7345"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_BaseConfigEntity" ("id" varchar PRIMARY KEY NOT NULL, "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "redirect_url" text, "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "identifier" varchar(255), "session_id" varchar(255), "type" varchar NOT NULL, "connectionId" varchar, CONSTRAINT "REL_BaseConfig_connectionId" UNIQUE ("connectionId"), CONSTRAINT "FK_0ab3b33e0a87e1706025e63d8a9" FOREIGN KEY ("connectionId") REFERENCES "Connection" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_BaseConfigEntity"("id", "client_id", "client_secret", "scopes", "issuer", "redirect_url", "dangerously_allow_insecure_http_requests", "client_auth_method", "identifier", "session_id", "type", "connectionId") SELECT "id", "client_id", "client_secret", "scopes", "issuer", "redirect_url", "dangerously_allow_insecure_http_requests", "client_auth_method", "identifier", "session_id", "type", "connectionId" FROM "BaseConfigEntity"` + // ) + // await queryRunner.query(`DROP TABLE "BaseConfigEntity"`) + // await queryRunner.query(`ALTER TABLE "temporary_BaseConfigEntity" RENAME TO "BaseConfigEntity"`) + // await queryRunner.query(`CREATE INDEX "IDX_228953a09ee91bbac6e28b7345" ON "BaseConfigEntity" ("type")`) + // await queryRunner.query( + // `CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identityId" varchar, CONSTRAINT "REL_CorrelationIdentifier_identityId" UNIQUE ("identityId"), CONSTRAINT "UQ_Correlation_id" UNIQUE ("correlation_id"), CONSTRAINT "FK_28945c1d57c5feee1d5d1f54510" FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identityId") SELECT "id", "type", "correlation_id", "identityId" FROM "CorrelationIdentifier"` + // ) + // await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`) + // await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_IdentityMetadata" ("id" varchar PRIMARY KEY NOT NULL, "label" varchar(255) NOT NULL, "value" varchar(255) NOT NULL, "identityId" varchar, CONSTRAINT "FK_e22568cc3d201c0131b87186117" FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_IdentityMetadata"("id", "label", "value", "identityId") SELECT "id", "label", "value", "identityId" FROM "IdentityMetadata"` + // ) + // await queryRunner.query(`DROP TABLE "IdentityMetadata"`) + // await queryRunner.query(`ALTER TABLE "temporary_IdentityMetadata" RENAME TO "IdentityMetadata"`) + // await queryRunner.query(`DROP INDEX "IDX_e50c368daf85e7ae54585b0f7b"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_ContactOwner" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "firstName" varchar(255), "middleName" varchar(255), "lastName" varchar(255), "displayName" varchar(255), "legalName" varchar(255), "type" varchar NOT NULL, "contactId" varchar, CONSTRAINT "UQ_9177af8a51a2a0598d3a8c68e1e" UNIQUE ("displayName"), CONSTRAINT "UQ_91bf22d2597ff429ece6ae807aa" UNIQUE ("legalName"), CONSTRAINT "UQ_9177af8a51a2a0598d3a8c68e1e" UNIQUE ("displayName"), CONSTRAINT "REL_26ce21b29da1426fa1198b947e" UNIQUE ("contactId"), CONSTRAINT "FK_26ce21b29da1426fa1198b947e1" FOREIGN KEY ("contactId") REFERENCES "Contact" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_ContactOwner"("id", "created_at", "last_updated_at", "firstName", "middleName", "lastName", "displayName", "legalName", "type", "contactId") SELECT "id", "created_at", "last_updated_at", "firstName", "middleName", "lastName", "displayName", "legalName", "type", "contactId" FROM "ContactOwner"` + // ) + // await queryRunner.query(`DROP TABLE "ContactOwner"`) + // await queryRunner.query(`ALTER TABLE "temporary_ContactOwner" RENAME TO "ContactOwner"`) + // await queryRunner.query(`CREATE INDEX "IDX_e50c368daf85e7ae54585b0f7b" ON "ContactOwner" ("type")`) + // await queryRunner.query(`DROP INDEX "IDX_ContactRelationshipEntity_left_right"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_ContactRelationship" ("id" varchar PRIMARY KEY NOT NULL, "leftId" varchar NOT NULL, "rightId" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_24a7bc0595cc5da51c91e1bee62" FOREIGN KEY ("leftId") REFERENCES "Contact" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_e673c9f78f3c7670a75c0ea7710" FOREIGN KEY ("rightId") REFERENCES "Contact" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_ContactRelationship"("id", "leftId", "rightId", "created_at", "last_updated_at") SELECT "id", "leftId", "rightId", "created_at", "last_updated_at" FROM "ContactRelationship"` + // ) + // await queryRunner.query(`DROP TABLE "ContactRelationship"`) + // await queryRunner.query(`ALTER TABLE "temporary_ContactRelationship" RENAME TO "ContactRelationship"`) + // await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ContactRelationshipEntity_left_right" ON "ContactRelationship" ("leftId", "rightId")`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Contact" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactTypeId" varchar NOT NULL, CONSTRAINT "FK_a992c5cdc48d0bc105d0338f982" FOREIGN KEY ("contactTypeId") REFERENCES "ContactType" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_Contact"("id", "uri", "created_at", "last_updated_at", "contactTypeId") SELECT "id", "uri", "created_at", "last_updated_at", "contactTypeId" FROM "Contact"` + // ) + // await queryRunner.query(`DROP TABLE "Contact"`) + // await queryRunner.query(`ALTER TABLE "temporary_Contact" RENAME TO "Contact"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Alias" UNIQUE ("alias"), CONSTRAINT "FK_70ac2a54e2041b7914613204e3d" FOREIGN KEY ("contactId") REFERENCES "Contact" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` + // ) + // await queryRunner.query( + // `INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"` + // ) + // await queryRunner.query(`DROP TABLE "Identity"`) + // await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`) + // await queryRunner.query( + // `CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identityId" varchar, CONSTRAINT "REL_Connection_identityId" UNIQUE ("identityId"), CONSTRAINT "FK_fff3668c112a6863bb8c37519a0" FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` + // ) + // await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identityId") SELECT "id", "type", "identityId" FROM "Connection"`) + // await queryRunner.query(`DROP TABLE "Connection"`) + // await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`) } public async down(queryRunner: QueryRunner): Promise {}