From 25444922bb61aed3d5fc78c518f6aa4931d1678c Mon Sep 17 00:00:00 2001 From: Ashley Gyngell Date: Wed, 5 Feb 2025 18:43:50 +0000 Subject: [PATCH] MAP-1878: update e2e mock --- cypress.config.ts | 10 +-- integration_tests/e2e/health.cy.ts | 1 + integration_tests/mockApis/feComponents.ts | 78 ++++++++++++++++++++++ 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 integration_tests/mockApis/feComponents.ts diff --git a/cypress.config.ts b/cypress.config.ts index 8a5d695..2dbd00b 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,10 +1,11 @@ import { defineConfig } from 'cypress' import { resetStubs } from './integration_tests/mockApis/wiremock' import auth from './integration_tests/mockApis/auth' -import tokenVerification from './integration_tests/mockApis/tokenVerification' -import prisonerSearch from './integration_tests/mockApis/prisonerSearch' +import feComponents from './integration_tests/mockApis/feComponents' import locations from './integration_tests/mockApis/locations' import prison from './integration_tests/mockApis/prison' +import prisonerSearch from './integration_tests/mockApis/prisonerSearch' +import tokenVerification from './integration_tests/mockApis/tokenVerification' export default defineConfig({ chromeWebSecurity: false, @@ -21,10 +22,11 @@ export default defineConfig({ on('task', { reset: resetStubs, ...auth, - ...tokenVerification, - ...prison, + ...feComponents, ...locations, + ...prison, ...prisonerSearch, + ...tokenVerification, }) }, baseUrl: 'http://localhost:3007', diff --git a/integration_tests/e2e/health.cy.ts b/integration_tests/e2e/health.cy.ts index 8d40eec..f40f11b 100644 --- a/integration_tests/e2e/health.cy.ts +++ b/integration_tests/e2e/health.cy.ts @@ -4,6 +4,7 @@ context('Healthcheck', () => { cy.task('reset') cy.task('stubAuthPing') cy.task('stubLocationsApiPing') + cy.task('stubFeComponentsPing') cy.task('stubPrisonApiPing') cy.task('stubPrisonerSearchApiPing') cy.task('stubTokenVerificationPing') diff --git a/integration_tests/mockApis/feComponents.ts b/integration_tests/mockApis/feComponents.ts new file mode 100644 index 0000000..336ebba --- /dev/null +++ b/integration_tests/mockApis/feComponents.ts @@ -0,0 +1,78 @@ +import type Service from '@ministryofjustice/hmpps-connect-dps-components/dist/types/Service' +import { stubFor } from './wiremock' +import { CaseLoad } from '../../server/data/interfaces/caseLoad' + +export default { + stubFeComponentsPing: () => + stubFor({ + request: { + method: 'GET', + urlPath: '/frontend-components/health/ping', + }, + response: { + status: 200, + }, + }), + + stubFeComponents: ( + options: { + caseLoads?: CaseLoad[] + services?: Service[] + residentialLocationsActive?: boolean + } = {}, + ) => { + const caseLoads = options.caseLoads || [ + { + caseLoadId: 'LEI', + currentlyActive: true, + description: 'Leeds (HMP)', + type: '', + caseloadFunction: '', + }, + ] + + return stubFor({ + request: { + method: 'GET', + urlPattern: '/frontend-components/components\\?.*', + }, + response: { + status: 200, + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + }, + jsonBody: { + header: { html: '', css: [], javascript: [] }, + footer: { html: '', css: [], javascript: [] }, + meta: { + caseLoads, + activeCaseLoad: caseLoads.find(caseLoad => caseLoad.currentlyActive === true), + services: options.services || [ + { + id: 'check-my-diary', + heading: 'Check my diary', + description: 'View your prison staff detail (staff rota) from home.', + href: 'http://localhost:3001', + navEnabled: true, + }, + { + id: 'key-worker-allocations', + heading: 'My key worker allocation', + description: 'View your key worker cases.', + href: 'http://localhost:3001/key-worker/111111', + navEnabled: true, + }, + { + id: 'residential-locations', + heading: 'Residential Locations', + description: 'Manage residential locations.', + href: 'http://localhost:3001/locations', + navEnabled: options.residentialLocationsActive, + }, + ], + }, + }, + }, + }) + }, +}