From 7981a7c12dc2a8d86d14af116ebbbae357cdf6eb Mon Sep 17 00:00:00 2001 From: mkuhn Date: Fri, 29 Nov 2024 14:43:26 +0100 Subject: [PATCH 1/9] feat: query templates --- .../runtime/src/useCases/common/Schemas.ts | 20 ++++++ .../GetRelationshipTemplates.ts | 26 ++++++- packages/runtime/test/lib/testUtils.ts | 12 +++- .../transport/relationshipTemplates.test.ts | 69 ++++++++++++++++++- 4 files changed, 118 insertions(+), 9 deletions(-) diff --git a/packages/runtime/src/useCases/common/Schemas.ts b/packages/runtime/src/useCases/common/Schemas.ts index 10416a7a8..33af9abb4 100644 --- a/packages/runtime/src/useCases/common/Schemas.ts +++ b/packages/runtime/src/useCases/common/Schemas.ts @@ -22679,6 +22679,26 @@ export const GetRelationshipTemplatesRequest: any = { } } ] + }, + "passwordProtection.password": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "passwordProtection.passwordIsPin": { + "type": "string", + "enum": [ + "true", + "!true" + ] } }, "additionalProperties": false diff --git a/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts b/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts index 30700b485..4b2b18a6f 100644 --- a/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts +++ b/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts @@ -1,6 +1,6 @@ import { QueryTranslator } from "@js-soft/docdb-querytranslator"; import { Result } from "@js-soft/ts-utils"; -import { CachedRelationshipTemplate, RelationshipTemplate, RelationshipTemplateController } from "@nmshd/transport"; +import { CachedRelationshipTemplate, PasswordProtection, RelationshipTemplate, RelationshipTemplateController } from "@nmshd/transport"; import { Inject } from "@nmshd/typescript-ioc"; import { nameof } from "ts-simple-nameof"; import { RelationshipTemplateDTO } from "../../../types"; @@ -15,6 +15,8 @@ export interface GetRelationshipTemplatesQuery { createdByDevice?: string | string[]; maxNumberOfAllocations?: string | string[]; forIdentity?: string | string[]; + "passwordProtection.password"?: string | string[]; + "passwordProtection.passwordIsPin"?: "true" | "!true"; } export interface GetRelationshipTemplatesRequest { @@ -37,7 +39,9 @@ export class GetRelationshipTemplatesUseCase extends UseCase((r) => r.createdBy)]: true, [nameof((r) => r.createdByDevice)]: true, [nameof((r) => r.maxNumberOfAllocations)]: true, - [nameof((r) => r.forIdentity)]: true + [nameof((r) => r.forIdentity)]: true, + [`${nameof((r) => r.passwordProtection)}.password`]: true, + [`${nameof((r) => r.passwordProtection)}.passwordIsPin`]: true }, alias: { [nameof((r) => r.isOwn)]: nameof((r) => r.isOwn), @@ -50,7 +54,23 @@ export class GetRelationshipTemplatesUseCase extends UseCase((r) => r.maxNumberOfAllocations)]: `${nameof((r) => r.cache)}.${nameof( (t) => t.maxNumberOfAllocations )}`, - [nameof((r) => r.forIdentity)]: `${nameof((r) => r.cache)}.${nameof((t) => t.forIdentity)}` + [nameof((r) => r.forIdentity)]: `${nameof((r) => r.cache)}.${nameof((t) => t.forIdentity)}`, + [`${nameof((r) => r.passwordProtection)}.password`]: `${nameof((r) => r.passwordProtection)}.${nameof((t) => t.password)}` + }, + custom: { + [`${nameof((t) => t.passwordProtection)}.passwordIsPin`]: (query: any, input: string) => { + if (input === "true") { + query[`${nameof((t) => t.passwordProtection)}.${nameof((t) => t.passwordType)}`] = { + $regex: "^pin" + }; + } + if (input === "!true") { + query[`${nameof((t) => t.passwordProtection)}.${nameof((t) => t.passwordType)}`] = "pw"; + } + } + }, + string: { + toNumber: false } }); diff --git a/packages/runtime/test/lib/testUtils.ts b/packages/runtime/test/lib/testUtils.ts index 5207554d3..c5a22b8e8 100644 --- a/packages/runtime/test/lib/testUtils.ts +++ b/packages/runtime/test/lib/testUtils.ts @@ -211,13 +211,19 @@ export const emptyRelationshipTemplateContent: ArbitraryRelationshipTemplateCont export const emptyRelationshipCreationContent: ArbitraryRelationshipCreationContentJSON = ArbitraryRelationshipCreationContent.from({ value: {} }).toJSON(); -export async function createTemplate(transportServices: TransportServices, body?: RelationshipTemplateContentJSON, templateExpiresAt?: DateTime): Promise { +export async function createTemplate( + transportServices: TransportServices, + body?: RelationshipTemplateContentJSON, + passwordProtection?: { password: string; passwordIsPin?: true }, + templateExpiresAt?: DateTime +): Promise { const defaultExpirationDateTime = DateTime.utc().plus({ minutes: 10 }).toString(); const response = await transportServices.relationshipTemplates.createOwnRelationshipTemplate({ maxNumberOfAllocations: 1, expiresAt: templateExpiresAt ? templateExpiresAt.toString() : defaultExpirationDateTime, - content: _.cloneDeep(body) ?? emptyRelationshipTemplateContent + content: _.cloneDeep(body) ?? emptyRelationshipTemplateContent, + passwordProtection }); expect(response).toBeSuccessful(); @@ -240,7 +246,7 @@ export async function exchangeTemplate( content?: RelationshipTemplateContentJSON, templateExpiresAt?: DateTime ): Promise { - const template = await createTemplate(transportServicesCreator, content, templateExpiresAt); + const template = await createTemplate(transportServicesCreator, content, undefined, templateExpiresAt); const response = await transportServicesRecipient.relationshipTemplates.loadPeerRelationshipTemplate({ reference: template.truncatedReference }); expect(response).toBeSuccessful(); diff --git a/packages/runtime/test/transport/relationshipTemplates.test.ts b/packages/runtime/test/transport/relationshipTemplates.test.ts index 6d5ee8fb2..8faba63eb 100644 --- a/packages/runtime/test/transport/relationshipTemplates.test.ts +++ b/packages/runtime/test/transport/relationshipTemplates.test.ts @@ -2,7 +2,7 @@ import { RelationshipTemplateContent, RelationshipTemplateContentJSON } from "@n import { RelationshipTemplateReference } from "@nmshd/transport"; import { DateTime } from "luxon"; import { GetRelationshipTemplatesQuery, OwnerRestriction } from "../../src"; -import { emptyRelationshipTemplateContent, QueryParamConditions, RuntimeServiceProvider, TestRuntimeServices } from "../lib"; +import { createTemplate, emptyRelationshipTemplateContent, QueryParamConditions, RuntimeServiceProvider, TestRuntimeServices } from "../lib"; const serviceProvider = new RuntimeServiceProvider(); let runtimeServices1: TestRuntimeServices; @@ -464,7 +464,8 @@ describe("RelationshipTemplates query", () => { maxNumberOfAllocations: 1, expiresAt: DateTime.utc().plus({ minutes: 10 }).toString(), content: emptyRelationshipTemplateContent, - forIdentity: runtimeServices1.address + forIdentity: runtimeServices1.address, + passwordProtection: { password: "1234", passwordIsPin: true } }) ).value; const conditions = new QueryParamConditions(template, runtimeServices1.transport) @@ -474,7 +475,9 @@ describe("RelationshipTemplates query", () => { .addStringSet("createdBy") .addStringSet("createdByDevice") .addNumberSet("maxNumberOfAllocations") - .addStringSet("forIdentity"); + .addStringSet("forIdentity") + .addStringSet("passwordProtection.password") + .addBooleanSet("passwordProtection.passwordIsPin"); await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates({ query: q })); }); @@ -514,4 +517,64 @@ describe("RelationshipTemplates query", () => { await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates({ query: q, ownerRestriction: OwnerRestriction.Peer })); }); + + test("password query", async () => { + const passwordProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "password" }); + + const pinProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "1234", passwordIsPin: true }); + + const passwordProtectedTemplates = ( + await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ + query: { + "passwordProtection.password": "password" + } + }) + ).value; + const passwordProtectedTemplateIds = passwordProtectedTemplates.map((t) => t.id); + + expect(passwordProtectedTemplateIds).toContain(passwordProtectedTemplate.id); + expect(passwordProtectedTemplateIds).not.toContain(pinProtectedTemplate.id); + + const pinProtectedTemplates = ( + await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ + query: { + "passwordProtection.password": "1234" + } + }) + ).value; + const pinProtectedTemplateIds = pinProtectedTemplates.map((t) => t.id); + + expect(pinProtectedTemplateIds).not.toContain(passwordProtectedTemplate.id); + expect(pinProtectedTemplateIds).toContain(pinProtectedTemplate.id); + }); + + test("passwordIsPin query", async () => { + const passwordProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "password" }); + + const pinProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "1234", passwordIsPin: true }); + + const passwordProtectedTemplates = ( + await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ + query: { + "passwordProtection.passwordIsPin": "!true" + } + }) + ).value; + const passwordProtectedTemplateIds = passwordProtectedTemplates.map((t) => t.id); + + expect(passwordProtectedTemplateIds).toContain(passwordProtectedTemplate.id); + expect(passwordProtectedTemplateIds).not.toContain(pinProtectedTemplate.id); + + const pinProtectedTemplates = ( + await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ + query: { + "passwordProtection.passwordIsPin": "true" + } + }) + ).value; + const pinProtectedTemplateIds = pinProtectedTemplates.map((t) => t.id); + + expect(pinProtectedTemplateIds).not.toContain(passwordProtectedTemplate.id); + expect(pinProtectedTemplateIds).toContain(pinProtectedTemplate.id); + }); }); From bd434efb259408058bef170d9efdeb7e543e8f9b Mon Sep 17 00:00:00 2001 From: mkuhn Date: Fri, 29 Nov 2024 14:51:28 +0100 Subject: [PATCH 2/9] fix: use custom query --- .../relationshipTemplates/GetRelationshipTemplates.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts b/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts index 4b2b18a6f..4b42e5740 100644 --- a/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts +++ b/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts @@ -54,10 +54,12 @@ export class GetRelationshipTemplatesUseCase extends UseCase((r) => r.maxNumberOfAllocations)]: `${nameof((r) => r.cache)}.${nameof( (t) => t.maxNumberOfAllocations )}`, - [nameof((r) => r.forIdentity)]: `${nameof((r) => r.cache)}.${nameof((t) => t.forIdentity)}`, - [`${nameof((r) => r.passwordProtection)}.password`]: `${nameof((r) => r.passwordProtection)}.${nameof((t) => t.password)}` + [nameof((r) => r.forIdentity)]: `${nameof((r) => r.cache)}.${nameof((t) => t.forIdentity)}` }, custom: { + [`${nameof((r) => r.passwordProtection)}.password`]: (query: any, input: string) => { + query[`${nameof((t) => t.passwordProtection)}.${nameof((t) => t.password)}`] = input; + }, [`${nameof((t) => t.passwordProtection)}.passwordIsPin`]: (query: any, input: string) => { if (input === "true") { query[`${nameof((t) => t.passwordProtection)}.${nameof((t) => t.passwordType)}`] = { @@ -68,9 +70,6 @@ export class GetRelationshipTemplatesUseCase extends UseCase((t) => t.passwordProtection)}.${nameof((t) => t.passwordType)}`] = "pw"; } } - }, - string: { - toNumber: false } }); From 6a4faeb384195c982d5277a44ccfd447c4ccfe4f Mon Sep 17 00:00:00 2001 From: mkuhn Date: Fri, 29 Nov 2024 14:56:13 +0100 Subject: [PATCH 3/9] test: cleanup tests --- .../runtime/test/transport/relationshipTemplates.test.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/runtime/test/transport/relationshipTemplates.test.ts b/packages/runtime/test/transport/relationshipTemplates.test.ts index 8faba63eb..a0c95c08b 100644 --- a/packages/runtime/test/transport/relationshipTemplates.test.ts +++ b/packages/runtime/test/transport/relationshipTemplates.test.ts @@ -464,8 +464,7 @@ describe("RelationshipTemplates query", () => { maxNumberOfAllocations: 1, expiresAt: DateTime.utc().plus({ minutes: 10 }).toString(), content: emptyRelationshipTemplateContent, - forIdentity: runtimeServices1.address, - passwordProtection: { password: "1234", passwordIsPin: true } + forIdentity: runtimeServices1.address }) ).value; const conditions = new QueryParamConditions(template, runtimeServices1.transport) @@ -475,9 +474,7 @@ describe("RelationshipTemplates query", () => { .addStringSet("createdBy") .addStringSet("createdByDevice") .addNumberSet("maxNumberOfAllocations") - .addStringSet("forIdentity") - .addStringSet("passwordProtection.password") - .addBooleanSet("passwordProtection.passwordIsPin"); + .addStringSet("forIdentity"); await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates({ query: q })); }); From 855551828228570912874ba653d0e33aebc23c54 Mon Sep 17 00:00:00 2001 From: mkuhn Date: Fri, 29 Nov 2024 17:26:05 +0100 Subject: [PATCH 4/9] fix: !true accepts undefined --- .../relationshipTemplates/GetRelationshipTemplates.ts | 4 +++- packages/runtime/test/transport/relationshipTemplates.test.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts b/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts index 4b42e5740..b19186361 100644 --- a/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts +++ b/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts @@ -67,7 +67,9 @@ export class GetRelationshipTemplatesUseCase extends UseCase((t) => t.passwordProtection)}.${nameof((t) => t.passwordType)}`] = "pw"; + query[`${nameof((t) => t.passwordProtection)}.${nameof((t) => t.passwordType)}`] = { + $in: ["pw", undefined] + }; } } } diff --git a/packages/runtime/test/transport/relationshipTemplates.test.ts b/packages/runtime/test/transport/relationshipTemplates.test.ts index ebe12b393..226dc67d1 100644 --- a/packages/runtime/test/transport/relationshipTemplates.test.ts +++ b/packages/runtime/test/transport/relationshipTemplates.test.ts @@ -363,6 +363,8 @@ describe("RelationshipTemplates query", () => { const pinProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "1234", passwordIsPin: true }); + const unprotectedTemplate = await createTemplate(runtimeServices1.transport); + const passwordProtectedTemplates = ( await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ query: { @@ -374,6 +376,7 @@ describe("RelationshipTemplates query", () => { expect(passwordProtectedTemplateIds).toContain(passwordProtectedTemplate.id); expect(passwordProtectedTemplateIds).not.toContain(pinProtectedTemplate.id); + expect(passwordProtectedTemplateIds).toContain(unprotectedTemplate.id); const pinProtectedTemplates = ( await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ @@ -386,5 +389,6 @@ describe("RelationshipTemplates query", () => { expect(pinProtectedTemplateIds).not.toContain(passwordProtectedTemplate.id); expect(pinProtectedTemplateIds).toContain(pinProtectedTemplate.id); + expect(pinProtectedTemplateIds).not.toContain(unprotectedTemplate.id); }); }); From e5414eb1e41d52bf660ff2498c576333b82d99c4 Mon Sep 17 00:00:00 2001 From: mkuhn Date: Fri, 29 Nov 2024 17:29:01 +0100 Subject: [PATCH 5/9] refactor: naming --- .../transport/relationshipTemplates.test.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/runtime/test/transport/relationshipTemplates.test.ts b/packages/runtime/test/transport/relationshipTemplates.test.ts index 226dc67d1..3c7c95fde 100644 --- a/packages/runtime/test/transport/relationshipTemplates.test.ts +++ b/packages/runtime/test/transport/relationshipTemplates.test.ts @@ -365,30 +365,30 @@ describe("RelationshipTemplates query", () => { const unprotectedTemplate = await createTemplate(runtimeServices1.transport); - const passwordProtectedTemplates = ( + const templatesWithoutPin = ( await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ query: { "passwordProtection.passwordIsPin": "!true" } }) ).value; - const passwordProtectedTemplateIds = passwordProtectedTemplates.map((t) => t.id); + const templateIdsWithoutPin = templatesWithoutPin.map((t) => t.id); - expect(passwordProtectedTemplateIds).toContain(passwordProtectedTemplate.id); - expect(passwordProtectedTemplateIds).not.toContain(pinProtectedTemplate.id); - expect(passwordProtectedTemplateIds).toContain(unprotectedTemplate.id); + expect(templateIdsWithoutPin).toContain(passwordProtectedTemplate.id); + expect(templateIdsWithoutPin).not.toContain(pinProtectedTemplate.id); + expect(templateIdsWithoutPin).toContain(unprotectedTemplate.id); - const pinProtectedTemplates = ( + const templatesWithPin = ( await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ query: { "passwordProtection.passwordIsPin": "true" } }) ).value; - const pinProtectedTemplateIds = pinProtectedTemplates.map((t) => t.id); + const templateIdsWithPin = templatesWithPin.map((t) => t.id); - expect(pinProtectedTemplateIds).not.toContain(passwordProtectedTemplate.id); - expect(pinProtectedTemplateIds).toContain(pinProtectedTemplate.id); - expect(pinProtectedTemplateIds).not.toContain(unprotectedTemplate.id); + expect(templateIdsWithPin).not.toContain(passwordProtectedTemplate.id); + expect(templateIdsWithPin).toContain(pinProtectedTemplate.id); + expect(templateIdsWithPin).not.toContain(unprotectedTemplate.id); }); }); From 27253c95fe0905a659418766f225f55e24a21471 Mon Sep 17 00:00:00 2001 From: mkuhn Date: Mon, 2 Dec 2024 10:09:07 +0100 Subject: [PATCH 6/9] feat: !true to ! --- .../relationshipTemplates/GetRelationshipTemplates.ts | 4 ++-- packages/runtime/test/transport/relationshipTemplates.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts b/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts index b19186361..e273b4e11 100644 --- a/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts +++ b/packages/runtime/src/useCases/transport/relationshipTemplates/GetRelationshipTemplates.ts @@ -16,7 +16,7 @@ export interface GetRelationshipTemplatesQuery { maxNumberOfAllocations?: string | string[]; forIdentity?: string | string[]; "passwordProtection.password"?: string | string[]; - "passwordProtection.passwordIsPin"?: "true" | "!true"; + "passwordProtection.passwordIsPin"?: "true" | "!"; } export interface GetRelationshipTemplatesRequest { @@ -66,7 +66,7 @@ export class GetRelationshipTemplatesUseCase extends UseCase((t) => t.passwordProtection)}.${nameof((t) => t.passwordType)}`] = { $in: ["pw", undefined] }; diff --git a/packages/runtime/test/transport/relationshipTemplates.test.ts b/packages/runtime/test/transport/relationshipTemplates.test.ts index 3c7c95fde..edd3ce532 100644 --- a/packages/runtime/test/transport/relationshipTemplates.test.ts +++ b/packages/runtime/test/transport/relationshipTemplates.test.ts @@ -368,7 +368,7 @@ describe("RelationshipTemplates query", () => { const templatesWithoutPin = ( await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ query: { - "passwordProtection.passwordIsPin": "!true" + "passwordProtection.passwordIsPin": "!" } }) ).value; From a608cf43ff63f7345fe314de0dabc17ec3e45573 Mon Sep 17 00:00:00 2001 From: mkuhn Date: Mon, 2 Dec 2024 10:33:20 +0100 Subject: [PATCH 7/9] chore: build schemas --- packages/runtime/src/useCases/common/Schemas.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/useCases/common/Schemas.ts b/packages/runtime/src/useCases/common/Schemas.ts index e1a79cc2c..e4447d430 100644 --- a/packages/runtime/src/useCases/common/Schemas.ts +++ b/packages/runtime/src/useCases/common/Schemas.ts @@ -22774,7 +22774,7 @@ export const GetRelationshipTemplatesRequest: any = { "type": "string", "enum": [ "true", - "!true" + "!" ] } }, From 7d5e5b95eb9e113d3583aba7182437a73af3c7ca Mon Sep 17 00:00:00 2001 From: mkuhn Date: Mon, 2 Dec 2024 10:33:57 +0100 Subject: [PATCH 8/9] test: use queryconditions --- .../transport/relationshipTemplates.test.ts | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/packages/runtime/test/transport/relationshipTemplates.test.ts b/packages/runtime/test/transport/relationshipTemplates.test.ts index edd3ce532..2761073f3 100644 --- a/packages/runtime/test/transport/relationshipTemplates.test.ts +++ b/packages/runtime/test/transport/relationshipTemplates.test.ts @@ -328,34 +328,20 @@ describe("RelationshipTemplates query", () => { await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates({ query: q, ownerRestriction: OwnerRestriction.Peer })); }); - test("password query", async () => { + test("password query with password", async () => { const passwordProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "password" }); - const pinProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "1234", passwordIsPin: true }); - - const passwordProtectedTemplates = ( - await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ - query: { - "passwordProtection.password": "password" - } - }) - ).value; - const passwordProtectedTemplateIds = passwordProtectedTemplates.map((t) => t.id); - - expect(passwordProtectedTemplateIds).toContain(passwordProtectedTemplate.id); - expect(passwordProtectedTemplateIds).not.toContain(pinProtectedTemplate.id); + const conditions = new QueryParamConditions(passwordProtectedTemplate, runtimeServices1.transport).addStringSet( + "passwordProtection.password" + ); + await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates({ query: q })); + }); - const pinProtectedTemplates = ( - await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ - query: { - "passwordProtection.password": "1234" - } - }) - ).value; - const pinProtectedTemplateIds = pinProtectedTemplates.map((t) => t.id); + test("password query with pin", async () => { + const pinProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "1234", passwordIsPin: true }); - expect(pinProtectedTemplateIds).not.toContain(passwordProtectedTemplate.id); - expect(pinProtectedTemplateIds).toContain(pinProtectedTemplate.id); + const conditions = new QueryParamConditions(pinProtectedTemplate, runtimeServices1.transport).addStringSet("passwordProtection.password"); + await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates({ query: q })); }); test("passwordIsPin query", async () => { From c19084a93971ce56c54f4205e3d1af1aefd26fa6 Mon Sep 17 00:00:00 2001 From: mkuhn Date: Mon, 2 Dec 2024 14:42:11 +0100 Subject: [PATCH 9/9] test: naming --- .../transport/relationshipTemplates.test.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/runtime/test/transport/relationshipTemplates.test.ts b/packages/runtime/test/transport/relationshipTemplates.test.ts index 2761073f3..4e58f61bd 100644 --- a/packages/runtime/test/transport/relationshipTemplates.test.ts +++ b/packages/runtime/test/transport/relationshipTemplates.test.ts @@ -328,7 +328,7 @@ describe("RelationshipTemplates query", () => { await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates({ query: q, ownerRestriction: OwnerRestriction.Peer })); }); - test("password query with password", async () => { + test("password query for a template protected with a password that's not a PIN", async () => { const passwordProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "password" }); const conditions = new QueryParamConditions(passwordProtectedTemplate, runtimeServices1.transport).addStringSet( @@ -337,7 +337,7 @@ describe("RelationshipTemplates query", () => { await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates({ query: q })); }); - test("password query with pin", async () => { + test("password query for a template protected with a PIN", async () => { const pinProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "1234", passwordIsPin: true }); const conditions = new QueryParamConditions(pinProtectedTemplate, runtimeServices1.transport).addStringSet("passwordProtection.password"); @@ -358,11 +358,11 @@ describe("RelationshipTemplates query", () => { } }) ).value; - const templateIdsWithoutPin = templatesWithoutPin.map((t) => t.id); + const idsOfTemplatesWithoutPin = templatesWithoutPin.map((t) => t.id); - expect(templateIdsWithoutPin).toContain(passwordProtectedTemplate.id); - expect(templateIdsWithoutPin).not.toContain(pinProtectedTemplate.id); - expect(templateIdsWithoutPin).toContain(unprotectedTemplate.id); + expect(idsOfTemplatesWithoutPin).toContain(passwordProtectedTemplate.id); + expect(idsOfTemplatesWithoutPin).not.toContain(pinProtectedTemplate.id); + expect(idsOfTemplatesWithoutPin).toContain(unprotectedTemplate.id); const templatesWithPin = ( await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ @@ -371,10 +371,10 @@ describe("RelationshipTemplates query", () => { } }) ).value; - const templateIdsWithPin = templatesWithPin.map((t) => t.id); + const idsOfTemplatesWithPin = templatesWithPin.map((t) => t.id); - expect(templateIdsWithPin).not.toContain(passwordProtectedTemplate.id); - expect(templateIdsWithPin).toContain(pinProtectedTemplate.id); - expect(templateIdsWithPin).not.toContain(unprotectedTemplate.id); + expect(idsOfTemplatesWithPin).not.toContain(passwordProtectedTemplate.id); + expect(idsOfTemplatesWithPin).toContain(pinProtectedTemplate.id); + expect(idsOfTemplatesWithPin).not.toContain(unprotectedTemplate.id); }); });