Skip to content

Commit 64e9995

Browse files
Comp tests
1 parent 345d687 commit 64e9995

File tree

19 files changed

+1469
-290
lines changed

19 files changed

+1469
-290
lines changed

package-lock.json

Lines changed: 875 additions & 228 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
{
22
"dependencies": {
3+
"@aws-sdk/client-api-gateway": "^3.906.0",
4+
"@playwright/test": "^1.55.1",
5+
"ajv": "^8.17.1",
6+
"js-yaml": "^4.1.0",
7+
"openapi-response-validator": "^12.1.3",
38
"serve": "^14.2.4"
49
},
510
"devDependencies": {
611
"@openapitools/openapi-generator-cli": "^2.21.4",
712
"@redocly/cli": "^1.34.5",
813
"@tsconfig/node22": "^22.0.2",
914
"@types/jest": "^29.5.14",
15+
"@types/js-yaml": "^4.0.9",
1016
"@typescript-eslint/eslint-plugin": "^8.27.0",
1117
"@typescript-eslint/parser": "^8.27.0",
1218
"esbuild": "^0.24.0",

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules/
77
/playwright/.cache/
88
/allure-results
99
/target
10+
/playwright/.auth/
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { test, expect } from '@playwright/test';
2+
import { SUPPLIER_API_GATEWAY_NAME, SUPPLIER_LETTERS, AWS_REGION } from '../../constants/api_constants';
3+
import { createHeaderWithNoCorrelationId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
4+
import { validateApiResponse } from '../../helpers/validateJsonSchema';
5+
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
6+
7+
let baseUrl: string;
8+
9+
test.beforeAll(async () => {
10+
const region = AWS_REGION;
11+
baseUrl = await getRestApiGatewayBaseUrl(SUPPLIER_API_GATEWAY_NAME, region);
12+
});
13+
14+
test.describe('API Gateway Tests To Get List Of Pending ', () =>
15+
{
16+
test('GET /letters should return 200 and list items', async ({ request }) =>
17+
{
18+
const header = await createValidRequestHeaders();
19+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
20+
headers: header,
21+
params: {
22+
limit:'2'},
23+
},
24+
);
25+
26+
expect(response.status()).toBe(200);
27+
const responseBody = await response.json();
28+
29+
const validationResult = validateApiResponse("get", "/letters", response.status(), responseBody);
30+
if (validationResult) {
31+
console.error("API response validation failed:", validationResult);
32+
}
33+
34+
expect(validationResult).toBeUndefined();
35+
});
36+
37+
test('GET /letters with invalid apikey should return 403', async ({ request }) => {
38+
const header = await createInvalidRequestHeaders();
39+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
40+
headers: header,
41+
params:{
42+
limit:'2'
43+
},
44+
},
45+
);
46+
expect(response.status()).toBe(403);
47+
});
48+
49+
50+
test('GET /letters with empty correlationId should return 500', async ({ request }) => {
51+
const header = await createHeaderWithNoCorrelationId();
52+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
53+
headers: header,
54+
params:{
55+
limit:'2'
56+
},
57+
},
58+
);
59+
expect(response.status()).toBe(500);
60+
const responseBody = await response.json();
61+
62+
const validationResult = validateApiResponse("get", "/letters", response.status(), responseBody);
63+
if (validationResult) {
64+
console.error("API response validation failed:", validationResult);
65+
}
66+
67+
expect(validationResult).toBeUndefined();
68+
});
69+
70+
test('GET /letters with invalid query param return 400', async ({ request }) => {
71+
const header = await createValidRequestHeaders();
72+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
73+
headers: header,
74+
params:{
75+
limit:'?'
76+
},
77+
},
78+
);
79+
expect(response.status()).toBe(400);
80+
const responseBody = await response.json();
81+
82+
const validationResult = validateApiResponse("get", "/letters", response.status(), responseBody);
83+
if (validationResult) {
84+
console.error("API response validation failed:", validationResult);
85+
}
86+
87+
expect(validationResult).toBeUndefined();
88+
});
89+
90+
});
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
import { createValidRequestHeaders, RequestHeaders } from '../../../constants/request_headers';
3+
import { test } from '@playwright/test';
4+
5+
type APIPatchMessageRequestTestCase = {
6+
testCase: string;
7+
id: string,
8+
body?: PatchMessageRequestBody;
9+
expectedStatus: number;
10+
expectedResponse?: PatchMessageResponseBody | PatchErrorMessageBody;
11+
};
12+
13+
type PatchMessageRequestBody = {
14+
data: {
15+
type: string;
16+
id: string;
17+
attributes: {
18+
reasonCode: number;
19+
reasonText: string;
20+
status: string;
21+
};
22+
};
23+
};
24+
25+
type PatchMessageResponseBody = {
26+
data: {
27+
type: string;
28+
id: string;
29+
attributes: {
30+
reasonCode: number;
31+
reasonText: string;
32+
status: string;
33+
specificationId:string;
34+
groupId:string;
35+
};
36+
};
37+
};
38+
39+
export type ErrorLink = {
40+
about: string;
41+
};
42+
43+
type PatchErrorResponse = {
44+
id: string;
45+
code: string;
46+
links: ErrorLink;
47+
status: string;
48+
title: string;
49+
detail: string;
50+
};
51+
52+
type PatchErrorMessageBody = {
53+
errors: PatchErrorResponse[];
54+
};
55+
56+
57+
58+
export const apiPatchMessageRequestTestData: APIPatchMessageRequestTestCase[] = [
59+
{
60+
testCase: '200 response if record is updated and status is REJECTED',
61+
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
62+
body: {
63+
data: {
64+
type: 'Letter',
65+
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
66+
attributes: {
67+
reasonCode: 123,
68+
reasonText: 'Test Reason Text',
69+
status: 'REJECTED',
70+
},
71+
}
72+
},
73+
expectedStatus: 200,
74+
expectedResponse: {
75+
data: {
76+
type: 'Letter',
77+
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
78+
attributes: {
79+
reasonCode: 123,
80+
reasonText: 'Test Reason Text',
81+
status: 'REJECTED',
82+
specificationId:'specification-id',
83+
groupId:'group-id'
84+
},
85+
}
86+
},
87+
},
88+
89+
{
90+
testCase: '400 response if request body is invalid',
91+
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
92+
body: {
93+
data: {
94+
type: 'Letter',
95+
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
96+
attributes: {
97+
reasonCode: 123,
98+
reasonText: 'Test Reason Text',
99+
status: '',
100+
},
101+
}
102+
},
103+
expectedStatus: 400,
104+
expectedResponse: {
105+
errors: [{
106+
id: '1234',
107+
code: 'NOTIFY_INVALID_REQUEST',
108+
links: {
109+
about: "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"
110+
},
111+
status: '400',
112+
title: 'Invalid request',
113+
detail: 'The request body is invalid'
114+
}]
115+
},
116+
},
117+
];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { test, expect } from '@playwright/test';
2+
import { SUPPLIER_API_GATEWAY_NAME, SUPPLIER_LETTERS, AWS_REGION } from '../../constants/api_constants';
3+
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
4+
import { createValidRequestHeaders } from '../../constants/request_headers';
5+
import { apiPatchMessageRequestTestData } from './testCases/UpdateLetterStatus';
6+
7+
let baseUrl: string;
8+
9+
test.beforeAll(async () => {
10+
const region = AWS_REGION;
11+
baseUrl = await getRestApiGatewayBaseUrl(SUPPLIER_API_GATEWAY_NAME, region);
12+
});
13+
14+
test.describe('API Gateway Tests To Verify Patch Status Endpoint ', () => {
15+
apiPatchMessageRequestTestData.forEach(({ testCase, id, body, expectedStatus, expectedResponse }) => {
16+
test(`Patch /letters returns ${testCase}`, async ({ request }) => {
17+
const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${id}` ,{
18+
headers: await createValidRequestHeaders(),
19+
data: body
20+
},
21+
);
22+
const res = await response.json();
23+
24+
expect(response.status()).toBe(expectedStatus);
25+
expect(res).toEqual(expectedResponse);
26+
});
27+
});
28+
});

tests/component_tests/apiGateway_tests/updateLetterStatus.spec.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/config/main.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { config as baseConfig } from './playwright.base.config';
33
import { getReporters } from './reporters';
44

55
const localConfig: PlaywrightTestConfig = {
6+
...baseConfig,
67
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
78
reporter: getReporters('api-test'),
8-
...baseConfig,
99
//globalSetup: require.resolve('./setup/globalSetup'),
1010
//globalTeardown: require.resolve('./setup/globalTeardown'),
11-
testIgnore: [],
1211
projects: [
1312
{
14-
name: 'sandbox',
15-
testMatch: 'tests/messages/get_single_letter/*.spec.ts',
13+
name: 'component-tests',
14+
testDir: 'tests/component-tests',
15+
testMatch: '**/*.spec.ts',
1616
},
1717
],
1818
};

tests/config/playwright.base.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const envMaxInstances = Number.parseInt(process.env.WORKERS_MAX_INST!) || 10;
66
* See https://playwright.dev/docs/test-configuration.
77
*/
88
export const config: PlaywrightTestConfig = {
9-
testDir: '../sandbox/messages/get_single_letter/',
10-
testMatch: '*.spec.ts/',
9+
testDir: '../tests',
10+
testMatch: '**/*.spec.ts',
1111
/* Maximum time one test can run for. */
1212
timeout: 60 * 1000,
1313
workers: envMaxInstances,

tests/config/sandbox.config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import { config as baseConfig } from './playwright.base.config';
3+
import { getReporters } from './reporters';
4+
5+
const localConfig: PlaywrightTestConfig = {
6+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
7+
reporter: getReporters('api-test'),
8+
...baseConfig,
9+
//globalSetup: require.resolve('./setup/globalSetup'),
10+
//globalTeardown: require.resolve('./setup/globalTeardown'),
11+
projects: [
12+
{
13+
name: 'sandbox',
14+
testMatch: '**/sandbox/get_single_letter/*.spec.ts',
15+
},
16+
],
17+
};
18+
19+
export default localConfig;

0 commit comments

Comments
 (0)