generated from Kan-A-Pesh/express-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c137b46
commit 3f118aa
Showing
2 changed files
with
12 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 () => { | ||
|
@@ -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 () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 () => { | ||
|