From daeb87d5a5f3f955b096be44e098d053f78a885b Mon Sep 17 00:00:00 2001 From: sksadjad Date: Wed, 13 Sep 2023 14:17:08 +0200 Subject: [PATCH 1/3] feat: added contact test data --- .../__tests__/agent.ts | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/packages/contact-manager-rest-api/__tests__/agent.ts b/packages/contact-manager-rest-api/__tests__/agent.ts index 0c73f11b1..5a40d219a 100644 --- a/packages/contact-manager-rest-api/__tests__/agent.ts +++ b/packages/contact-manager-rest-api/__tests__/agent.ts @@ -3,8 +3,9 @@ import { DataStore, DataStoreORM } from '@veramo/data-store' import { IRequiredPlugins } from '../src' import { DB_CONNECTION_NAME, sqliteConfig } from './database' import { ContactManager } from '@sphereon/ssi-sdk.contact-manager' -import { ContactStore } from '@sphereon/ssi-sdk.data-store' +import { ContactStore, PartyTypeEnum } from '@sphereon/ssi-sdk.data-store' import { DataSources } from '@sphereon/ssi-sdk.agent-config' +import { v4 } from 'uuid' const dbConnection = DataSources.singleInstance() .addConfig(DB_CONNECTION_NAME, sqliteConfig) @@ -14,4 +15,52 @@ const agent = createAgent({ plugins: [new DataStore(dbConnection), new DataStoreORM(dbConnection), new ContactManager({ store: new ContactStore(dbConnection) })], }) +agent.cmAddContactType({ + name: `${v4()}-people`, + type: PartyTypeEnum.NATURAL_PERSON, + tenantId: v4() +}).then(ct=> { + agent.cmAddContact({ + "firstName": "emp1_fn", + "middleName": "emp1_mn", + "lastName": "emp1_ln", + "displayName": "emp1_dn", + contactType: ct, + uri: "emp1_url" + }) + agent.cmAddContact({ + "firstName": "emp2_fn", + "middleName": "emp2_mn", + "lastName": "emp2_ln", + "displayName": "emp2_dn", + contactType: ct, + uri: "emp2_url" + }) + agent.cmAddContact({ + "firstName": "emp3_fn", + "middleName": "emp3_mn", + "lastName": "emp3_ln", + "displayName": "emp3_dn", + contactType: ct, + uri: "emp2_url" + }) +}) +agent.cmAddContactType({ + name: `${v4()}-orgzanizations`, + type: PartyTypeEnum.ORGANIZATION, + tenantId: v4() +}).then(ct=> { + agent.cmAddContact({ + legalName: `${v4()}-org1_fn`, + displayName: "org1_dn", + contactType: ct, + uri: "org1_uri" + }) + agent.cmAddContact({ + legalName: `${v4()}-org2_fn`, + displayName: "org2_dn", + contactType: ct, + uri: "org2_uri" + }) +}) export default agent From 2706a7e48622e668cc41c0bf476ae757f1fee325 Mon Sep 17 00:00:00 2001 From: sksadjad Date: Thu, 14 Sep 2023 09:23:30 +0200 Subject: [PATCH 2/3] chore: changed the test contact data --- .../__tests__/agent.ts | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/packages/contact-manager-rest-api/__tests__/agent.ts b/packages/contact-manager-rest-api/__tests__/agent.ts index 5a40d219a..8dda2689a 100644 --- a/packages/contact-manager-rest-api/__tests__/agent.ts +++ b/packages/contact-manager-rest-api/__tests__/agent.ts @@ -16,51 +16,47 @@ const agent = createAgent({ }) agent.cmAddContactType({ - name: `${v4()}-people`, + name: "people", type: PartyTypeEnum.NATURAL_PERSON, tenantId: v4() }).then(ct=> { agent.cmAddContact({ - "firstName": "emp1_fn", - "middleName": "emp1_mn", - "lastName": "emp1_ln", - "displayName": "emp1_dn", + firstName: "Abraham", + middleName: "Gerrit Jan", + lastName: "ten Cate", + displayName: "Bram ten Cate", contactType: ct, - uri: "emp1_url" + uri: "example.com" }) agent.cmAddContact({ - "firstName": "emp2_fn", - "middleName": "emp2_mn", - "lastName": "emp2_ln", - "displayName": "emp2_dn", + firstName: "Kraak", + middleName: "en", + lastName: "Smaak", + displayName: "Kraak en Smaak", contactType: ct, - uri: "emp2_url" - }) - agent.cmAddContact({ - "firstName": "emp3_fn", - "middleName": "emp3_mn", - "lastName": "emp3_ln", - "displayName": "emp3_dn", - contactType: ct, - uri: "emp2_url" + uri: "example.com" }) +}).catch(e => { + console.log(e) }) agent.cmAddContactType({ - name: `${v4()}-orgzanizations`, + name: "orgzanizations", type: PartyTypeEnum.ORGANIZATION, tenantId: v4() }).then(ct=> { agent.cmAddContact({ - legalName: `${v4()}-org1_fn`, - displayName: "org1_dn", + legalName: "Sphereon International", + displayName: "Sphereon B.V.", contactType: ct, - uri: "org1_uri" + uri: "sphereon.com" }) agent.cmAddContact({ - legalName: `${v4()}-org2_fn`, - displayName: "org2_dn", + legalName: "Kamer van verkoophandel", + displayName: "Kamer van koophandel", contactType: ct, - uri: "org2_uri" + uri: "kvk.nl" }) +}).catch(e=> { + console.log(e) }) export default agent From 51861fd35110b57975c4d897893a65f670e50430 Mon Sep 17 00:00:00 2001 From: sksadjad Date: Thu, 14 Sep 2023 09:52:53 +0200 Subject: [PATCH 3/3] fix: fixed partyId property in rest api --- packages/contact-manager-rest-api/src/api-functions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contact-manager-rest-api/src/api-functions.ts b/packages/contact-manager-rest-api/src/api-functions.ts index 101990845..1da07992a 100644 --- a/packages/contact-manager-rest-api/src/api-functions.ts +++ b/packages/contact-manager-rest-api/src/api-functions.ts @@ -29,7 +29,7 @@ export function partyReadEndpoint(router: Router, context: IRequiredContext, opt const path = opts?.path ?? '/parties' router.get(`${path}/:partyId`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => { try { - const partyId = request.params.contactId + const partyId = request.params.partyId const party = await context.agent.cmGetContact({ contactId: partyId }) response.statusCode = 200 return response.send(party)