diff --git a/README.md b/README.md index 84cac17bf..ef6f6ec37 100644 --- a/README.md +++ b/README.md @@ -65,16 +65,14 @@ Note: there is a test account you can use. Get this from another developer if yo - `GOOGLE_TAG_MANAGER_CONTAINER_ID` - Optional Google Tag Manager container ID - `NEXT_PUBLIC_MEDIA_FAVICON` - Application favicon image url - `NEXT_PUBLIC_MEDIA_LOGO` - Application logo image url -- `REWRITE_DOMAIN` - The domain which where new & old MPDX applications live. Set to `old.mpdx.org` for mpdx.org & `old-stage.mpdx.org` for staging. - `DATADOG_APP_ID` - Datadog tracking application ID. - `DATADOG_CLIENT_TOKEN` - Datadog tracking client token. - `DD_ENV` - Datadog environment. -- `BEACON_TOKEN` - HelpScout beacon token -- `HS_CONTACTS_SUGGESTIONS` - Comma-separated IDs of the HelpScout articles to suggest on the contacts page -- `HS_CONTACTS_CONTACT_SUGGESTIONS` - Comma-separated IDs of the HelpScout articles to suggest on the contact page -- `HS_HOME_SUGGESTIONS` - Comma-separated IDs of the HelpScout articles to suggest on the dashboard page -- `HS_REPORTS_SUGGESTIONS` - Comma-separated IDs of the HelpScout articles to suggest on the reports pages -- `HS_TASKS_SUGGESTIONS` - Comma-separated IDs of the HelpScout articles to suggest on the tasks page +- `HELPJUICE_ORIGIN` - Helpjuice origin for documentation and user support (example: `https://www.helpducks.org`) +- `HELPJUICE_KNOWLEDGE_BASE_URL` - Knowledge base page to make the Helpjuice "Visit Knowledge Base" page link to (example: `https://www.helpducks.org/mpdx`) +- `HELP_URL_COACHING_ACTIVITY` - Link to an article explaining the coaching activity table +- `HELP_URL_COACHING_APPOINTMENTS_AND_RESULTS` - Link to an article explaining the coaching appointments and results table +- `HELP_URL_SETUP_FIND_ORGANIZATION` - Link to an article explaining how to find an organization - `PRIVACY_POLICY_URL` - URL of the privacy policy - `TERMS_OF_USE_URL` - URL of the terms of use - `DISABLE_SETUP_TOUR` - Set to `true` to disable starting users on the welcome tour. This should be removed from the codebase once tools are live. diff --git a/__tests__/pages/api/MpdxWebHandoff.test.ts b/__tests__/pages/api/MpdxWebHandoff.test.ts deleted file mode 100644 index 9955b8db6..000000000 --- a/__tests__/pages/api/MpdxWebHandoff.test.ts +++ /dev/null @@ -1,314 +0,0 @@ -import { getToken } from 'next-auth/jwt'; -import { createMocks } from 'node-mocks-http'; -import mpdxWebHandoff from 'pages/api/mpdx-web-handoff.page'; -import { taskFiltersTabs } from 'src/utils/tasks/taskFilterTabs'; - -jest.mock('next-auth/jwt', () => ({ getToken: jest.fn() })); - -const siteUrl = process.env.SITE_URL; -const accountListsUrl = `${siteUrl}/accountLists`; -// User one -const userOneId = 'userId_1'; -const userOneToken = 'userOne.token'; -const userOneImpersonate = 'userOne.impersonate.token'; -// User two -const userTwoId = 'userId_2'; -const userTwoToken = 'userTwo.token'; -const userTwoImpersonate = 'userTwo.impersonate.token'; - -const convertCookieStringToObject = (cookieString) => { - return cookieString.split('; ').reduce((prev, current) => { - const [name, ...value] = current.split('='); - prev[name] = value.join('='); - return prev; - }, {}); -}; - -const grabCookies = (setCookieHeader: string[]): Cookies[] => { - const cookies: Cookies[] = []; - setCookieHeader.forEach((cookie) => - cookies.push(convertCookieStringToObject(cookie)), - ); - return cookies; -}; - -type Cookies = Record; - -describe('/api/mpdx-web-handoff', () => { - it('No accountListId or path defined. Redirect to home', async () => { - const { req, res } = createMocks({ method: 'GET' }); - await mpdxWebHandoff(req, res); - expect(res._getRedirectUrl()).toBe(`${siteUrl}/`); - }); - - const redirectUrl = `${siteUrl}/accountLists/accountListId/contacts`; - - describe('No prev session', () => { - beforeEach(() => { - (getToken as jest.Mock).mockReturnValue(null); - }); - it('New user - Redirect to login with correct cookies', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - path: '/contacts', - }, - }); - await mpdxWebHandoff(req, res); - expect(res._getRedirectUrl()).toBe(`${siteUrl}/login`); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - expect(cookies.length).toBe(2); - expect(cookies[0]['mpdx-handoff.redirect-url']).toBe(redirectUrl); - expect(cookies[1]['mpdx-handoff.logged-in']).toBe(`true`); - }); - - it('Impersonate user - Redirect to login with correct cookies', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - path: '/contacts', - userId: userOneId, - token: userOneToken, - impersonate: userOneImpersonate, - }, - }); - await mpdxWebHandoff(req, res); - expect(res._getRedirectUrl()).toBe(`${siteUrl}/login`); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - - expect(cookies.length).toBe(4); - expect(cookies[0]['mpdx-handoff.impersonate']).toBe(userOneImpersonate); - expect(cookies[1]['mpdx-handoff.redirect-url']).toBe(redirectUrl); - expect(cookies[2]['mpdx-handoff.token']).toBe(userOneToken); - expect(cookies[3]['mpdx-handoff.logged-in']).toBe(`true`); - }); - - it('No user - Redirect to home', async () => { - const { req, res } = createMocks({ method: 'GET' }); - await mpdxWebHandoff(req, res); - expect(res._getRedirectUrl()).toBe(`${siteUrl}/`); - }); - }); - - describe('Has active session', () => { - beforeEach(() => { - (getToken as jest.Mock).mockReturnValue({ - apiToken: userOneToken, - userID: userOneId, - }); - }); - - it('New user - Loggout prev user', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - path: '/contacts', - userId: userTwoId, - token: userTwoToken, - }, - }); - await mpdxWebHandoff(req, res); - expect(res._getRedirectUrl()).toBe( - `${siteUrl}/accountLists/accountListId/contacts`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - - expect(cookies.length).toBe(5); - expect(cookies[0]['__Secure-next-auth.session-token']).toBe(''); - expect(cookies[1]['next-auth.session-token']).toBe(''); - expect(cookies[0]['Max-Age']).toBe('0'); - expect(cookies[1]['Max-Age']).toBe('0'); - expect(cookies[2]['mpdx-handoff.accountConflictUserId']).toBe(userTwoId); - expect(cookies[3]['mpdx-handoff.redirect-url']).toBe(redirectUrl); - expect(cookies[4]['mpdx-handoff.token']).toBe(userTwoToken); - }); - - it('New user - Same token - Shouldnt remove prev user', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - path: '/contacts', - userId: userTwoId, - token: userOneToken, - }, - }); - await mpdxWebHandoff(req, res); - expect(res._getRedirectUrl()).toBe( - `${siteUrl}/accountLists/accountListId/contacts`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - - expect(cookies.length).toBe(5); - expect(cookies[0]['__Secure-next-auth.session-token']).toBe(''); - expect(cookies[1]['next-auth.session-token']).toBe(''); - expect(cookies[0]['Max-Age']).toBe('0'); - expect(cookies[1]['Max-Age']).toBe('0'); - expect(cookies[2]['mpdx-handoff.accountConflictUserId']).toBe(userTwoId); - expect(cookies[3]['mpdx-handoff.redirect-url']).toBe(redirectUrl); - expect(cookies[4]['mpdx-handoff.token']).toBe(userOneToken); - }); - - it('Impersonate user - Loggout prev user', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - path: '/contacts', - userId: userTwoId, - token: userTwoToken, - impersonate: userTwoImpersonate, - }, - }); - await mpdxWebHandoff(req, res); - expect(res._getRedirectUrl()).toBe( - `${siteUrl}/accountLists/accountListId/contacts`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - - expect(cookies.length).toBe(6); - expect(cookies[0]['__Secure-next-auth.session-token']).toBe(''); - expect(cookies[1]['next-auth.session-token']).toBe(''); - expect(cookies[0]['Max-Age']).toBe('0'); - expect(cookies[1]['Max-Age']).toBe('0'); - expect(cookies[2]['mpdx-handoff.accountConflictUserId']).toBe(userTwoId); - expect(cookies[3]['mpdx-handoff.redirect-url']).toBe(redirectUrl); - expect(cookies[4]['mpdx-handoff.token']).toBe(userTwoToken); - expect(cookies[5]['mpdx-handoff.impersonate']).toBe(userTwoImpersonate); - }); - - it('New user - Same token - Should logout prev user', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - path: '/contacts', - token: userOneToken, - }, - }); - await mpdxWebHandoff(req, res); - expect(res._getRedirectUrl()).toBe( - `${siteUrl}/accountLists/accountListId/contacts`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - expect(cookies.length).toBe(0); - }); - - it('Same user - Redirect to contact with url params', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - p1: 'p1', - p2: 'p2', - path: '/contacts', - }, - }); - await mpdxWebHandoff(req, res); - - expect(res._getRedirectUrl()).toBe( - `${accountListsUrl}/accountListId/contacts?p1=p1&p2=p2&`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - expect(cookies.length).toBe(0); - }); - it('Same user - Redirects to reports', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - path: '/reports', - }, - }); - await mpdxWebHandoff(req, res); - - expect(res._getRedirectUrl()).toBe( - `${accountListsUrl}/accountListId/reports`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - expect(cookies.length).toBe(0); - }); - - it('Same user - Redirects to reports with url params', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - p1: 'p1', - p2: 'p2', - path: '/reports', - }, - }); - await mpdxWebHandoff(req, res); - - expect(res._getRedirectUrl()).toBe( - `${accountListsUrl}/accountListId/reports?p1=p1&p2=p2&`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - expect(cookies.length).toBe(0); - }); - it('Same user - Redirects with tasks', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - path: '/tasks', - }, - }); - await mpdxWebHandoff(req, res); - - expect(res._getRedirectUrl()).toBe( - `${accountListsUrl}/accountListId/tasks`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - expect(cookies.length).toBe(0); - }); - - it('Same user - Redirects with tasks and group', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - group: 'today', - path: '/tasks', - }, - }); - await mpdxWebHandoff(req, res); - - const typeDetails = taskFiltersTabs.find( - (item) => item.name.toLowerCase() === 'today', - ); - - const filters = `filters=${encodeURIComponent( - JSON.stringify(typeDetails?.activeFiltersOptions), - )}`; - - expect(res._getRedirectUrl()).toBe( - `${accountListsUrl}/accountListId/tasks?${filters}`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - expect(cookies.length).toBe(0); - }); - - it('Same user - Redirects with none Contact/Report or Task path', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - modal: 'AddContact', - path: '/', - }, - }); - await mpdxWebHandoff(req, res); - - expect(res._getRedirectUrl()).toBe( - `${accountListsUrl}/accountListId/?modal=AddContact&`, - ); - const cookies = grabCookies(res._getHeaders()['set-cookie']); - expect(cookies.length).toBe(0); - }); - }); -}); diff --git a/__tests__/pages/api/NextAuth.test.ts b/__tests__/pages/api/NextAuth.test.ts index 4684ff50f..33d754577 100644 --- a/__tests__/pages/api/NextAuth.test.ts +++ b/__tests__/pages/api/NextAuth.test.ts @@ -15,8 +15,6 @@ const cookieCreator = (name: string, value: string) => { switch (name) { case '__Secure-next-auth.session-token': return `__Secure-next-auth.session-token=${value}; Secure; ${expireCookieDefaultInfo}`; - case 'mpdx-handoff.logged-in': - return `mpdx-handoff.logged-in=${value}; path=/; domain=${process.env.REWRITE_DOMAIN}`; default: return `${name}=${value}; ${expireCookieDefaultInfo}`; } diff --git a/__tests__/pages/api/handoff.test.ts b/__tests__/pages/api/handoff.test.ts deleted file mode 100644 index cbbe7ee8f..000000000 --- a/__tests__/pages/api/handoff.test.ts +++ /dev/null @@ -1,196 +0,0 @@ -import { getToken } from 'next-auth/jwt'; -import { createMocks } from 'node-mocks-http'; -import handoff from 'pages/api/handoff.page'; -import makeSsrClient from 'src/lib/apollo/ssrClient'; - -jest.mock('next-auth/jwt', () => ({ getToken: jest.fn() })); -jest.mock('src/lib/apollo/ssrClient', () => jest.fn()); - -describe('/api/handoff', () => { - const OLD_ENV = process.env; - beforeEach(() => { - jest.resetModules(); - process.env = { ...OLD_ENV, REWRITE_DOMAIN: 'stage.mpdx.org' }; - }); - - afterAll(() => { - process.env = OLD_ENV; - }); - it('returns 302', async () => { - const { req, res } = createMocks({ method: 'GET' }); - await handoff(req, res); - - expect(res._getStatusCode()).toBe(302); - }); - - describe('session', () => { - const defaultAccountList = 'defaultAccountList'; - beforeEach(() => { - (getToken as jest.Mock).mockReturnValue({ - apiToken: 'accessToken', - userID: 'sessionUserID', - }); - (makeSsrClient as jest.Mock).mockReturnValue({ - query: jest.fn().mockReturnValue({ - data: { user: { defaultAccountList } }, - }), - }); - }); - - describe('Staging env', () => { - const OLD_ENV = process.env; - beforeEach(() => { - jest.resetModules(); - process.env = { - ...OLD_ENV, - REWRITE_DOMAIN: 'stage.mpdx.org', - }; - }); - - afterAll(() => { - process.env = OLD_ENV; - }); - - it('returns redirect', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - userId: 'userId', - path: 'path', - }, - }); - await handoff(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - 'https://stage.mpdx.org/handoff?accessToken=accessToken&accountListId=accountListId&userId=userId&path=path', - ); - }); - - it('returns redirect but gets session userID', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - userId: '', - path: 'path', - }, - }); - await handoff(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - `https://stage.mpdx.org/handoff?accessToken=accessToken&accountListId=accountListId&userId=sessionUserID&path=path`, - ); - }); - - it('returns redirect but gets defaultAccountList', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: '', - userId: 'userId', - path: 'path', - }, - }); - await handoff(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - `https://stage.mpdx.org/handoff?accessToken=accessToken&accountListId=${defaultAccountList}&userId=userId&path=path`, - ); - }); - - it('returns redirect but gets first accountList id', async () => { - (makeSsrClient as jest.Mock).mockReturnValue({ - query: jest.fn().mockReturnValue({ - data: { - user: { defaultAccountList: '' }, - accountLists: { nodes: [{ id: 'accountID' }] }, - }, - }), - }); - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: '', - userId: 'userId', - path: 'path', - }, - }); - await handoff(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - `https://stage.mpdx.org/handoff?accessToken=accessToken&accountListId=accountID&userId=userId&path=path`, - ); - }); - - it('returns redirect for auth', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - path: 'auth/user/admin', - auth: 'true', - }, - }); - await handoff(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - 'https://auth.stage.mpdx.org/auth/user/admin?access_token=accessToken', - ); - }); - }); - - describe('Production env', () => { - const OLD_ENV = process.env; - - beforeEach(() => { - jest.resetModules(); - process.env = { - ...OLD_ENV, - REWRITE_DOMAIN: 'mpdx.org', - }; - }); - - afterAll(() => { - process.env = OLD_ENV; - }); - - it('returns redirect', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - userId: 'userId', - path: 'path', - }, - }); - await handoff(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - 'https://mpdx.org/handoff?accessToken=accessToken&accountListId=accountListId&userId=userId&path=path', - ); - }); - - it('returns redirect for auth', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - path: 'auth/user/admin', - auth: 'true', - }, - }); - await handoff(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - 'https://auth.mpdx.org/auth/user/admin?access_token=accessToken', - ); - }); - }); - }); -}); diff --git a/__tests__/pages/api/stopImpersonating.test.ts b/__tests__/pages/api/stopImpersonating.test.ts index f1c1e96f1..3377a3068 100644 --- a/__tests__/pages/api/stopImpersonating.test.ts +++ b/__tests__/pages/api/stopImpersonating.test.ts @@ -1,177 +1,14 @@ -import { getToken } from 'next-auth/jwt'; import { createMocks } from 'node-mocks-http'; import stopImpersonating from 'pages/api/stop-impersonating.page'; -import makeSsrClient from 'src/lib/apollo/ssrClient'; - -jest.mock('next-auth/jwt', () => ({ getToken: jest.fn() })); -jest.mock('src/lib/apollo/ssrClient', () => jest.fn()); -// User one -const userOneImpersonate = 'userOne.impersonate.token'; - -const convertCookieStringToObject = (cookieString) => { - return cookieString.split('; ').reduce((prev, current) => { - const [name, ...value] = current.split('='); - prev[name] = value.join('='); - return prev; - }, {}); -}; -type Cookies = Record; +import { clearNextAuthSessionCookies } from 'pages/api/utils/cookies'; describe('/api/stop-impersonating', () => { - const defaultAccountList = 'defaultAccountList'; - const OLD_ENV = process.env; - const siteUrl = 'https://next.mpdx.org'; - - beforeEach(() => { - jest.resetModules(); - process.env = { - ...OLD_ENV, - REWRITE_DOMAIN: 'mpdx.org', - SITE_URL: siteUrl, - }; - (getToken as jest.Mock).mockReturnValue({ - impersonatorApiToken: userOneImpersonate, - apiToken: 'accessToken', - userID: 'sessionUserID', - }); - (makeSsrClient as jest.Mock).mockReturnValue({ - query: jest.fn().mockReturnValue({ - data: { user: { defaultAccountList } }, - }), - }); - }); - - afterAll(() => { - process.env = OLD_ENV; - }); - - it('Returns user to home when error', async () => { - (makeSsrClient as jest.Mock).mockReturnValue({ - query: jest.fn().mockRejectedValueOnce(new Error('An Error Happened')), - }); - - const { req, res } = createMocks({ method: 'GET' }); - await stopImpersonating(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe('https://next.mpdx.org/'); - }); - - it('Returns user to legacy home when no values sent', async () => { + it('clears auth cookies and redirects the user', async () => { const { req, res } = createMocks({ method: 'GET' }); await stopImpersonating(req, res); expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - 'https://mpdx.org/handoff?accessToken=accessToken&accountListId=defaultAccountList&userId=sessionUserID&path=', - ); - }); - - it('Ensure Correct cookies are removed or added/edited', async () => { - const { req, res } = createMocks({ method: 'GET' }); - await stopImpersonating(req, res); - const cookies: Cookies[] = []; - res._getHeaders()['set-cookie'].forEach((cookie) => { - cookies.push(convertCookieStringToObject(cookie)); - }); - expect(cookies.length).toBe(4); - expect(cookies[0]['__Secure-next-auth.session-token']).toBe(''); - expect(cookies[1]['next-auth.session-token']).toBe(''); - expect(cookies[0]['Max-Age']).toBe('0'); - expect(cookies[1]['Max-Age']).toBe('0'); - expect(cookies[2]['mpdx-handoff.redirect-url']).toBe(`${siteUrl}/`); - expect(cookies[3]['mpdx-handoff.token']).toBe(userOneImpersonate); - }); - - it('Should redirect user to legacy site', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - userId: 'userId', - path: 'path', - }, - }); - await stopImpersonating(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - 'https://mpdx.org/handoff?accessToken=accessToken&accountListId=accountListId&userId=userId&path=path', - ); - }); - - it('Redirects user to legacy site using sessionUserID when userId not passed in', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: 'accountListId', - userId: '', - path: 'path', - }, - }); - await stopImpersonating(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - `https://mpdx.org/handoff?accessToken=accessToken&accountListId=accountListId&userId=sessionUserID&path=path`, - ); - }); - - it('Redirects user to legacy site but gets defaultAccountList', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: '', - userId: 'userId', - path: 'path', - }, - }); - await stopImpersonating(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - `https://mpdx.org/handoff?accessToken=accessToken&accountListId=${defaultAccountList}&userId=userId&path=path`, - ); - }); - - it('Redirects user to legacy site but gets first accountList id', async () => { - (makeSsrClient as jest.Mock).mockReturnValue({ - query: jest.fn().mockReturnValue({ - data: { - user: { defaultAccountList: '' }, - accountLists: { nodes: [{ id: 'accountID' }] }, - }, - }), - }); - const { req, res } = createMocks({ - method: 'GET', - query: { - accountListId: '', - userId: 'userId', - path: 'path', - }, - }); - await stopImpersonating(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - `https://mpdx.org/handoff?accessToken=accessToken&accountListId=accountID&userId=userId&path=path`, - ); - }); - - it('Redirect user to auth site', async () => { - const { req, res } = createMocks({ - method: 'GET', - query: { - path: 'auth/user/admin', - auth: 'true', - }, - }); - await stopImpersonating(req, res); - - expect(res._getStatusCode()).toBe(302); - expect(res._getRedirectUrl()).toBe( - 'https://auth.mpdx.org/auth/user/admin?access_token=accessToken', - ); + expect(res._getRedirectUrl()).toBe('/'); + expect(res.getHeaders()['set-cookie']).toEqual(clearNextAuthSessionCookies); }); }); diff --git a/__tests__/util/setup.ts b/__tests__/util/setup.ts index e10250bfe..5531f4bb1 100644 --- a/__tests__/util/setup.ts +++ b/__tests__/util/setup.ts @@ -25,8 +25,6 @@ expect.extend({ toHaveGraphqlOperation, }); -window.Beacon = jest.fn(); - window.document.createRange = (): Range => ({ setStart: jest.fn(), diff --git a/next.config.js b/next.config.js index 71c589551..638365c6e 100644 --- a/next.config.js +++ b/next.config.js @@ -41,7 +41,6 @@ const config = { SITE_URL: siteUrl, CLIENT_ID: process.env.CLIENT_ID ?? '4027334344069527005', CLIENT_SECRET: process.env.CLIENT_SECRET, - BEACON_TOKEN: process.env.BEACON_TOKEN, AUTH_PROVIDER: process.env.AUTH_PROVIDER ?? 'OKTA', OKTA_CLIENT_ID: process.env.OKTA_CLIENT_ID ?? '0oa1n0gjoy3j5Ycdg0h8', OKTA_CLIENT_SECRET: process.env.OKTA_CLIENT_SECRET, @@ -67,7 +66,6 @@ const config = { ONESKY_API_KEY: process.env.ONESKY_API_KEY, APP_NAME: process.env.APP_NAME ?? 'MPDX', ROLLBAR_SERVER_ACCESS_TOKEN: process.env.ROLLBAR_SERVER_ACCESS_TOKEN, - REWRITE_DOMAIN: process.env.REWRITE_DOMAIN ?? 'mpdx.org', DATADOG_APP_ID: process.env.DATADOG_APP_ID, DATADOG_CLIENT_TOKEN: process.env.DATADOG_CLIENT_TOKEN, DATADOG_CONFIGURED: Boolean( @@ -75,25 +73,13 @@ const config = { process.env.DATADOG_APP_ID && process.env.DATADOG_CLIENT_TOKEN, ).toString(), - HS_COACHING_ACTIVITY_SUMMARY: process.env.HS_COACHING_ACTIVITY_SUMMARY, - HS_COACHING_ACTIVITY: process.env.HS_COACHING_ACTIVITY, - HS_COACHING_APPOINTMENTS_AND_RESULTS: - process.env.HS_COACHING_APPOINTMENTS_AND_RESULTS, - HS_COACHING_COMMITMENTS: process.env.HS_COACHING_COMMITMENTS, - HS_COACHING_OUTSTANDING_RECURRING_COMMITMENTS: - process.env.HS_COACHING_OUTSTANDING_RECURRING_COMMITMENTS, - HS_COACHING_OUTSTANDING_SPECIAL_NEEDS: - process.env.HS_COACHING_OUTSTANDING_SPECIAL_NEEDS, - HS_COACHING_SUGGESTIONS: process.env.HS_COACHING_SUGGESTIONS, - HS_CONTACTS_CONTACT_SUGGESTIONS: - process.env.HS_CONTACTS_CONTACT_SUGGESTIONS, - HS_CONTACTS_SUGGESTIONS: process.env.HS_CONTACTS_SUGGESTIONS, - HS_HOME_SUGGESTIONS: process.env.HS_HOME_SUGGESTIONS, - HS_REPORTS_SUGGESTIONS: process.env.HS_REPORTS_SUGGESTIONS, - HS_TASKS_SUGGESTIONS: process.env.HS_TASKS_SUGGESTIONS, - HS_SETTINGS_SERVICES_SUGGESTIONS: - process.env.HS_SETTINGS_SERVICES_SUGGESTIONS, - HS_SETUP_FIND_ORGANIZATION: process.env.HS_SETUP_FIND_ORGANIZATION, + HELPJUICE_ORIGIN: process.env.HELPJUICE_ORIGIN, + HELPJUICE_KNOWLEDGE_BASE_URL: process.env.HELPJUICE_KNOWLEDGE_BASE_URL, + HELP_URL_COACHING_ACTIVITY: process.env.HELP_URL_COACHING_ACTIVITY, + HELP_URL_COACHING_APPOINTMENTS_AND_RESULTS: + process.env.HELP_URL_COACHING_APPOINTMENTS_AND_RESULTS, + HELP_URL_SETUP_FIND_ORGANIZATION: + process.env.HELP_URL_SETUP_FIND_ORGANIZATION, ALERT_MESSAGE: process.env.ALERT_MESSAGE, PRIVACY_POLICY_URL: process.env.PRIVACY_POLICY_URL, TERMS_OF_USE_URL: process.env.TERMS_OF_USE_URL, diff --git a/pages/_app.page.tsx b/pages/_app.page.tsx index 9cef845a7..20d37f3b7 100644 --- a/pages/_app.page.tsx +++ b/pages/_app.page.tsx @@ -21,7 +21,7 @@ import { I18nextProvider, useTranslation } from 'react-i18next'; import Rollbar from 'rollbar'; import DataDog from 'src/components/DataDog/DataDog'; import { GlobalStyles } from 'src/components/GlobalStyles/GlobalStyles'; -import HelpscoutBeacon from 'src/components/Helpscout/HelpscoutBeacon'; +import { Helpjuice } from 'src/components/Helpjuice/Helpjuice'; import PrimaryLayout from 'src/components/Layouts/Primary'; import Loading from 'src/components/Loading'; import { RouterGuard } from 'src/components/RouterGuard/RouterGuard'; @@ -36,7 +36,7 @@ import { useRequiredSession } from 'src/hooks/useRequiredSession'; import makeClient from 'src/lib/apollo/client'; import i18n from 'src/lib/i18n'; import theme from 'src/theme'; -import './helpscout.css'; +import './helpjuice.css'; import './print.css'; export type PageWithLayout = NextPage & { @@ -170,7 +170,6 @@ const App = ({ - @@ -203,6 +202,7 @@ const App = ({ + {process.env.ALERT_MESSAGE ? ( + {process.env.HELPJUICE_ORIGIN && ( + + )} + {/* The swifty.js script initializes in response to a DOMContentLoaded + * event, but that event has fired by the time the script is executed + * when using the Next.js