From 2d814f44be5241c38aed9511de8bb9087ad34677 Mon Sep 17 00:00:00 2001 From: wanlingt Date: Tue, 14 Nov 2023 17:02:51 +0800 Subject: [PATCH] fix: use ADMIN_LOGIN_SESSION_COOKIE_NAME constant for tests --- .../routes/api/v3/auth/__tests__/auth.routes.spec.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/app/routes/api/v3/auth/__tests__/auth.routes.spec.ts b/src/app/routes/api/v3/auth/__tests__/auth.routes.spec.ts index eb77ef48c0..63279c91bb 100644 --- a/src/app/routes/api/v3/auth/__tests__/auth.routes.spec.ts +++ b/src/app/routes/api/v3/auth/__tests__/auth.routes.spec.ts @@ -6,6 +6,7 @@ import { errAsync, okAsync } from 'neverthrow' import supertest, { Session } from 'supertest-session' import validator from 'validator' +import { ADMIN_LOGIN_SESSION_COOKIE_NAME } from 'src/app/loaders/express/session' import MailService from 'src/app/services/mail/mail.service' import { HashingError } from 'src/app/utils/hash' import * as OtpUtils from 'src/app/utils/otp' @@ -511,7 +512,7 @@ describe('auth.routes', () => { }) // Should have session cookie returned. const sessionCookie = request.cookies.find( - (cookie) => cookie.name === 'formsg.connect.sid', + (cookie) => cookie.name === ADMIN_LOGIN_SESSION_COOKIE_NAME, ) expect(sessionCookie).toBeDefined() }) @@ -538,7 +539,7 @@ describe('auth.routes', () => { }) // Should have session cookie returned. const sessionCookie = request.cookies.find( - (cookie) => cookie.name === 'formsg.connect.sid', + (cookie) => cookie.name === ADMIN_LOGIN_SESSION_COOKIE_NAME, ) expect(sessionCookie).toBeDefined() }) @@ -591,9 +592,9 @@ describe('auth.routes', () => { // Assert expect(response.status).toEqual(200) expect(response.body).toEqual({ message: 'Sign out successful' }) - // formsg.connect.sid should now be empty. + // Login cookie should now be empty. expect(response.header['set-cookie'][0]).toEqual( - expect.stringContaining('formsg.connect.sid=;'), + expect.stringContaining(`${ADMIN_LOGIN_SESSION_COOKIE_NAME}=;`), ) }) @@ -629,7 +630,7 @@ describe('auth.routes', () => { // Assert // Should have session cookie returned. const sessionCookie = request.cookies.find( - (cookie) => cookie.name === 'formsg.connect.sid', + (cookie) => cookie.name === ADMIN_LOGIN_SESSION_COOKIE_NAME, ) expect(sessionCookie).toBeDefined() return response.body