mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-09 09:04:20 +02:00
Fix jwt testing
This commit is contained in:
parent
6541de5ff9
commit
040f1e6a0e
@ -56,5 +56,6 @@ module.exports = {
|
|||||||
__SERVER__: true,
|
__SERVER__: true,
|
||||||
__DEV__: true,
|
__DEV__: true,
|
||||||
__LOCAL__: false,
|
__LOCAL__: false,
|
||||||
|
__TEST__: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ module.exports = {
|
|||||||
__CLIENT__: true,
|
__CLIENT__: true,
|
||||||
__SERVER__: false,
|
__SERVER__: false,
|
||||||
__LOCAL__: false,
|
__LOCAL__: false,
|
||||||
|
__TEST__: true,
|
||||||
|
localStorage: { getItem: () => null, setItem: () => null, removeItem: () => null },
|
||||||
},
|
},
|
||||||
maxConcurrency: 50,
|
maxConcurrency: 50,
|
||||||
maxWorkers: 1,
|
maxWorkers: 1,
|
||||||
|
@ -51,8 +51,14 @@ async function getSecret() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getJwt(email: string): Promise<string> {
|
export async function getJwt(email: string): Promise<string> {
|
||||||
const jwt = sign({ user: canonicalEmail(email), permissions: [] }, await getSecret(), {
|
const jwt = sign(
|
||||||
|
{ user: canonicalEmail(email), permissions: [] },
|
||||||
|
await getSecret(),
|
||||||
|
__TEST__
|
||||||
|
? undefined
|
||||||
|
: {
|
||||||
expiresIn: "365d",
|
expiresIn: "365d",
|
||||||
})
|
}
|
||||||
|
)
|
||||||
return jwt
|
return jwt
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* @jest-environment jsdom
|
* @jest-environment jsdom
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import _ from "lodash"
|
||||||
import { login } from "../login"
|
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
|
// 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", () => {
|
describe("login with", () => {
|
||||||
it("right password", async () => {
|
it("right password", async () => {
|
||||||
const res = await login("my.email@gmail.com", "12345678")
|
const res = await login("my.email@gmail.com", "12345678")
|
||||||
expect(res).toEqual({
|
expect(_.omit(res, "jwt")).toEqual({
|
||||||
membre: {
|
membre: {
|
||||||
prenom: mockUser.prenom,
|
prenom: mockUser.prenom,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
expect(res.jwt).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("invalid password length", async () => {
|
it("invalid password length", async () => {
|
||||||
|
2
src/types/index.d.ts
vendored
2
src/types/index.d.ts
vendored
@ -2,6 +2,7 @@ declare const __CLIENT__: boolean
|
|||||||
declare const __SERVER__: boolean
|
declare const __SERVER__: boolean
|
||||||
declare const __DEV__: boolean
|
declare const __DEV__: boolean
|
||||||
declare const __LOCAL__: boolean
|
declare const __LOCAL__: boolean
|
||||||
|
declare const __TEST__: boolean
|
||||||
|
|
||||||
declare module "*.svg"
|
declare module "*.svg"
|
||||||
declare module "*.gif"
|
declare module "*.gif"
|
||||||
@ -18,6 +19,7 @@ declare namespace NodeJS {
|
|||||||
__SERVER__: boolean
|
__SERVER__: boolean
|
||||||
__DEV__: boolean
|
__DEV__: boolean
|
||||||
__LOCAL__: boolean
|
__LOCAL__: boolean
|
||||||
|
__TEST__: boolean
|
||||||
$RefreshReg$: () => void
|
$RefreshReg$: () => void
|
||||||
$RefreshSig$$: () => void
|
$RefreshSig$$: () => void
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user