Skip to content

Commit

Permalink
fix: email is set as expired when email is not a beta.gouv.fr address (
Browse files Browse the repository at this point in the history
…#654)

* fix: eamil is set as expired when email is not a beta.gouv.fr address

* test: fix setEmailExpired relative test
  • Loading branch information
LucasCharrier authored Nov 21, 2024
1 parent 192ed03 commit 820a29d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
22 changes: 18 additions & 4 deletions __tests__/test-user-contract-ending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,7 @@ describe("After quitting", () => {
should.equal(test.length, 2);
});

it("should set email as expired", async () => {
const today = new Date(fakeTodayDate);

it("should set email as expired if email is not from main domain", async () => {
const updatedUser = await db
.updateTable("users")
.where("username", "=", "julien.dauphant")
Expand All @@ -436,7 +434,23 @@ describe("After quitting", () => {
.selectAll()
.where("username", "=", "julien.dauphant")
.execute();
user.primary_email_status.should.equal(EmailStatusCode.EMAIL_EXPIRED);
user.primary_email_status.should.equal(EmailStatusCode.EMAIL_SUSPENDED);

const updatedUser2 = await db
.updateTable("users")
.where("username", "=", "julien.dauphant")
.set({
primary_email: `[email protected]`,
})
.returningAll()
.executeTakeFirstOrThrow();
await setEmailExpired();
const [user2] = await db
.selectFrom("users")
.selectAll()
.where("username", "=", "julien.dauphant")
.execute();
user2.primary_email_status.should.equal(EmailStatusCode.EMAIL_EXPIRED);
// userinfos.restore();
});

Expand Down
3 changes: 2 additions & 1 deletion src/server/schedulers/setEmailExpired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as utils from "@controllers/utils";
export async function setEmailExpired(
optionalExpiredUsers?: memberBaseInfoSchemaType[]
) {
// set email that are not beta.gouv.fr as expired
let expiredUsers = optionalExpiredUsers;
let dbUsers: memberBaseInfoSchemaType[] = [];
if (!expiredUsers) {
Expand All @@ -28,7 +29,7 @@ export async function setEmailExpired(
user.primary_email_status === EmailStatusCode.EMAIL_SUSPENDED &&
user.primary_email_status_updated_at < todayLess30days &&
user.primary_email &&
user.primary_email.includes(`@${config.domain}`)
!user.primary_email.includes(`@${config.domain}`)
);
}
for (const user of dbUsers) {
Expand Down

0 comments on commit 820a29d

Please sign in to comment.