Fix jwt testing

This commit is contained in:
pikiou 2021-11-30 16:41:46 +01:00
parent 6541de5ff9
commit 040f1e6a0e
5 changed files with 17 additions and 4 deletions

View File

@ -56,5 +56,6 @@ module.exports = {
__SERVER__: true,
__DEV__: true,
__LOCAL__: false,
__TEST__: false,
},
}

View File

@ -22,6 +22,8 @@ module.exports = {
__CLIENT__: true,
__SERVER__: false,
__LOCAL__: false,
__TEST__: true,
localStorage: { getItem: () => null, setItem: () => null, removeItem: () => null },
},
maxConcurrency: 50,
maxWorkers: 1,

View File

@ -51,8 +51,14 @@ async function getSecret() {
}
export async function getJwt(email: string): Promise<string> {
const jwt = sign({ user: canonicalEmail(email), permissions: [] }, await getSecret(), {
expiresIn: "365d",
})
const jwt = sign(
{ user: canonicalEmail(email), permissions: [] },
await getSecret(),
__TEST__
? undefined
: {
expiresIn: "365d",
}
)
return jwt
}

View File

@ -2,6 +2,7 @@
* @jest-environment jsdom
*/
import _ from "lodash"
import { login } from "../login"
// Could do a full test with wget --header='Content-Type:application/json' --post-data='{"email":"pikiou.sub@gmail.com","password":"mot de passe"}' http://localhost:3000/api/user/login
@ -19,11 +20,12 @@ jest.mock("../../gsheets/accessors", () => () => ({
describe("login with", () => {
it("right password", async () => {
const res = await login("my.email@gmail.com", "12345678")
expect(res).toEqual({
expect(_.omit(res, "jwt")).toEqual({
membre: {
prenom: mockUser.prenom,
},
})
expect(res.jwt).toBeDefined()
})
it("invalid password length", async () => {

View File

@ -2,6 +2,7 @@ declare const __CLIENT__: boolean
declare const __SERVER__: boolean
declare const __DEV__: boolean
declare const __LOCAL__: boolean
declare const __TEST__: boolean
declare module "*.svg"
declare module "*.gif"
@ -18,6 +19,7 @@ declare namespace NodeJS {
__SERVER__: boolean
__DEV__: boolean
__LOCAL__: boolean
__TEST__: boolean
$RefreshReg$: () => void
$RefreshSig$$: () => void
}