mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-08 08:34: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 { envieListGet, envieAdd } from "./gsheets/envies"
|
||||
import { membreGet, membreSet } from "./gsheets/membres"
|
||||
import signInHandler from "./userManagement/signIn"
|
||||
import loginHandler from "./userManagement/login"
|
||||
import config from "../config"
|
||||
|
||||
const app = express()
|
||||
@ -56,7 +56,7 @@ app.post("/MembreSet", membreSet)
|
||||
app.post("/EnvieAdd", envieAdd)
|
||||
|
||||
// Sign in & up API
|
||||
app.post("/api/user/login", signInHandler)
|
||||
app.post("/api/user/login", loginHandler)
|
||||
|
||||
// Use React server-side rendering middleware
|
||||
app.get("*", ssr)
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @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
|
||||
|
||||
@ -16,9 +16,9 @@ jest.mock("../../gsheets/accessors", () => () => ({
|
||||
listGet: () => [mockUser],
|
||||
}))
|
||||
|
||||
describe("signIn with", () => {
|
||||
describe("login with", () => {
|
||||
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({
|
||||
membre: {
|
||||
prenom: mockUser.prenom,
|
||||
@ -27,29 +27,29 @@ describe("signIn with", () => {
|
||||
})
|
||||
|
||||
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 () => {
|
||||
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 () => {
|
||||
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"
|
||||
)
|
||||
})
|
||||
|
||||
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 () => {
|
||||
await expect(signIn(" ", "12345678")).rejects.toThrow("Email invalid")
|
||||
await expect(login(" ", "12345678")).rejects.toThrow("Email invalid")
|
||||
})
|
||||
|
||||
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"
|
||||
)
|
||||
})
|
@ -5,7 +5,7 @@ import getAccessors from "../gsheets/accessors"
|
||||
|
||||
const { listGet } = getAccessors("Membres", new Membre())
|
||||
|
||||
export default async function signInHandler(
|
||||
export default async function loginHandler(
|
||||
request: Request,
|
||||
response: Response,
|
||||
_next: NextFunction
|
||||
@ -14,7 +14,7 @@ export default async function signInHandler(
|
||||
if (typeof request.body.email !== "string" || typeof request.body.password !== "string") {
|
||||
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)
|
||||
} catch (e: any) {
|
||||
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*$/, "")
|
||||
if (!emailRegexp.test(email)) {
|
||||
throw Error("Email invalid")
|
Loading…
x
Reference in New Issue
Block a user