diff --git a/.eslintrc.js b/.eslintrc.js index 8fb6966..0184e79 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -56,5 +56,6 @@ module.exports = { __SERVER__: true, __DEV__: true, __LOCAL__: false, + __TEST__: false, }, } diff --git a/jest/config.js b/jest/config.js index 4788890..3ac0720 100644 --- a/jest/config.js +++ b/jest/config.js @@ -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, diff --git a/src/server/secure.ts b/src/server/secure.ts index 6ab36c5..96b1e95 100644 --- a/src/server/secure.ts +++ b/src/server/secure.ts @@ -51,8 +51,14 @@ async function getSecret() { } export async function getJwt(email: string): Promise { - 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 } diff --git a/src/server/userManagement/__tests__/login.tsx b/src/server/userManagement/__tests__/login.tsx index 12f3d7f..ab2d4a8 100755 --- a/src/server/userManagement/__tests__/login.tsx +++ b/src/server/userManagement/__tests__/login.tsx @@ -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 () => { diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 723cae4..56627ad 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -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 }