-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query RelationshipTemplates for password protection #353
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
|
[`${nameof<RelationshipTemplateDTO>((r) => r.passwordProtection)}.password`]: (query: any, input: string) => { | ||
query[`${nameof<RelationshipTemplate>((t) => t.passwordProtection)}.${nameof<PasswordProtection>((t) => t.password)}`] = input; | ||
}, | ||
[`${nameof<RelationshipTemplateDTO>((t) => t.passwordProtection)}.passwordIsPin`]: (query: any, input: string) => { | ||
if (input === "true") { | ||
query[`${nameof<RelationshipTemplate>((t) => t.passwordProtection)}.${nameof<PasswordProtection>((t) => t.passwordType)}`] = { | ||
$regex: "^pin" | ||
}; | ||
} | ||
if (input === "!true") { | ||
query[`${nameof<RelationshipTemplate>((t) => t.passwordProtection)}.${nameof<PasswordProtection>((t) => t.passwordType)}`] = { | ||
$in: ["pw", undefined] | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a need for a custom filter here, just add aliases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
password
needs a custom filter, because PINs are otherwise turned into numbers (and I can't switch this off since then the maxNumberOfAllocations would be a problem).
And we don't store passwordIsPin
, only passwordType
in the database, so the custom filter does that mapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argh, I see. Then we'll have to discuss on how to align these custom thingies to our query translator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it could be enough to do !
instead of !true
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 unprotectedTemplate = await createTemplate(runtimeServices1.transport); | ||
|
||
const templatesWithoutPin = ( | ||
await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ | ||
query: { | ||
"passwordProtection.passwordIsPin": "!true" | ||
} | ||
}) | ||
).value; | ||
const templateIdsWithoutPin = templatesWithoutPin.map((t) => t.id); | ||
|
||
expect(templateIdsWithoutPin).toContain(passwordProtectedTemplate.id); | ||
expect(templateIdsWithoutPin).not.toContain(pinProtectedTemplate.id); | ||
expect(templateIdsWithoutPin).toContain(unprotectedTemplate.id); | ||
|
||
const templatesWithPin = ( | ||
await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({ | ||
query: { | ||
"passwordProtection.passwordIsPin": "true" | ||
} | ||
}) | ||
).value; | ||
const templateIdsWithPin = templatesWithPin.map((t) => t.id); | ||
|
||
expect(templateIdsWithPin).not.toContain(passwordProtectedTemplate.id); | ||
expect(templateIdsWithPin).toContain(pinProtectedTemplate.id); | ||
expect(templateIdsWithPin).not.toContain(unprotectedTemplate.id); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see the other tests that do querying, we have a fabulous tester for querystrings :)
Readiness checklist