Skip to content

Commit fdc6a52

Browse files
add sandbox tests
1 parent 9d2d436 commit fdc6a52

9 files changed

Lines changed: 225 additions & 0 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, test } from "@playwright/test";
2+
import {
3+
MI_ENDPOINT,
4+
SUPPLIER_API_URL_SANDBOX,
5+
} from "tests/constants/api-constants";
6+
import { apiSandboxCreateMiTestData } from "./testCases/create-mi-test-cases";
7+
8+
test.describe("Sandbox Tests To Verify Mi Endpoint", () => {
9+
for (const {
10+
body,
11+
expectedResponse,
12+
expectedStatus,
13+
header,
14+
testCase,
15+
} of apiSandboxCreateMiTestData) {
16+
test(`Post /Mi endpoint returns ${testCase}`, async ({ request }) => {
17+
const response = await request.post(
18+
`${SUPPLIER_API_URL_SANDBOX}/${MI_ENDPOINT}`,
19+
{
20+
headers: header,
21+
data: body,
22+
},
23+
);
24+
expect(response.status()).toBe(expectedStatus);
25+
const responseBody = await response.json();
26+
expect(responseBody).toMatchObject(expectedResponse);
27+
});
28+
}
29+
});

tests/sandbox/create-mi.spec.ts

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { expect, test } from "@playwright/test";
2+
import {
3+
SUPPLIER_API_URL_SANDBOX,
4+
SUPPLIER_LETTERS,
5+
} from "../constants/api-constants";
6+
import {
7+
RequestSandBoxHeaders,
8+
sandBoxHeader,
9+
} from "../constants/request-headers";
10+
11+
test.describe("Sandbox Tests To Get Letter Data", () => {
12+
test(`Get Letter Data endpoint returns 200 for valid id`, async ({
13+
request,
14+
}) => {
15+
const id = "2AL5eYSWGzCHlGmzNxuqVusPxDg";
16+
const headers: RequestSandBoxHeaders = sandBoxHeader;
17+
const response = await request.get(
18+
`${SUPPLIER_API_URL_SANDBOX}/${SUPPLIER_LETTERS}/${id}/data`,
19+
{
20+
headers,
21+
},
22+
);
23+
24+
expect(response.status()).toBe(200);
25+
expect(response.headers()["content-type"]).toMatch("application/pdf");
26+
});
27+
test(`Get Letter Data endpoint returns 404 for invalid id`, async ({
28+
request,
29+
}) => {
30+
const id = "invalid-id";
31+
const headers: RequestSandBoxHeaders = sandBoxHeader;
32+
const response = await request.get(
33+
`${SUPPLIER_API_URL_SANDBOX}/${SUPPLIER_LETTERS}/${id}/data`,
34+
{
35+
headers,
36+
},
37+
);
38+
39+
expect(response.status()).toBe(404);
40+
const responseBody = await response.json();
41+
expect(responseBody).toMatchObject({
42+
errors: [
43+
{
44+
code: "NOTIFY_RESOURCE_NOT_FOUND",
45+
detail: "No resource found with that ID",
46+
id: expect.any(String),
47+
links: {
48+
about:
49+
"https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier",
50+
},
51+
status: "404",
52+
title: "Resource not found",
53+
},
54+
],
55+
});
56+
});
57+
});

