Skip to content

Commit

Permalink
VKT(Frontend): Add test verifying that examiner is redirected from ro…
Browse files Browse the repository at this point in the history
…ot examiner URL to their own view [deploy]
  • Loading branch information
pkoivisto committed Jan 17, 2025
1 parent 6dfbfb1 commit dbe3bc1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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),
),
);
});
});
8 changes: 8 additions & 0 deletions frontend/packages/vkt/src/tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare global {
openClerkExcellentLevelPage(): void;
openClerkExamEventPage(examEventId: number): void;
openClerkCreateExamEventPage(): void;
openExaminerPage(): void;
usePhoneViewport(): void;
goBack(): void;
goForward(): void;
Expand Down
28 changes: 21 additions & 7 deletions frontend/packages/vkt/src/tests/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit dbe3bc1

Please sign in to comment.