Skip to content

Commit

Permalink
Merge pull request #68 from PermanentOrg/use_lowercase_emails_when_se…
Browse files Browse the repository at this point in the history
…tting_subjects

Use case insensitive email lookup in /admin/account/set_null_subjects
  • Loading branch information
liam-lloyd authored Jan 30, 2024
2 parents 24791ac + 7878651 commit ce4c5bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/api/src/admin/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ describe("set_null_subjects", () => {
.expect(200, { updatedAccounts: ["2", "4"], emailsWithErrors: [] });
});

test("should look up emails case-insensitively", async () => {
const testEmail = "test+4@permanent.org";
await agent
.post("/api/v2/admin/account/set_null_subjects")
.send({
accounts: [
{
email: testEmail,
subject: "5c3473b6-cf2e-4c55-a80e-8db51d1bc5fd",
},
],
})
.expect(200, { updatedAccounts: ["6"], emailsWithErrors: [] });
});

test("should call logger.error if database call fails", async () => {
const testError = new Error("out of cheese - redo from start");
jest.spyOn(db, "sql").mockRejectedValueOnce(testError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ account
SET
subject = :subject
WHERE
primaryemail = :email
LOWER(primaryemail) = LOWER(:email)
AND status = 'status.auth.ok'
AND subject IS NULL
RETURNING
Expand Down
9 changes: 9 additions & 0 deletions packages/api/src/fixtures/create_test_accounts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ VALUES
'type.account.standard',
'Jenny Rando',
null
),
(
6,
'TEST+4@permanent.org',
'status.auth.ok',
'{}',
'type.account.standard',
'Jenny Rando',
null
);

0 comments on commit ce4c5bb

Please sign in to comment.