diff --git a/frontend/packages/vkt/src/tests/cypress/integration/examiner_redirect_page.spec.ts b/frontend/packages/vkt/src/tests/cypress/integration/examiner_redirect_page.spec.ts new file mode 100644 index 000000000..980830e57 --- /dev/null +++ b/frontend/packages/vkt/src/tests/cypress/integration/examiner_redirect_page.spec.ts @@ -0,0 +1,13 @@ +import { AppRoutes } from 'enums/app'; +import { examinerUser } from 'tests/msw/handlers'; + +describe('ExaminerRedirectPage', () => { + it('should redirect examiner to URL matching their own details', () => { + cy.openExaminerPage(); + cy.url().should('satisfy', (url) => + url.endsWith( + AppRoutes.ExaminerHomePage.replace(/:oid/, examinerUser.oid), + ), + ); + }); +}); diff --git a/frontend/packages/vkt/src/tests/cypress/support/commands.ts b/frontend/packages/vkt/src/tests/cypress/support/commands.ts index b5a2d95a8..0b060a1df 100644 --- a/frontend/packages/vkt/src/tests/cypress/support/commands.ts +++ b/frontend/packages/vkt/src/tests/cypress/support/commands.ts @@ -83,6 +83,14 @@ Cypress.Commands.add('openClerkCreateExamEventPage', () => { cy.visit(AppRoutes.ClerkExamEventCreatePage); }); +Cypress.Commands.add('openExaminerPage', () => { + cy.window().then((win) => { + win.sessionStorage.setItem('persist:root', '{}'); + cy.setCookie('cookie-consent-vkt', 'true'); + }); + cy.visit(AppRoutes.ExaminerRoot); +}); + Cypress.Commands.add('usePhoneViewport', () => { cy.viewport('iphone-6'); }); diff --git a/frontend/packages/vkt/src/tests/cypress/support/types/index.d.ts b/frontend/packages/vkt/src/tests/cypress/support/types/index.d.ts index 322f598af..45f49728e 100644 --- a/frontend/packages/vkt/src/tests/cypress/support/types/index.d.ts +++ b/frontend/packages/vkt/src/tests/cypress/support/types/index.d.ts @@ -21,6 +21,7 @@ declare global { openClerkExcellentLevelPage(): void; openClerkExamEventPage(examEventId: number): void; openClerkCreateExamEventPage(): void; + openExaminerPage(): void; usePhoneViewport(): void; goBack(): void; goForward(): void; diff --git a/frontend/packages/vkt/src/tests/msw/handlers.ts b/frontend/packages/vkt/src/tests/msw/handlers.ts index 360ca8019..8f8c0c67b 100644 --- a/frontend/packages/vkt/src/tests/msw/handlers.ts +++ b/frontend/packages/vkt/src/tests/msw/handlers.ts @@ -23,15 +23,29 @@ import { import { publicExamEvents11 } from 'tests/msw/fixtures/publicExamEvents11'; import { publicExaminers } from 'tests/msw/fixtures/publicExaminer'; +const clerkUser: ClerkUser = { + oid: '1.2.246.562.10.00000000001', + isAdmin: true, + isExaminer: false, +}; + +export const examinerUser: ClerkUser = { + oid: '1.2.246.562.10.30000000003', + isAdmin: false, + isExaminer: true, +}; + export const handlers = [ - http.get(APIEndpoints.ClerkUser, ({ cookies }) => { - const user: ClerkUser = { - oid: '1.2.246.562.10.00000000001', - isAdmin: true, - isExaminer: false, - }; + http.get(APIEndpoints.ClerkUser, ({ cookies, request }) => { + if (cookies.noAuth) { + return new Response('null'); + } + + if (request.referrer.endsWith(AppRoutes.ExaminerRoot)) { + return new Response(JSON.stringify(examinerUser)); + } - return new Response(cookies.noAuth ? 'null' : JSON.stringify(user)); + return new Response(JSON.stringify(clerkUser)); }), http.get(APIEndpoints.PublicUser, ({ cookies }) => { const person: PublicPerson = {