Skip to content

Commit

Permalink
DatawalletSynchronizedEvent is not anymore emitted in the connector (#…
Browse files Browse the repository at this point in the history
…347)

* chore: update runtime and tests

* chore: improve delete method error

* chore: fix expect for attribute deletion

* chore: fix identity metadata tests

* Update test/lib/testUtils.ts

Co-authored-by: Julian König <[email protected]>

* chore: deletion of all attributes

* fix: use delete third party for all third party attributes

---------

Co-authored-by: Julian König <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent 9b0ab06 commit abc25ed
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 99 deletions.
270 changes: 199 additions & 71 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@js-soft/docdb-access-mongo": "1.1.9",
"@js-soft/node-logger": "1.2.0",
"@js-soft/ts-utils": "^2.3.3",
"@nmshd/runtime": "6.20.0",
"@nmshd/runtime": "6.23.0",
"@nmshd/typescript-ioc": "^3.2.4",
"@nmshd/typescript-rest": "^3.0.5",
"agentkeepalive": "4.6.0",
Expand Down Expand Up @@ -113,8 +113,8 @@
"@js-soft/eslint-config-ts": "1.6.13",
"@js-soft/license-check": "1.0.9",
"@nmshd/connector-sdk": "*",
"@nmshd/content": "6.20.0",
"@nmshd/core-types": "6.20.0",
"@nmshd/content": "6.23.0",
"@nmshd/core-types": "6.23.0",
"@nmshd/typescript-rest-swagger": "^1.4.1",
"@types/amqplib": "^0.10.6",
"@types/compression": "^1.7.5",
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"build:schemas:watch": "npx nodemon -e ts -w 'src/types' --exec 'npm run build:schemas'"
},
"dependencies": {
"@nmshd/content": "6.20.0",
"@nmshd/content": "6.23.0",
"axios": "^1.7.9",
"form-data": "^4.0.1",
"qs": "^6.13.1"
"qs": "^6.14.0"
},
"devDependencies": {
"@types/qs": "^6.9.17",
"@types/qs": "^6.9.18",
"ts-json-schema-generator": "^2.3.0"
},
"publishConfig": {
Expand Down
5 changes: 4 additions & 1 deletion test/attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getTimeout } from "./lib/setTimeout";
import {
connectAndEmptyCollection,
createRepositoryAttribute,
deleteAllAttributes,
establishRelationship,
executeFullCreateAndShareRelationshipAttributeFlow,
executeFullCreateAndShareRepositoryAttributeFlow,
Expand All @@ -31,7 +32,9 @@ beforeAll(async () => {
}, getTimeout(30000));
afterAll(() => launcher.stop());

beforeEach(() => {
beforeEach(async () => {
await deleteAllAttributes(client1, client1Address);
await deleteAllAttributes(client2, client2Address);
client1._eventBus?.reset();
client2._eventBus?.reset();
});
Expand Down
29 changes: 10 additions & 19 deletions test/identityMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,58 @@
import { Random, RandomCharacterRange } from "@nmshd/transport";
import { ConnectorClientWithMetadata, Launcher } from "./lib/Launcher";
import { ValidationSchema } from "./lib/validation";

const launcher = new Launcher();
let client1: ConnectorClientWithMetadata;
let client1Address: string;

beforeAll(async () => {
[client1] = await launcher.launch(1);
client1Address = (await client1.account.getIdentityInfo()).result.address;
}, 30000);

afterAll(() => launcher.stop());

describe("IdentityMetadata", () => {
test.each([
{
reference: "did:e:localhost:dids:1234567890abcdef123456",
key: undefined,
value: "value"
},
{
reference: "did:e:localhost:dids:1234567890abcdef123456",
key: undefined,
value: { a: "json" }
},
{
reference: "did:e:localhost:dids:1234567890abcdef123456",
key: "key",
value: "value"
}
])("should upsert an IdentityMetadata with key '$key' and value '$value'", async (data) => {
const result = await client1.identityMetadata.upsertIdentityMetadata(data);
const result = await client1.identityMetadata.upsertIdentityMetadata({ ...data, reference: client1Address });
expect(result).toBeSuccessful(ValidationSchema.IdentityMetadata);

const identityMetadata = result.result;
expect(identityMetadata.reference.toString()).toStrictEqual(data.reference);
expect(identityMetadata.reference.toString()).toStrictEqual(client1Address);
expect(identityMetadata.key).toStrictEqual(data.key);
expect(identityMetadata.value).toStrictEqual(data.value);
});

test("should get an IdentityMetadata", async () => {
const reference = await generateReference();
await client1.identityMetadata.upsertIdentityMetadata({ reference: reference, value: "value" });
await client1.identityMetadata.upsertIdentityMetadata({ reference: client1Address, value: "value" });

const result = await client1.identityMetadata.getIdentityMetadata(reference);
const result = await client1.identityMetadata.getIdentityMetadata(client1Address);
expect(result).toBeSuccessful(ValidationSchema.IdentityMetadata);

const identityMetadata = result.result;
expect(identityMetadata.value).toBe("value");
});

test("should delete an IdentityMetadata", async () => {
const reference = await generateReference();
await client1.identityMetadata.upsertIdentityMetadata({ reference: reference, value: "value" });
await client1.identityMetadata.upsertIdentityMetadata({ reference: client1Address, value: "value" });

const result = await client1.identityMetadata.deleteIdentityMetadata(reference);
const result = await client1.identityMetadata.deleteIdentityMetadata(client1Address);
expect(result).toBeSuccessfulVoidResult();

const getResult = await client1.identityMetadata.getIdentityMetadata(reference);
expect(getResult).toBeAnError("IdentityMetadata not found. Make sure the ID exists and the record is not expired.", "error.runtime.recordNotFound");
const getResult = await client1.identityMetadata.getIdentityMetadata(client1Address);
expect(getResult).toBeAnError("There is no stored IdentityMetadata for the specified combination of reference and key.", "error.runtime.identityMetadata.notFound");
});
});

async function generateReference(): Promise<string> {
const identityPart = await Random.string(22, `${RandomCharacterRange.Digit}abcdef`);
return `did:e:localhost:dids:${identityPart}`;
}
2 changes: 1 addition & 1 deletion test/iqlquery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ beforeAll(async () => {
owner: client1Address,
value: {
"@type": "GivenName",
value: "AGivenName"
value: "ASecondGivenName"
},
tags: ["language:de", "content:edu.de.higher"]
}
Expand Down
33 changes: 33 additions & 0 deletions test/lib/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,36 @@ export async function waitForEvent<TEvent>(
clearTimeout(timeoutId);
});
}

export async function deleteAllAttributes(client: ConnectorClient, clientAddress: string): Promise<void> {
const attributesResponse = await client.attributes.getAttributes({});
expect(attributesResponse).toBeSuccessful(ValidationSchema.ConnectorAttributes);

for (const attribute of attributesResponse.result) {
if (!attribute.shareInfo) {
const result = await client.attributes.deleteRepositoryAttribute(attribute.id);
expect(result).toBeSuccessfulVoidResult();
continue;
}

if (attribute.shareInfo.thirdPartyAddress) {
const result = await client.attributes.deleteThirdPartyRelationshipAttributeAndNotifyPeer(attribute.id);
expect(result).toBeSuccessful(ValidationSchema.DeleteThirdPartyRelationshipAttributeAndNotifyPeerResponse);
continue;
}

if (attribute.content.owner === clientAddress) {
const result = await client.attributes.deleteOwnSharedAttributeAndNotifyPeer(attribute.id);
expect(result).toBeSuccessful(ValidationSchema.DeleteOwnSharedAttributeAndNotifyPeerResponse);
continue;
}

if (attribute.content.owner !== clientAddress) {
const result = await client.attributes.deletePeerSharedAttributeAndNotifyOwner(attribute.id);
expect(result).toBeSuccessful(ValidationSchema.DeletePeerSharedAttributeAndNotifyOwnerResponse);
continue;
}

throw new Error("No delete method called");
}
}
5 changes: 4 additions & 1 deletion test/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export enum ValidationSchema {
ConnectorAttribute = "ConnectorAttribute",
ConnectorAttributes = "ConnectorAttributes",
ConnectorAttributeTagCollection = "ConnectorAttributeTagCollection",
SucceedAttributeResponse = "SucceedAttributeResponse"
SucceedAttributeResponse = "SucceedAttributeResponse",
DeleteThirdPartyRelationshipAttributeAndNotifyPeerResponse = "DeleteThirdPartyRelationshipAttributeAndNotifyPeerResponse",
DeleteOwnSharedAttributeAndNotifyPeerResponse = "DeleteOwnSharedAttributeAndNotifyPeerResponse",
DeletePeerSharedAttributeAndNotifyOwnerResponse = "DeletePeerSharedAttributeAndNotifyOwnerResponse"
}

export function validateSchema(schemaName: ValidationSchema, obj: any): void {
Expand Down

0 comments on commit abc25ed

Please sign in to comment.