Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions src/main/generated/ccd/PCS/dto-types.ts
Original file line number Diff line number Diff line change
@@ -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";
18 changes: 18 additions & 0 deletions src/main/generated/ccd/PCS/event-contracts.ts
Original file line number Diff line number Diff line change
@@ -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<EventDtoMap>()({
caseTypeId: "PCS",
events: {
"createPossessionClaim": {
fieldPrefix: "cpc",
pages: ["crossBorderPostcodeSelection", "enterPropertyAddress", "postcodeNotAssignedToCourt", "propertyNotEligible", "startTheService"],
},
},
} as const satisfies CcdCaseBindings<EventDtoMap>);
Original file line number Diff line number Diff line change
@@ -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<void> {
if (action !== 'createCaseTypedAPI') {
throw new Error(`No action found for '${action}'`);
}
await this.createCaseTypedAPI(fieldName);
}

private async createCaseTypedAPI(caseData: actionData): Promise<void> {
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<string, string>,
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<CreateClaimData>;
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 ?? '');
}
}
2 changes: 2 additions & 0 deletions src/test/ui/utils/registry/action.registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
RespondToClaimAction,
TriggerErrorMessagesAction,
} from '../actions/custom-actions';
import { CreateCaseTypedAPIAction } from '../actions/custom-actions/createCaseTypedAPI.action';
import {
CheckAction,
ClickButtonAction,
Expand Down Expand Up @@ -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()],
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down