mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-10 01:24:20 +02:00
rename signIn to login
This commit is contained in:
parent
e9bbbdc897
commit
976fbded67
@ -18,7 +18,7 @@ import certbotRouter from "../routes/certbot"
|
|||||||
import { jeuJavListGet } from "./gsheets/jeuJav"
|
import { jeuJavListGet } from "./gsheets/jeuJav"
|
||||||
import { envieListGet, envieAdd } from "./gsheets/envies"
|
import { envieListGet, envieAdd } from "./gsheets/envies"
|
||||||
import { membreGet, membreSet } from "./gsheets/membres"
|
import { membreGet, membreSet } from "./gsheets/membres"
|
||||||
import signInHandler from "./userManagement/signIn"
|
import loginHandler from "./userManagement/login"
|
||||||
import config from "../config"
|
import config from "../config"
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
@ -56,7 +56,7 @@ app.post("/MembreSet", membreSet)
|
|||||||
app.post("/EnvieAdd", envieAdd)
|
app.post("/EnvieAdd", envieAdd)
|
||||||
|
|
||||||
// Sign in & up API
|
// Sign in & up API
|
||||||
app.post("/api/user/login", signInHandler)
|
app.post("/api/user/login", loginHandler)
|
||||||
|
|
||||||
// Use React server-side rendering middleware
|
// Use React server-side rendering middleware
|
||||||
app.get("*", ssr)
|
app.get("*", ssr)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @jest-environment jsdom
|
* @jest-environment jsdom
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { signIn } from "../signIn"
|
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
|
||||||
|
|
||||||
@ -16,9 +16,9 @@ jest.mock("../../gsheets/accessors", () => () => ({
|
|||||||
listGet: () => [mockUser],
|
listGet: () => [mockUser],
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe("signIn with", () => {
|
describe("login with", () => {
|
||||||
it("right password", async () => {
|
it("right password", async () => {
|
||||||
const res = await signIn("my.email@gmail.com", "12345678")
|
const res = await login("my.email@gmail.com", "12345678")
|
||||||
expect(res).toEqual({
|
expect(res).toEqual({
|
||||||
membre: {
|
membre: {
|
||||||
prenom: mockUser.prenom,
|
prenom: mockUser.prenom,
|
||||||
@ -27,29 +27,29 @@ describe("signIn with", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("invalid password length", async () => {
|
it("invalid password length", async () => {
|
||||||
await expect(signIn("my.email@gmail.com", "123")).rejects.toThrow("Mot de passe trop court")
|
await expect(login("my.email@gmail.com", "123")).rejects.toThrow("Mot de passe trop court")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("empty password", async () => {
|
it("empty password", async () => {
|
||||||
await expect(signIn("my.email@gmail.com", " ")).rejects.toThrow("Mot de passe nécessaire")
|
await expect(login("my.email@gmail.com", " ")).rejects.toThrow("Mot de passe nécessaire")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("wrong password", async () => {
|
it("wrong password", async () => {
|
||||||
await expect(signIn("my.email@gmail.com", "1234567891011")).rejects.toThrow(
|
await expect(login("my.email@gmail.com", "1234567891011")).rejects.toThrow(
|
||||||
"Mauvais mot de passe pour cet email"
|
"Mauvais mot de passe pour cet email"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("invalid email format", async () => {
|
it("invalid email format", async () => {
|
||||||
await expect(signIn("my.email@gmail", "12345678")).rejects.toThrow("Email invalid")
|
await expect(login("my.email@gmail", "12345678")).rejects.toThrow("Email invalid")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("empty email", async () => {
|
it("empty email", async () => {
|
||||||
await expect(signIn(" ", "12345678")).rejects.toThrow("Email invalid")
|
await expect(login(" ", "12345678")).rejects.toThrow("Email invalid")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("unknown email", async () => {
|
it("unknown email", async () => {
|
||||||
await expect(signIn("mon.emailBidon@gmail.com", "12345678")).rejects.toThrow(
|
await expect(login("mon.emailBidon@gmail.com", "12345678")).rejects.toThrow(
|
||||||
"Cet email ne correspond à aucun utilisateur"
|
"Cet email ne correspond à aucun utilisateur"
|
||||||
)
|
)
|
||||||
})
|
})
|
@ -5,7 +5,7 @@ import getAccessors from "../gsheets/accessors"
|
|||||||
|
|
||||||
const { listGet } = getAccessors("Membres", new Membre())
|
const { listGet } = getAccessors("Membres", new Membre())
|
||||||
|
|
||||||
export default async function signInHandler(
|
export default async function loginHandler(
|
||||||
request: Request,
|
request: Request,
|
||||||
response: Response,
|
response: Response,
|
||||||
_next: NextFunction
|
_next: NextFunction
|
||||||
@ -14,7 +14,7 @@ export default async function signInHandler(
|
|||||||
if (typeof request.body.email !== "string" || typeof request.body.password !== "string") {
|
if (typeof request.body.email !== "string" || typeof request.body.password !== "string") {
|
||||||
throw Error()
|
throw Error()
|
||||||
}
|
}
|
||||||
const res = await signIn(request.body.email, request.body.password)
|
const res = await login(request.body.email, request.body.password)
|
||||||
response.status(200).json(res)
|
response.status(200).json(res)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e.message) {
|
if (e.message) {
|
||||||
@ -25,7 +25,7 @@ export default async function signInHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function signIn(rawEmail: string, rawPassword: string): Promise<MemberLogin> {
|
export async function login(rawEmail: string, rawPassword: string): Promise<MemberLogin> {
|
||||||
const email = rawEmail.replace(/^\s*/, "").replace(/\s*$/, "")
|
const email = rawEmail.replace(/^\s*/, "").replace(/\s*$/, "")
|
||||||
if (!emailRegexp.test(email)) {
|
if (!emailRegexp.test(email)) {
|
||||||
throw Error("Email invalid")
|
throw Error("Email invalid")
|
Loading…
x
Reference in New Issue
Block a user