tests/sandbox/get-letter-data.spec.ts

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import {
2+
RequestSandBoxHeaders,
3+
sandBoxHeader,
4+
} from "../../constants/request-headers";
5+
import { ErrorMessageBody } from "../../helpers/common-types";
6+
import {
7+
NoRequestIdHeaders,
8+
SandboxErrorResponse,
9+
} from "./get-list-of-letters-test-cases";
10+
11+
type ApiSandboxMiRequestTestCase = {
12+
testCase: string;
13+
header?: RequestSandBoxHeaders | NoRequestIdHeaders;
14+
body: MiRequestBody;
15+
expectedResponse: MiRequestBody | ErrorMessageBody | SandboxErrorResponse;
16+
expectedStatus: number;
17+
};
18+
19+
export type MiRequestBody = {
20+
data: {
21+
type: string;
22+
attributes: {
23+
groupId: string;
24+
lineItem: string;
25+
quantity: number;
26+
specificationId: string;
27+
stockRemaining: number;
28+
timestamp: string;
29+
};
30+
};
31+
};
32+
33+
export const apiSandboxCreateMiTestData: ApiSandboxMiRequestTestCase[] = [
34+
{
35+
testCase: "200 when a valid request is passed",
36+
header: sandBoxHeader,
37+
body: miValidSandboxRequest(),
38+
expectedStatus: 200,
39+
expectedResponse: {
40+
data: {
41+
attributes: {
42+
groupId: "abc123",
43+
lineItem: "envelope-business-standard",
44+
quantity: 22,
45+
specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg",
46+
stockRemaining: 2000,
47+
timestamp: "2023-11-17T14:27:51.413Z",
48+
},
49+
type: "ManagementInformation",
50+
},
51+
},
52+
},
53+
{
54+
testCase: "400 when a invalid timestamp is passed",
55+
header: sandBoxHeader,
56+
body: miInvalidDateSandboxRequest(),
57+
expectedStatus: 400,
58+
expectedResponse: {
59+
message:
60+
'request.body.data.attributes.timestamp should match format "date-time"',
61+
errors: [
62+
{
63+
path: ".body.data.attributes.timestamp",
64+
message: 'should match format "date-time"',
65+
errorCode: "format.openapi.validation",
66+
},
67+
],
68+
},
69+
},
70+
{
71+
testCase: "404 when a invalid id is passed",
72+
header: sandBoxHeader,
73+
body: miInvalidSandboxRequest(),
74+
expectedStatus: 404,
75+
expectedResponse: {
76+
errors: [
77+
{
78+
id: "rrt-1931948104716186917-c-geu2-10664-3111479-3.0",
79+
code: "NOTIFY_RESOURCE_NOT_FOUND",
80+
links: {
81+
about:
82+
"https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier",
83+
},
84+
status: "404",
85+
title: "Resource not found",
86+
detail: "No resource found with that ID",
87+
},
88+
],
89+
},
90+
},
91+
];
92+
93+
export function miValidSandboxRequest(): MiRequestBody {
94+
return {
95+
data: {
96+
attributes: {
97+
groupId: "abc123",
98+
lineItem: "envelope-business-standard",
99+
quantity: 22,
100+
specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg",
101+
stockRemaining: 2000,
102+
timestamp: "2023-11-17T14:27:51.413Z",
103+
},
104+
type: "ManagementInformation",
105+
},
106+
};
107+
}
108+
109+
export function miInvalidSandboxRequest(): MiRequestBody {
110+
return {
111+
data: {
112+
attributes: {
113+
groupId: "abc123",
114+
lineItem: "envelope-business-standard",
115+
quantity: 22,
116+
specificationId: "",
117+
stockRemaining: 2000,
118+
timestamp: "2023-11-17T14:27:51.413Z",
119+
},
120+
type: "ManagementInformation",
121+
},
122+
};
123+
}
124+
125+
export function miInvalidDateSandboxRequest(): MiRequestBody {
126+
return {
127+
data: {
128+
attributes: {
129+
groupId: "abc123",
130+
lineItem: "envelope-business-standard",
131+
quantity: 22,
132+
specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg",
133+
stockRemaining: 2000,
134+
timestamp: "yesterday",
135+
},
136+
type: "ManagementInformation",
137+
},
138+
};
139+
}
File renamed without changes.

tests/sandbox/update-multiple-letter-status.spec.ts renamed to tests/sandbox/update-multiple-letter-status-sandbox.spec.ts

File renamed without changes.

0 commit comments

Comments
 (0)