Skip to content

Commit e9abb16

Browse files
test: subscriber-endpoint-updated-in-test (#1593)
* added-initial-test * added-config-to-test * test-name-updated * initial-test-added * test-3881-updated * test-updated-to-include-superseded-fix * fixed-review-comment * updated-nhs-number-to-999 * test-config-updated * subscriber-status-config-added
1 parent 898af83 commit e9abb16

5 files changed

Lines changed: 62 additions & 42 deletions

File tree

tests/playwright-tests/src/api/distributionService/bsSelectService.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export const getRecordsFromExceptionManagementService = (
4545

4646
export const getRecordsFromNemsSubscription = (
4747
request: APIRequestContext,
48-
id: string
48+
nhsNumbers: string
4949
): Promise<ApiResponse> => {
50-
return apiClient.get(request, `${config.endpointNemsSubscriptionDataDataService}api/${config.nemsSubscriberDataService}${id}`);
50+
return apiClient.get(request, `${config.endpointNemsSubscriptionDataDataService}api/${config.nemsSubscriberDataService}?nhsNumber=${nhsNumbers}`);
5151
};
5252

5353
export function extractSubscriptionID(response: ApiResponse): string | null {
@@ -115,3 +115,34 @@ export const invalidServiceNowEndpoint = (
115115
return apiClient.post(request, endpoint, payload);
116116
};
117117

118+
export async function retry<T>(
119+
fn: () => Promise<T>,
120+
validate: (result: T) => boolean,
121+
options?: {
122+
retries?: number;
123+
delayMs?: number;
124+
throwLastError?: boolean;
125+
}
126+
): Promise<T> {
127+
const { retries = 5, delayMs = 2000, throwLastError = true } = options || {};
128+
let lastError: any;
129+
for (let attempt = 1; attempt <= retries; attempt++) {
130+
try {
131+
const result = await fn();
132+
if (validate(result)) {
133+
return result;
134+
}
135+
} catch (err) {
136+
lastError = err;
137+
}
138+
if (attempt < retries) {
139+
await new Promise(res => setTimeout(res, delayMs));
140+
}
141+
}
142+
if (throwLastError && lastError) {
143+
throw lastError;
144+
}
145+
throw new Error(`Retry validation failed after ${retries} attempts`);
146+
}
147+
148+

tests/playwright-tests/src/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const config = {
5656
routeBsSelectUnblockParticipant: 'api/UnblockParticipant',
5757
routeGetValidationExceptions: 'api/GetValidationExceptions',
5858
routeSerNowReceiveParticipant: 'api/servicenow/receive',
59-
nemsSubscriberDataService: 'CheckSubscriptionStatus?nhsNumber=',
59+
nemsSubscriberDataService: 'CheckSubscriptionStatus',
6060
invalidRouteSerNowEndpoint: 'api/serviceno/receive',
6161
cohortDistributionService: 'CohortDistributionDataService',
6262
participantManagementService: 'ParticipantManagementDataService',

tests/playwright-tests/src/tests/api/testFiles/@DTOSS-3881-01/ADD-participantPayload.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"inputParticipantRecord_test": {
2+
"inputParticipantRecord": {
33
"number": "CS0573846",
44
"u_case_variable_data": {
55
"nhs_number": "9997160908",
66
"forename_": "Jane",
77
"surname_family_name": "Doe",
88
"date_of_birth": "2010-10-22",
9-
"enter_dummy_gp_code": "ZZZDKL",
9+
"enter_dummy_gp_code": "",
1010
"BSO_code": "NORTH NOTTINGHAMSHIRE BREAST SCREENING OFFICE",
1111
"reason_for_adding": "requires_ceasing_following_surgery_bilateral_mastectomy"
1212
}
Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '../../fixtures/test-fixtures';
2-
import { extractSubscriptionID, getRecordsFromNemsSubscription, getRecordsFromParticipantDemographicService, getRecordsFromParticipantManagementService, receiveParticipantViaServiceNow } from "../../../api/distributionService/bsSelectService";
2+
import { extractSubscriptionID, getRecordsFromNemsSubscription, getRecordsFromParticipantDemographicService, getRecordsFromParticipantManagementService, receiveParticipantViaServiceNow, retry } from "../../../api/distributionService/bsSelectService";
33
import { composeValidators, expectStatus } from "../../../api/responseValidators";
44
import { ParticipantRecord } from '../../../interface/InputData';
55
import { loadParticipantPayloads } from '../../fixtures/jsonDataReader';
@@ -8,10 +8,10 @@ test.describe('@DTOSS-3881-01 @e2e @epic4c- Cohort Manger subscribed the Added r
88

99
let participantData: Record<string, ParticipantRecord>;
1010

11-
test.beforeAll(() => {
11+
test.beforeAll(async () => {
1212
const folderName = '@DTOSS-3881-01';
1313
const fileName = 'ADD-participantPayload.json';
14-
participantData = loadParticipantPayloads(folderName, fileName);
14+
participantData = await loadParticipantPayloads(folderName, fileName);
1515
});
1616

1717
test('@DTOSS-3881-01 DTOSS-10011 @not-runner-based - Verify subscription IDs on Nems table for ADD', {
@@ -22,7 +22,7 @@ test.describe('@DTOSS-3881-01 @e2e @epic4c- Cohort Manger subscribed the Added r
2222
}, async ({ request }, testInfo) => {
2323

2424
await test.step('Given Cohort manager receives data from ServiceNow and subscribed to PDS', async () => {
25-
const payload = participantData['inputParticipantRecord_test'];
25+
const payload = participantData['inputParticipantRecord'];
2626
const response = await receiveParticipantViaServiceNow(request, payload);
2727
const validators = composeValidators(
2828
expectStatus(202)
@@ -31,55 +31,44 @@ test.describe('@DTOSS-3881-01 @e2e @epic4c- Cohort Manger subscribed the Added r
3131
});
3232

3333
await test.step('Then NHSNumber, GivenName, FamilyName is written to Participant Demographic table', async () => {
34-
const response = await getRecordsFromParticipantDemographicService(request);
35-
34+
const response = await retry(
35+
() => getRecordsFromParticipantDemographicService(request),
36+
(res) =>
37+
res?.data?.[0]?.NhsNumber === 9997160908 &&
38+
res?.data?.[0]?.GivenName === "Jane" &&
39+
res?.data?.[0]?.FamilyName === "Doe",
40+
{ retries: 5, delayMs: 2000 }
41+
);
3642
expect(response?.data?.[0]?.NhsNumber).toBe(9997160908);
3743
expect(response?.data?.[0]?.GivenName).toBe("Jane");
3844
expect(response?.data?.[0]?.FamilyName).toBe("Doe");
3945
});
4046

4147
await test.step('And NHSNumber, ScreeningId, ReferralFlag is written to Participant Management table', async () => {
42-
const response = await getRecordsFromParticipantManagementService(request);
48+
const response = await retry(
49+
() => getRecordsFromParticipantManagementService(request),
50+
(res) =>
51+
res?.data?.[0]?.NHSNumber === 9997160908 &&
52+
res?.data?.[0]?.ScreeningId === 1 &&
53+
res?.data?.[0]?.ReferralFlag === 1,
54+
{ retries: 5, delayMs: 2000 }
55+
);
4356
expect(response?.data?.[0]?.NHSNumber).toBe(9997160908);
4457
expect(response?.data?.[0]?.ScreeningId).toBe(1);
4558
expect(response?.data?.[0]?.ReferralFlag).toBe(1);
4659
});
4760

48-
await test.step('Assert that NemsSubscription service is available', async () => {
49-
const nhsNumber = participantData['inputParticipantRecord_test'].u_case_variable_data.nhs_number;
61+
await test.step('DTOSS-10012 ADD verify NemsSubscription in NEMS_SUBSCRIPTION table', async () => {
62+
const nhsNumber = participantData['inputParticipantRecord'].u_case_variable_data.nhs_number;
5063
const response = await getRecordsFromNemsSubscription(request, nhsNumber);
5164
const validators = composeValidators(
5265
expectStatus(200)
5366
);
5467
await validators(response);
55-
});
56-
57-
await test.step(`DTOSS-10012 ADD verify NemsSubscription in NEMS_SUBSCRIPTION table`, async () => {
58-
const nhsNumber = participantData['inputParticipantRecord_test'].u_case_variable_data.nhs_number;
59-
60-
const response = await getRecordsFromNemsSubscription(request, nhsNumber);
6168
const subscriptionID = extractSubscriptionID(response);
62-
expect(response.status).toBe(200);
6369
expect(subscriptionID).not.toBeNull();
6470

6571
console.log(`Extracted Subscription ID: ${subscriptionID} for NHS number: ${nhsNumber}`);
6672
});
6773
});
68-
69-
test('@DTOSS-3881-02 DTOSS-10013 @not-runner-based AMEND verify NemsSubscription_id in NEMS_SUBSCRIPTION table', {
70-
annotation: [{
71-
type: 'Requirement - https://nhsd-jira.digital.nhs.uk/browse/DTOSS-3881',
72-
description: 'Tests - https://nhsd-jira.digital.nhs.uk/browse/DTOSS-10013',
73-
}]
74-
}, async ({ request }, testInfo) => {
75-
76-
const nhsNumber = '9996534472';
77-
78-
const response = await getRecordsFromNemsSubscription(request, nhsNumber);
79-
const subscriptionID = extractSubscriptionID(response);
80-
expect(response.status).toBe(200);
81-
expect(subscriptionID).not.toBeNull();
82-
83-
console.log(`Extracted Subscription ID: ${subscriptionID} for NHS number: ${nhsNumber}`);
84-
});
8574
});

tests/playwright-tests/src/tests/fixtures/jsonDataReader.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { config } from '../../config/env';
44
import { ParticipantRecord } from '../../interface/InputData';
55

66

7-
export function loadParticipantPayloads(folderName: string, fileName: string): Record<string, ParticipantRecord> {
7+
export async function loadParticipantPayloads(folderName: string, fileName: string): Promise<Record<string, ParticipantRecord>> {
88
const fullPath = path.join(process.cwd(), config.participantPayloadPath, folderName, fileName);
99
if (!fs.existsSync(fullPath)) {
10-
throw new Error(`File not found: ${fullPath}`);
10+
throw new Error(`File not found: ${fullPath}`);
1111
}
12-
const rawData = fs.readFileSync(fullPath, 'utf-8');
12+
const rawData = await fs.readFileSync(fullPath, 'utf-8');
1313
return JSON.parse(rawData);
1414
}
1515

16-
export function omitField<T extends object>(obj: T, fieldPath: string): Partial<T> {
16+
export async function omitField<T extends object>(obj: T, fieldPath: string): Promise<Partial<T>> {
1717
const result = JSON.parse(JSON.stringify(obj));
1818
const parts = fieldPath.split('.');
1919
let current: any = result;

0 commit comments

Comments
 (0)