diff --git a/epictrack-web/cypress/support/utils.ts b/epictrack-web/cypress/support/utils.ts index e84e99fcd..a2776c87e 100644 --- a/epictrack-web/cypress/support/utils.ts +++ b/epictrack-web/cypress/support/utils.ts @@ -1,7 +1,16 @@ export function setupIntercepts(endpoints: any[]) { - endpoints.forEach(({ method, url, body }) => { - const response: any = { body }; + endpoints.forEach(({ method, url, response, name }) => { + // Add CORS headers specifically for OPTIONS requests + response = { + ...response, + headers: { + "Access-Control-Allow-Origin": "*", // Allow all domains + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", // Specify allowed methods + "Access-Control-Allow-Headers": "Content-Type, Authorization", // Specify allowed headers + }, + statusCode: 200, // Ensure the response is marked as successful + }; - cy.intercept(method, url, response); + cy.intercept(method, url, response).as(name); }); } diff --git a/epictrack-web/src/components/indigenousNation/__test__/IndigenousNationForm.cy.tsx b/epictrack-web/src/components/indigenousNation/__test__/IndigenousNationForm.cy.tsx index 655cc4e2d..de5f4eefc 100644 --- a/epictrack-web/src/components/indigenousNation/__test__/IndigenousNationForm.cy.tsx +++ b/epictrack-web/src/components/indigenousNation/__test__/IndigenousNationForm.cy.tsx @@ -5,33 +5,43 @@ import { mockStaffs, createMockMasterContext, } from "../../../../cypress/support/common"; -import { setupIntercepts } from "../../../../cypress/support/utils"; import { AppConfig } from "config"; +import { setupIntercepts } from "../../../../cypress/support/utils"; const endpoints = [ { + name: "getActiveStaffsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}staffs?is_active=false`, }, { + name: "getPIPTypeOptions", method: "OPTIONS", - url: `{AppConfig.apiUrl}pip-org-types`, + url: `${AppConfig.apiUrl}codes/pip_org_types`, + }, + + { + name: "getFirstNationsOptions", + method: "OPTIONS", + url: `${AppConfig.apiUrl}first_nations`, }, - { method: "OPTIONS", url: `${AppConfig.apiUrl}first_nations` }, { + name: "getActiveStaffs", method: "GET", url: `${AppConfig.apiUrl}staffs?is_active=false`, - body: { data: mockStaffs }, + response: { body: mockStaffs }, }, { + name: "getPIPType", method: "GET", url: `${AppConfig.apiUrl}pip-org-types`, - body: [], + response: { body: [] }, }, { + name: "getFirstNations", method: "GET", url: `${AppConfig.apiUrl}first_nations`, - body: [], + response: { body: [] }, }, ]; diff --git a/epictrack-web/src/components/project/__test__/ProjectList.cy.tsx b/epictrack-web/src/components/project/__test__/ProjectList.cy.tsx index cae241ab0..4895b8c9c 100644 --- a/epictrack-web/src/components/project/__test__/ProjectList.cy.tsx +++ b/epictrack-web/src/components/project/__test__/ProjectList.cy.tsx @@ -2,6 +2,7 @@ import { MemoryRouter as Router } from "react-router-dom"; import ProjectList from "../ProjectList"; import { generateMockProject } from "../../../../cypress/support/common"; import { AppConfig } from "config"; +import { setupIntercepts } from "../../../../cypress/support/utils"; const project1 = generateMockProject(); const project2 = generateMockProject(); @@ -32,12 +33,6 @@ const endpoints = [ }, ]; -function setupIntercepts(endpoints: any[]) { - endpoints.forEach(({ method, url, response, name }) => { - cy.intercept(method, url, response).as(name); - }); -} - describe("ProjectList", () => { beforeEach(() => { // This assumes you have a route set up for your projects in your commands.js diff --git a/epictrack-web/src/components/proponent/__test__/ProponentForm.cy.tsx b/epictrack-web/src/components/proponent/__test__/ProponentForm.cy.tsx index 201e038eb..d96d7d1a1 100644 --- a/epictrack-web/src/components/proponent/__test__/ProponentForm.cy.tsx +++ b/epictrack-web/src/components/proponent/__test__/ProponentForm.cy.tsx @@ -4,6 +4,7 @@ import ProponentForm from "../ProponentForm"; import { Staff } from "models/staff"; import { defaultProponent } from "models/proponent"; import { AppConfig } from "config"; +import { setupIntercepts } from "../../../../cypress/support/utils"; const staffs: Staff[] = [ { @@ -33,28 +34,38 @@ const staffs: Staff[] = [ const endpoints = [ { + name: "getActiveStaffsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}staffs?is_active=false`, }, { + name: "getPIPTypeOptions", method: "OPTIONS", - url: `${AppConfig.apiUrl}pip-org-types`, + url: `${AppConfig.apiUrl}codes/pip_org_types`, }, - { method: "OPTIONS", url: `${AppConfig.apiUrl}first_nations` }, + { + name: "getFirstNationsOptions", + method: "OPTIONS", + url: `${AppConfig.apiUrl}first_nations`, + }, + { + name: "getActiveStaffs", method: "GET", url: `${AppConfig.apiUrl}staffs?is_active=false`, - body: { data: staffs }, + response: { body: staffs }, }, { + name: "getPIPType", method: "GET", url: `${AppConfig.apiUrl}pip-org-types`, - body: [], + response: { body: [] }, }, { + name: "getFirstNations", method: "GET", url: `${AppConfig.apiUrl}first_nations`, - body: [], + response: { body: [] }, }, ]; @@ -80,17 +91,11 @@ function createMockContext() { setDialogProps: cy.stub(), }; } -function setupIntercepts(endpoints: any[]) { - endpoints.forEach(({ method, url, body }) => { - cy.intercept(method, url, { body }); - }); -} describe("ProponentForm", () => { beforeEach(() => { const mockContext = createMockContext(); setupIntercepts(endpoints); - cy.mount( diff --git a/epictrack-web/src/components/proponent/__test__/ProponentList.cy.tsx b/epictrack-web/src/components/proponent/__test__/ProponentList.cy.tsx index c620c1396..e248c0d1e 100644 --- a/epictrack-web/src/components/proponent/__test__/ProponentList.cy.tsx +++ b/epictrack-web/src/components/proponent/__test__/ProponentList.cy.tsx @@ -9,8 +9,9 @@ import { mockStaffs, testTableFiltering, } from "../../../../cypress/support/common"; -import { setupIntercepts } from "../../../../cypress/support/utils"; import { AppConfig } from "config"; +import { setupIntercepts } from "../../../../cypress/support/utils"; + //ensure proponents are never the same by incrementing the counter let proponentCounter = 0; @@ -31,31 +32,38 @@ const proponents = [proponent1, proponent2]; const endpoints = [ { + name: "getActiveStaffsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}staffs?is_active=false`, }, { + name: "getPIPTypeOptions", method: "OPTIONS", - url: `${AppConfig.apiUrl}pip-org-types`, + url: `${AppConfig.apiUrl}codes/pip_org_types`, }, + { + name: "getFirstNationsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}first_nations`, }, { + name: "getActiveStaff", method: "GET", url: `${AppConfig.apiUrl}staffs?is_active=false`, - body: { data: mockStaffs }, + response: { body: mockStaffs }, }, { + name: "getPIPType", method: "GET", url: `${AppConfig.apiUrl}pip-org-types`, - body: [], + response: { body: [] }, }, { + name: "getFirstNations", method: "GET", url: `${AppConfig.apiUrl}first_nations`, - body: [], + response: { body: [] }, }, ]; diff --git a/epictrack-web/src/components/shared/__test__/MasterTrackTable.cy.tsx b/epictrack-web/src/components/shared/__test__/MasterTrackTable.cy.tsx index 42015b3c2..1d2c8b2d0 100644 --- a/epictrack-web/src/components/shared/__test__/MasterTrackTable.cy.tsx +++ b/epictrack-web/src/components/shared/__test__/MasterTrackTable.cy.tsx @@ -9,7 +9,6 @@ import { generateMockProject, testTableFiltering, } from "../../../../cypress/support/common"; -import { setupIntercepts } from "../../../../cypress/support/utils"; import { defaultFirstNation } from "models/firstNation"; import { MasterContext } from "components/shared/MasterContext"; import { ETGridTitle } from ".."; @@ -19,6 +18,7 @@ import { FirstNation } from "models/firstNation"; import { MemoryRouter as Router } from "react-router-dom"; import { Project } from "models/project"; import { AppConfig } from "config"; +import { setupIntercepts } from "../../../../cypress/support/utils"; // Mock reducer declare global { @@ -29,28 +29,22 @@ declare global { const endpoints = [ { - method: "OPTIONS", - url: `${AppConfig.apiUrl}staffs?is_active=false`, - }, - { - method: "OPTIONS", - url: `${AppConfig.apiUrl}pip-org-types`, - }, - { method: "OPTIONS", url: `${AppConfig.apiUrl}first_nations` }, - { + name: "getActiveStaffs", method: "GET", url: `${AppConfig.apiUrl}staffs?is_active=false`, - body: { data: mockStaffs }, + response: { body: { data: mockStaffs } }, }, { + name: "getPIPType", method: "GET", url: `${AppConfig.apiUrl}pip-org-types`, - body: [], + response: { body: [] }, }, { + name: "getFirstNations", method: "GET", url: `${AppConfig.apiUrl}first_nations`, - body: [], + response: { body: [] }, }, ]; diff --git a/epictrack-web/src/components/shared/__test__/SpecialField.cy.tsx b/epictrack-web/src/components/shared/__test__/SpecialField.cy.tsx index d984e77fb..d129c7120 100644 --- a/epictrack-web/src/components/shared/__test__/SpecialField.cy.tsx +++ b/epictrack-web/src/components/shared/__test__/SpecialField.cy.tsx @@ -4,7 +4,6 @@ import { SpecialFieldEntityEnum, SPECIAL_FIELDS, } from "../../../constants/application-constant"; - import { setupIntercepts } from "../../../../cypress/support/utils"; import { faker } from "@faker-js/faker"; import { AppConfig } from "config"; diff --git a/epictrack-web/src/components/staff/__test__/StaffForm.cy.tsx b/epictrack-web/src/components/staff/__test__/StaffForm.cy.tsx index fbfdc53c9..e34fc122d 100644 --- a/epictrack-web/src/components/staff/__test__/StaffForm.cy.tsx +++ b/epictrack-web/src/components/staff/__test__/StaffForm.cy.tsx @@ -5,33 +5,49 @@ import { createMockMasterContext, mockStaffs, } from "../../../../cypress/support/common"; -import { setupIntercepts } from "../../../../cypress/support/utils"; import { AppConfig } from "config"; +import { setupIntercepts } from "../../../../cypress/support/utils"; const endpoints = [ { + name: "getActiveStaffsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}staffs?is_active=false`, }, { + name: "getPIPTypeOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}codes/pip_org_types`, }, - { method: "OPTIONS", url: `${AppConfig.apiUrl}first_nations` }, + + { + name: "getFirstNationsOptions", + method: "OPTIONS", + url: `${AppConfig.apiUrl}first_nations`, + }, { + name: "getActiveStaffs", method: "GET", url: `${AppConfig.apiUrl}staffs?is_active=false`, - body: { data: mockStaffs }, + response: { body: { data: mockStaffs } }, }, { + name: "getPIPType", method: "GET", url: `${AppConfig.apiUrl}codes/pip_org_types`, - body: [], + response: { body: [] }, }, { + name: "getFirstNations", method: "GET", url: `${AppConfig.apiUrl}first_nations`, - body: [], + response: { body: [] }, + }, + { + name: "getPositions", + method: "GET", + url: `${AppConfig.apiUrl}positions`, + response: { body: [] }, }, ]; diff --git a/epictrack-web/src/components/staff/__test__/StaffList.cy.tsx b/epictrack-web/src/components/staff/__test__/StaffList.cy.tsx index a657c7631..b097e0528 100644 --- a/epictrack-web/src/components/staff/__test__/StaffList.cy.tsx +++ b/epictrack-web/src/components/staff/__test__/StaffList.cy.tsx @@ -10,8 +10,8 @@ import { mockStaffs, testTableFiltering, } from "../../../../cypress/support/common"; -import { setupIntercepts } from "../../../../cypress/support/utils"; import { AppConfig } from "config"; +import { setupIntercepts } from "../../../../cypress/support/utils"; //ensure staffs are never the same by incrementing the counter let staffCounter = 0; @@ -38,31 +38,38 @@ const staffs = [staff1, staff2]; const endpoints = [ { + name: "getActiveStaffsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}staffs?is_active=false`, }, { + name: "getPIPTypeOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}codes/pip_org_types`, }, + { + name: "getFirstNationsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}first_nations`, }, { + name: "getInactiveStaffs", method: "GET", url: `${AppConfig.apiUrl}staffs?is_active=false`, - body: { data: mockStaffs }, + response: { body: { data: mockStaffs } }, }, { + name: "getPIPType", method: "GET", url: `${AppConfig.apiUrl}codes/pip_org_types`, - body: [], + response: { body: [] }, }, { + name: "getFirstNations", method: "GET", url: `${AppConfig.apiUrl}first_nations`, - body: [], + response: { body: [] }, }, ]; diff --git a/epictrack-web/src/components/user/__test__/UserList.cy.tsx b/epictrack-web/src/components/user/__test__/UserList.cy.tsx index bd7d2a27d..91be009d3 100644 --- a/epictrack-web/src/components/user/__test__/UserList.cy.tsx +++ b/epictrack-web/src/components/user/__test__/UserList.cy.tsx @@ -39,45 +39,54 @@ const users = [user1, user2]; const endpoints = [ { + name: "getInactiveStaffsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}staffs?is_active=false`, }, { + name: "getPIPTypeOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}codes/pip_org_types`, }, { + name: "getFirstNationsOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}first_nations`, }, { + name: "getInactiveStaffs", method: "GET", url: `${AppConfig.apiUrl}staffs?is_active=false`, - body: mockStaffs, + response: { body: mockStaffs }, }, { + name: "getPIPType", method: "GET", url: `${AppConfig.apiUrl}codes/pip_org_types`, - body: [], + response: { body: [] }, }, { + name: "getFirstNations", method: "GET", url: `${AppConfig.apiUrl}first_nations`, - body: [], + response: { body: [] }, }, { + name: "getUsersOptions", method: "OPTIONS", url: `${AppConfig.apiUrl}users/groups`, }, { + name: "getUsers", method: "GET", url: `${AppConfig.apiUrl}users`, - body: users, + response: { body: users }, }, { + name: "getGroups", method: "GET", url: `${AppConfig.apiUrl}users/groups`, - body: [user1.group, user2.group], + response: { body: [user1.group, user2.group] }, }, ]; diff --git a/epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx b/epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx index 983f1ffa1..5195c9d70 100644 --- a/epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx +++ b/epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx @@ -6,6 +6,7 @@ import { userDetails } from "services/userService/userSlice"; import { store } from "store"; import { UserDetail } from "services/userService/type"; import { AppConfig } from "config"; +import { setupIntercepts } from "../../../../../cypress/support/utils"; const generateFakePosition = () => { return { @@ -178,12 +179,6 @@ const endpoints = [ }, ]; -function setupIntercepts(endpoints: any[]) { - endpoints.forEach(({ method, url, response, name }) => { - cy.intercept(method, url, response).as(name); - }); -} - describe("WorkForm", () => { beforeEach(() => { setupIntercepts(endpoints);