From 960bd2ecb53081981cb1cdbf47d3d6e9a9798386 Mon Sep 17 00:00:00 2001 From: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com> Date: Tue, 22 Nov 2022 13:13:43 +0800 Subject: [PATCH] feat: allow adding a default user session --- src/fixtures/app.ts | 24 ++++++++++++++++++++++++ src/fixtures/sessionData.ts | 28 ++++++++++++++++++++++++++++ src/fixtures/sites.ts | 2 ++ src/fixtures/users.ts | 9 +++++++++ 4 files changed, 63 insertions(+) create mode 100644 src/fixtures/sites.ts create mode 100644 src/fixtures/users.ts diff --git a/src/fixtures/app.ts b/src/fixtures/app.ts index c8d43b5ad..e3f5dcaa7 100644 --- a/src/fixtures/app.ts +++ b/src/fixtures/app.ts @@ -14,7 +14,9 @@ import { mockUserSessionData, mockUserWithSiteSessionData, mockGithubSessionData, + MOCK_USER_SESSION_DATA_ONE, } from "./sessionData" +import { MOCK_SITE_NAME_ONE } from "./sites" /** * @deprecated @@ -72,6 +74,28 @@ const attachUserSessionDataWithSite: ( next() } +const attachDefaultUserSessionData: RequestHandler< + unknown, + unknown, + unknown, + unknown, + { userSessionData: UserSessionData } +> = attachUserSessionData(MOCK_USER_SESSION_DATA_ONE) + +const attachDefaultUserSessionDataWithSite: RequestHandler< + unknown, + unknown, + unknown, + unknown, + { + userSessionData: UserSessionData + userWithSiteSessionData: UserWithSiteSessionData + } +> = attachUserSessionDataWithSite( + MOCK_USER_SESSION_DATA_ONE, + MOCK_SITE_NAME_ONE +) + /** * @deprecated */ diff --git a/src/fixtures/sessionData.ts b/src/fixtures/sessionData.ts index 756ddc107..3898ce3b6 100644 --- a/src/fixtures/sessionData.ts +++ b/src/fixtures/sessionData.ts @@ -2,6 +2,17 @@ import GithubSessionData from "@root/classes/GithubSessionData" import UserSessionData from "@root/classes/UserSessionData" import UserWithSiteSessionData from "@root/classes/UserWithSiteSessionData" +import { + MOCK_USER_EMAIL_ONE, + MOCK_USER_EMAIL_TWO, + MOCK_USER_EMAIL_THREE, + MOCK_USER_EMAIL_FOUR, + MOCK_USER_ID_ONE, + MOCK_USER_ID_TWO, + MOCK_USER_ID_THREE, + MOCK_USER_ID_FOUR, +} from "./users" + export const mockAccessToken = "mockAccessToken" export const mockGithubId = "mockGithubId" export const mockIsomerUserId = "1" @@ -43,3 +54,20 @@ export const mockSessionDataEmailUserWithSite = new UserWithSiteSessionData({ email: mockEmail, siteName: mockSiteName, }) + +export const MOCK_USER_SESSION_DATA_ONE = new UserSessionData({ + isomerUserId: String(MOCK_USER_ID_ONE), + email: MOCK_USER_EMAIL_ONE, +}) +export const MOCK_USER_SESSION_DATA_TWO = new UserSessionData({ + isomerUserId: String(MOCK_USER_ID_TWO), + email: MOCK_USER_EMAIL_TWO, +}) +export const MOCK_USER_SESSION_DATA_THREE = new UserSessionData({ + isomerUserId: String(MOCK_USER_ID_THREE), + email: MOCK_USER_EMAIL_THREE, +}) +export const MOCK_USER_SESSION_DATA_FOUR = new UserSessionData({ + isomerUserId: String(MOCK_USER_ID_FOUR), + email: MOCK_USER_EMAIL_FOUR, +}) diff --git a/src/fixtures/sites.ts b/src/fixtures/sites.ts new file mode 100644 index 000000000..5b282c0b4 --- /dev/null +++ b/src/fixtures/sites.ts @@ -0,0 +1,2 @@ +export const MOCK_SITE_NAME_ONE = "test-site-one" +export const MOCK_SITE_NAME_TWO = "test-site-two" diff --git a/src/fixtures/users.ts b/src/fixtures/users.ts new file mode 100644 index 000000000..4212b4b34 --- /dev/null +++ b/src/fixtures/users.ts @@ -0,0 +1,9 @@ +export const MOCK_USER_ID_ONE = 1 +export const MOCK_USER_ID_TWO = 2 +export const MOCK_USER_ID_THREE = 3 +export const MOCK_USER_ID_FOUR = 4 + +export const MOCK_USER_EMAIL_ONE = "one@test.gov.sg" +export const MOCK_USER_EMAIL_TWO = "two@test.gov.sg" +export const MOCK_USER_EMAIL_THREE = "three@test.gov.sg" +export const MOCK_USER_EMAIL_FOUR = "four@test.gov.sg"