Skip to content

Commit

Permalink
fix: issues with JWT token on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kan-A-Pesh committed Nov 5, 2024
1 parent c137b46 commit 3f118aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions tests/e2e/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const app = createApp("e2e-auth");
describe("Test authentication", () => {
const email = "[email protected]";
const token = AuthController.generateCreationToken(email, false);
const redirectUrl = globals.env.MAIL_REDIRECT_URL.replace("{token}", token);

test("should send an email", async () => {
// We use X-ADMIN-KEY to fetch back the redirect URL without expiration
const res = await post(app, "/auth/send-mail", { email: email }, { "X-ADMIN-KEY": globals.env.ADMIN_TOKEN });
const rawRedirectUrl = globals.env.MAIL_REDIRECT_URL.replace("{token}", "");

expect(res.body).toStrictEqual({
masterStatus: 201,
Expand All @@ -21,10 +21,12 @@ describe("Test authentication", () => {
{
status: 201,
success: true,
data: redirectUrl
data: expect.stringContaining(rawRedirectUrl)
}
]
});

expect(AuthController.validateCreationToken(res.body.response[0].data.replace(rawRedirectUrl, ""))).toBe(email);
});

test("should get 'too many requests' error", async () => {
Expand Down Expand Up @@ -91,10 +93,12 @@ describe("Test authentication", () => {
{
status: 200,
success: true,
data: expect.stringContaining(authToken.substring(0, authToken.indexOf("."))) // Remove the signature
data: expect.any(String)
}
]
});

expect(AuthController.validateAuthToken(res.body.response[0].data)).toBe(email);
});

test("should get 'invalid credentials' error", async () => {
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/granters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,16 @@ describe("Test granters", () => {
status: 200,
success: true,
data: {
token: testGlobals.granterAuthToken,
token: expect.any(String),
clubId: testGlobals.clubId
}
}
]
});

expect(AuthController.validateGranterAuthToken(res.body.response[0].data.token)).toBe(
"[email protected]"
);
});

test("should authenticate", async () => {
Expand Down

0 comments on commit 3f118aa

Please sign in to comment.