Skip to content

Commit aae412a

Browse files
tests
1 parent 6939e07 commit aae412a

File tree

4 files changed

+28
-39
lines changed

4 files changed

+28
-39
lines changed

tests/constants/api_constants.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
export const SUPPLIER_LETTERS = 'letters';
2-
export const SUPPLIER_API_URL_SANDBOX = 'https://internal-dev-sandbox.api.service.nhs.uk/nhs-notify-supplier';
32
export const AWS_REGION = 'eu-west-2';
43
export const envName = process.env.PR_NUMBER ?? 'main';
54
export const API_NAME = `nhs-${envName}-supapi`;
65
export const LETTERSTABLENAME = `nhs-${envName}-supapi-letters`;
76
export const SUPPLIERID = 'TestSupplier1';
87
export const MI_ENDPOINT = 'mi';
8+
9+
const formattedPr = process.env.PR_NUMBER
10+
? process.env.PR_NUMBER.replace(/^pr(\d+)$/i, "PR-$1")
11+
: null;
12+
13+
// Build sandbox environment name
14+
const sandboxEnv = formattedPr
15+
? `nhs-notify-supplier-${formattedPr}`
16+
: "nhs-notify-supplier";
17+
export const SUPPLIER_API_URL_SANDBOX = `https://internal-dev-sandbox.api.service.nhs.uk/${sandboxEnv}`;

tests/sandbox/testCases/updateLetterStatus_testCases.ts

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export type ApiSandboxUpdateLetterStatusTestData = {
1616

1717
export const apiSandboxUpdateLetterStatusTestData: ApiSandboxUpdateLetterStatusTestData[] = [
1818
{
19-
testCase: '200 response if record is updated with status PENDING',
20-
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
19+
testCase: '202 response if record is updated with status PENDING',
20+
id: '24L5eYSWGzCHlGmzNxuqVusPxDg',
2121
header: sandBoxHeader,
2222
body: {
2323
data: {
@@ -28,47 +28,25 @@ export const apiSandboxUpdateLetterStatusTestData: ApiSandboxUpdateLetterStatusT
2828
},
2929
}
3030
},
31-
expectedStatus: 200,
32-
expectedResponse: {
33-
data: {
34-
type: 'Letter',
35-
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
36-
attributes: {
37-
status: 'PENDING',
38-
specificationId:'2WL5eYSWGzCHlGmzNxuqVusPxDg',
39-
},
40-
}
41-
},
31+
expectedStatus: 202,
4232
},
4333

4434
{
45-
testCase: '200 response if record is updated with status REJECTED',
46-
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
35+
testCase: '202 response if record is updated with status REJECTED',
36+
id: '24L5eYSWGzCHlGmzNxuqVusPxDg',
4737
header: sandBoxHeader,
4838
body: {
4939
data: {
5040
type: 'Letter',
5141
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
5242
attributes: {
5343
status: 'REJECTED',
54-
reasonCode: 'R01',
55-
reasonText: 'failed validation',
56-
},
57-
}
58-
},
59-
expectedStatus: 200,
60-
expectedResponse: {
61-
data: {
62-
type: 'Letter',
63-
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
64-
attributes: {
65-
reasonCode: 'R01',
66-
reasonText: 'failed validation',
67-
status: 'REJECTED',
68-
specificationId:'2WL5eYSWGzCHlGmzNxuqVusPxDg',
44+
reasonCode: 'R07',
45+
reasonText: 'No such address',
6946
},
7047
}
7148
},
49+
expectedStatus: 202,
7250
},
7351
{
7452
testCase: '404 response if no resource is found for the given id',
@@ -112,10 +90,10 @@ export const apiSandboxUpdateLetterStatusTestData: ApiSandboxUpdateLetterStatusT
11290
},
11391
expectedStatus: 400,
11492
expectedResponse: {
115-
message: 'request.body.data.attributes.status should be equal to one of the allowed values: PENDING, ACCEPTED, REJECTED, PRINTED, ENCLOSED, CANCELLED, DISPATCHED, DELIVERED, FAILED, RETURNED, DESTROYED, FORWARDED',
93+
message: 'request.body.data.attributes.status should be equal to one of the allowed values: PENDING, ACCEPTED, REJECTED, PRINTED, ENCLOSED, CANCELLED, DISPATCHED, DELIVERED, FAILED, RETURNED, FORWARDED',
11694
errors: [{
11795
path: '.body.data.attributes.status',
118-
message: 'should be equal to one of the allowed values: PENDING, ACCEPTED, REJECTED, PRINTED, ENCLOSED, CANCELLED, DISPATCHED, DELIVERED, FAILED, RETURNED, DESTROYED, FORWARDED',
96+
message: 'should be equal to one of the allowed values: PENDING, ACCEPTED, REJECTED, PRINTED, ENCLOSED, CANCELLED, DISPATCHED, DELIVERED, FAILED, RETURNED, FORWARDED',
11997
errorCode: 'enum.openapi.validation'
12098
}]
12199
},

tests/sandbox/testCases/updateMultipleStatus_testCases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type postRequest = {
2323

2424
export const apiSandboxMultipleLetterStatusTestData: ApiSandboxUpdateLetterStatusTestData[] =
2525
[{
26-
testCase: '200 response if records are updated',
26+
testCase: '202 response if records are updated',
2727
header: sandBoxHeader,
2828
body:{
2929
data :
@@ -106,7 +106,7 @@ export const apiSandboxMultipleLetterStatusTestData: ApiSandboxUpdateLetterStatu
106106
type: 'Letter'
107107
}
108108
]},
109-
expectedStatus: 200
109+
expectedStatus: 202
110110
},
111111
{
112112
testCase: '404 response if invalid request is passed',

tests/sandbox/updateLetterStatus.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ test.describe('Sandbox Tests To Update Letter Status', () =>
77
{
88
apiSandboxUpdateLetterStatusTestData.forEach(({ testCase, header, id, body, expectedStatus, expectedResponse }) => {
99
test(`Patch /Letters endpoint returns ${testCase}`, async ({ request }) => {
10-
1110
const response = await request.patch(`${SUPPLIER_API_URL_SANDBOX}/${SUPPLIER_LETTERS}/${id}` ,{
1211
headers: header,
1312
data: body
1413
});
1514

16-
const res = await response.json();
17-
expect(response.status()).toBe(expectedStatus);
18-
expect(res).toEqual(expectedResponse);
15+
console.log("URL", `${SUPPLIER_API_URL_SANDBOX}/${SUPPLIER_LETTERS}/${id}`);
1916

17+
expect(response.status()).toBe(expectedStatus);
18+
if (response.status() != 202){
19+
const res = await response.json();
20+
expect(res).toEqual(expectedResponse);
21+
}
2022
});
2123
});
2224
});

0 commit comments

Comments
 (0)