diff --git a/package.json b/package.json index 9c616311e..63a2332f9 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "prepare": "husky" }, "dependencies": { + "@hmcts/ccd-event-runtime": "file:../../sdk/ccd-event-runtime", "@hmcts/info-provider": "^1.1.0", "@hmcts/nodejs-healthcheck": "^1.8.0", "@hmcts/nodejs-logging": "^4.0.4", diff --git a/src/main/generated/ccd/PCS/dto-types.ts b/src/main/generated/ccd/PCS/dto-types.ts new file mode 100644 index 000000000..c24fcdee1 --- /dev/null +++ b/src/main/generated/ccd/PCS/dto-types.ts @@ -0,0 +1,43 @@ +/* tslint:disable */ +/* eslint-disable */ + +export interface CreateClaimData { + propertyAddress: AddressUK; + legislativeCountry: LegislativeCountry; + feeAmount: string; + showCrossBorderPage: YesOrNo; + showPropertyNotEligiblePage: YesOrNo; + showPostcodeNotAssignedToCourt: YesOrNo; + crossBorderCountriesList: DynamicStringList; + crossBorderCountry1: string; + crossBorderCountry2: string; + postcodeNotAssignedView: string; +} + +export interface AddressUK extends Address { +} + +export interface DynamicStringList { + value: DynamicStringListElement; + list_items: DynamicStringListElement[]; + valueCode: string; +} + +export interface Address { + AddressLine1: string; + AddressLine2: string; + AddressLine3: string; + PostTown: string; + County: string; + PostCode: string; + Country: string; +} + +export interface DynamicStringListElement { + code: string; + label: string; +} + +export type LegislativeCountry = "England" | "Northern Ireland" | "Scotland" | "Wales" | "Isle of Man" | "Channel Islands"; + +export type YesOrNo = "Yes" | "No"; diff --git a/src/main/generated/ccd/PCS/event-contracts.ts b/src/main/generated/ccd/PCS/event-contracts.ts new file mode 100644 index 000000000..15ad2a1f0 --- /dev/null +++ b/src/main/generated/ccd/PCS/event-contracts.ts @@ -0,0 +1,18 @@ +// Generated by CCD SDK. Do not edit manually. +// Module: pcs +import { defineCaseBindings, type CcdCaseBindings } from "@hmcts/ccd-event-runtime"; +import type { CreateClaimData } from "./dto-types"; + +export interface EventDtoMap { + "createPossessionClaim": CreateClaimData; +} + +export const caseBindings = defineCaseBindings()({ + caseTypeId: "PCS", + events: { + "createPossessionClaim": { + fieldPrefix: "cpc", + pages: ["crossBorderPostcodeSelection", "enterPropertyAddress", "postcodeNotAssignedToCourt", "propertyNotEligible", "startTheService"], + }, + }, +} as const satisfies CcdCaseBindings); diff --git a/src/test/ui/utils/actions/custom-actions/createCaseTypedAPI.action.ts b/src/test/ui/utils/actions/custom-actions/createCaseTypedAPI.action.ts new file mode 100644 index 000000000..e4f3efdcb --- /dev/null +++ b/src/test/ui/utils/actions/custom-actions/createCaseTypedAPI.action.ts @@ -0,0 +1,59 @@ +import { Page } from '@playwright/test'; +// eslint-disable-next-line import/no-named-as-default +import Axios from 'axios'; +import { createCcdClient } from '@hmcts/ccd-event-runtime'; + +import { createCaseEventTokenApiData } from '../../../data/api-data'; +import { IAction, actionData, actionRecord } from '../../interfaces'; +import { caseInfo } from './createCaseAPI.action'; +import { caseBindings } from '../../../../../main/generated/ccd/PCS/event-contracts'; +import type { CreateClaimData } from '../../../../../main/generated/ccd/PCS/dto-types'; + +export class CreateCaseTypedAPIAction implements IAction { + async execute(page: Page, action: string, fieldName: actionData | actionRecord): Promise { + if (action !== 'createCaseTypedAPI') { + throw new Error(`No action found for '${action}'`); + } + await this.createCaseTypedAPI(fieldName); + } + + private async createCaseTypedAPI(caseData: actionData): Promise { + const requestConfig = createCaseEventTokenApiData.createCaseApiInstance(); + const baseUrl = requestConfig.baseURL; + if (!baseUrl) { + throw new Error('Missing DATA_STORE_URL_BASE for createCaseTypedAPI'); + } + + const createCaseApi = Axios.create(requestConfig); + const client = createCcdClient( + { + baseUrl, + getAuthHeaders: () => (requestConfig.headers ?? {}) as Record, + transport: { + get: async (url, headers) => (await createCaseApi.get(url, { headers })).data, + post: async (url, data, headers) => (await createCaseApi.post(url, data, { headers })).data, + }, + }, + caseBindings + ); + + const flow = await client.event('createPossessionClaim').start(); + const createCasePayloadData = ( + typeof caseData === 'object' && caseData !== null && 'data' in caseData ? caseData.data : caseData + ) as Partial; + const createResponse = await flow.submit({ + ...flow.data, + ...createCasePayloadData, + } as CreateClaimData); + const caseId = String(createResponse.id ?? ''); + + if (!caseId) { + throw new Error('Create case response did not include a case id'); + } + + process.env.CASE_NUMBER = caseId; + caseInfo.id = caseId; + caseInfo.fid = caseId.replace(/(.{4})(?=.)/g, '$1-'); + caseInfo.state = String(createResponse.state ?? ''); + } +} diff --git a/src/test/ui/utils/registry/action.registry.ts b/src/test/ui/utils/registry/action.registry.ts index 2bf71c5f7..8d552e750 100644 --- a/src/test/ui/utils/registry/action.registry.ts +++ b/src/test/ui/utils/registry/action.registry.ts @@ -6,6 +6,7 @@ import { RespondToClaimAction, TriggerErrorMessagesAction, } from '../actions/custom-actions'; +import { CreateCaseTypedAPIAction } from '../actions/custom-actions/createCaseTypedAPI.action'; import { CheckAction, ClickButtonAction, @@ -36,6 +37,7 @@ export class ActionRegistry { ['createUser', new LoginAction()], ['navigateToUrl', new NavigateToUrlAction()], ['createCaseAPI', new CreateCaseAPIAction()], + ['createCaseTypedAPI', new CreateCaseTypedAPIAction()], ['submitCaseAPI', new CreateCaseAPIAction()], ['selectLegalAdvice', new RespondToClaimAction()], ['inputDefendantDetails', new RespondToClaimAction()], diff --git a/yarn.lock b/yarn.lock index 392c5a661..163689378 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2069,6 +2069,13 @@ __metadata: languageName: node linkType: hard +"@hmcts/ccd-event-runtime@file:../../sdk/ccd-event-runtime::locator=pcs-frontend%40workspace%3A.": + version: 0.0.1 + resolution: "@hmcts/ccd-event-runtime@file:../../sdk/ccd-event-runtime#../../sdk/ccd-event-runtime::hash=70a76c&locator=pcs-frontend%40workspace%3A." + checksum: 10/5f5a2bced183e19deb4770985c866188c5a9806ebb898b7801c9758940f0098cb832b3e0ac4dc89a425f8d1c9df3bfc414bb83219484d36a4358c3e84abd3173 + languageName: node + linkType: hard + "@hmcts/info-provider@npm:^1.1.0": version: 1.3.0 resolution: "@hmcts/info-provider@npm:1.3.0" @@ -12623,6 +12630,7 @@ __metadata: "@eslint/eslintrc": "npm:^3.3.1" "@eslint/js": "npm:^9.29.0" "@eslint/plugin-kit": "npm:^0.5.0" + "@hmcts/ccd-event-runtime": "file:../../sdk/ccd-event-runtime" "@hmcts/info-provider": "npm:^1.1.0" "@hmcts/nodejs-healthcheck": "npm:^1.8.0" "@hmcts/nodejs-logging": "npm:^4.0.4"