Skip to content

Commit 8e56956

Browse files
component tests
1 parent d28f7d5 commit 8e56956

22 files changed

+656
-280
lines changed

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ node_modules/
88
/allure-results
99
/target
1010
/playwright/.auth/
11+
/allure-report

tests/component-tests/apiGateway-tests/getLetters.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ test.describe('API Gateway Tests To Get List Of Pending ', () =>
7474
params:{
7575
limit:'?'
7676
},
77-
},
78-
);
77+
});
7978
expect(response.status()).toBe(400);
8079
const responseBody = await response.json();
8180

tests/component-tests/apiGateway-tests/testCases/UpdateLetterStatus.ts

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ type APIPatchMessageRequestTestCase = {
1010
expectedResponse?: PatchMessageResponseBody | PatchErrorMessageBody;
1111
};
1212

13-
type PatchMessageRequestBody = {
13+
export type PatchMessageRequestBody = {
1414
data: {
1515
type: string;
1616
id: string;
1717
attributes: {
18-
reasonCode: number;
19-
reasonText: string;
18+
reasonCode?: number;
19+
reasonText?: string;
2020
status: string;
2121
};
2222
};
2323
};
2424

25-
type PatchMessageResponseBody = {
25+
export type PatchMessageResponseBody = {
2626
data: {
2727
type: string;
2828
id: string;
2929
attributes: {
30-
reasonCode: number;
31-
reasonText: string;
30+
reasonCode?: number;
31+
reasonText?: string;
3232
status: string;
3333
specificationId:string;
34-
groupId:string;
34+
groupId?:string;
3535
};
3636
};
3737
};
@@ -49,15 +49,15 @@ type PatchErrorResponse = {
4949
detail: string;
5050
};
5151

52-
type PatchErrorMessageBody = {
52+
export type PatchErrorMessageBody = {
5353
errors: PatchErrorResponse[];
5454
};
5555

5656

5757

5858
export const apiPatchMessageRequestTestData: APIPatchMessageRequestTestCase[] = [
5959
{
60-
testCase: '200 response if record is updated and status is REJECTED',
60+
testCase: '200 response if record is updated with status REJECTED',
6161
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
6262
body: {
6363
data: {
@@ -86,6 +86,34 @@ export const apiPatchMessageRequestTestData: APIPatchMessageRequestTestCase[] =
8686
},
8787
},
8888

89+
{
90+
testCase: '200 response if record is updated with status ACCEPTED',
91+
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
92+
body: {
93+
data: {
94+
type: 'Letter',
95+
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
96+
attributes: {
97+
status: 'ACCEPTED',
98+
},
99+
}
100+
},
101+
expectedStatus: 200,
102+
expectedResponse: {
103+
data: {
104+
type: 'Letter',
105+
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
106+
attributes: {
107+
reasonCode: 123,
108+
reasonText: 'Test Reason Text',
109+
status: 'ACCEPTED',
110+
specificationId:'specification-id',
111+
groupId:'group-id'
112+
},
113+
}
114+
},
115+
},
116+
89117
{
90118
testCase: '400 response if request body is invalid',
91119
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
@@ -114,4 +142,31 @@ export const apiPatchMessageRequestTestData: APIPatchMessageRequestTestCase[] =
114142
}]
115143
},
116144
},
145+
146+
{
147+
testCase: '500 response if id doesnt exist supplierid',
148+
id: '0',
149+
body: {
150+
data: {
151+
type: 'Letter',
152+
id: '0',
153+
attributes: {
154+
status: 'ACCEPTED',
155+
},
156+
}
157+
},
158+
expectedStatus: 500,
159+
expectedResponse: {
160+
errors: [{
161+
id: '1234',
162+
code: 'NOTIFY_INTERNAL_SERVER_ERROR',
163+
links: {
164+
about: "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"
165+
},
166+
status: '500',
167+
title: 'Internal server error',
168+
detail: 'Letter with id 0 not found for supplier supplier-id'
169+
}]
170+
},
171+
},
117172
];

tests/config/main.config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import type { PlaywrightTestConfig } from '@playwright/test';
2-
import { config as baseConfig } from './playwright.base.config';
3-
import { getReporters } from './reporters';
1+
import {defineConfig, PlaywrightTestConfig } from '@playwright/test';
2+
import baseConfig from './playwright.base.config';
3+
import { getReporters } from './reporters';
4+
import path from 'path';
45

56
const localConfig: PlaywrightTestConfig = {
67
...baseConfig,
78
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
89
reporter: getReporters('api-test'),
9-
//globalSetup: require.resolve('./setup/globalSetup'),
10-
//globalTeardown: require.resolve('./setup/globalTeardown'),
1110
projects: [
1211
{
1312
name: 'component-tests',
14-
testDir: 'tests/component-tests',
13+
testDir: path.resolve(__dirname, '../component-tests'),
1514
testMatch: '**/*.spec.ts',
1615
},
1716
],
1817
};
1918

20-
export default localConfig;
19+
export default defineConfig(localConfig);
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import type { PlaywrightTestConfig } from '@playwright/test';
1+
import { defineConfig, PlaywrightTestConfig } from '@playwright/test';
22

33
const baseUrl = process.env.NHSD_APIM_PROXY_URL || 'http://localhost:3000/';
44
const envMaxInstances = Number.parseInt(process.env.WORKERS_MAX_INST!) || 10;
55
/**
66
* See https://playwright.dev/docs/test-configuration.
77
*/
88
export const config: PlaywrightTestConfig = {
9-
testDir: '../tests',
10-
testMatch: '**/*.spec.ts',
119
/* Maximum time one test can run for. */
1210
timeout: 60 * 1000,
1311
workers: envMaxInstances,
@@ -24,19 +22,5 @@ export const config: PlaywrightTestConfig = {
2422
forbidOnly: !!process.env.CI,
2523
/* Retry on CI only */
2624
retries: process.env.CI ? 2 : 0,
27-
28-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
29-
use: {
30-
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
31-
actionTimeout: 0,
32-
/* Base URL to use in actions like `await page.goto('/')`. */
33-
baseURL: baseUrl,
34-
ignoreHTTPSErrors: true,
35-
trace: 'on-first-retry',
36-
/* Slows down Playwright operations by the specified amount of milliseconds. */
37-
launchOptions: {
38-
slowMo: 0,
39-
},
40-
},
4125
};
42-
export default config;
26+
export default defineConfig(config);

tests/config/sandbox.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PlaywrightTestConfig } from '@playwright/test';
22
import { config as baseConfig } from './playwright.base.config';
33
import { getReporters } from './reporters';
4+
import path from 'path';
45

56
const localConfig: PlaywrightTestConfig = {
67
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
@@ -11,7 +12,8 @@ const localConfig: PlaywrightTestConfig = {
1112
projects: [
1213
{
1314
name: 'sandbox',
14-
testMatch: '**/sandbox/get_single_letter/*.spec.ts',
15+
testDir: path.resolve(__dirname, '../sandbox'),
16+
testMatch: '*.spec.ts',
1517
},
1618
],
1719
};

tests/constants/api_constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const SUPPLIER_API_GATEWAY_NAME = 'nhs-main-supapi';
22
export const SUPPLIER_LETTERS = 'letters';
33
export const SUPPLIER_API_URL = 'https://internal-dev.api.service.nhs.uk/nhs-notify-supplier/';
4-
export const SUPPLIER_API_URL_SANDBOX = 'https://internal-sandbox.api.service.nhs.uk/nhs-notify-supplier/';
4+
export const SUPPLIER_API_URL_SANDBOX = 'https://internal-dev-sandbox.api.service.nhs.uk/nhs-notify-supplier';
55
export const AWS_REGION = 'eu-west-2';

tests/constants/request_headers.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,11 @@ export async function createHeaderWithNoCorrelationId(): Promise<RequestHeaders>
3030
return requestHeaders;
3131
}
3232

33-
export async function createValidSandBoxRequestHeaders(): Promise<RequestSandBoxHeaders> {
34-
let requestHeaders: RequestSandBoxHeaders;
35-
requestHeaders = {
36-
'X-Request-ID': randomUUID(),
37-
'Content-Type':'application/vnd.api+json',
38-
'X-Correlation-ID': randomUUID(),
39-
};
40-
return requestHeaders;
41-
}
33+
export const sandBoxHeader: RequestSandBoxHeaders = {
34+
'X-Request-ID': randomUUID(),
35+
'Content-Type': 'application/vnd.api+json',
36+
'X-Correlation-ID': randomUUID(),
37+
};
4238

4339
export interface RequestHeaders {
4440
headerauth1: string;
@@ -47,7 +43,7 @@ export interface RequestHeaders {
4743
[key: string]: string;
4844
}
4945

50-
interface RequestSandBoxHeaders {
46+
export interface RequestSandBoxHeaders {
5147
'X-Request-ID': string;
5248
'Content-Type': string;
5349
'X-Correlation-ID': string;

tests/helpers/awsGatewayHelper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ export async function getRestApiGatewayBaseUrl(
1313
if (!api?.id) throw new Error(`API with name "${apiName}" not found.`);
1414

1515
const url = `https://${api.id}.execute-api.${region}.amazonaws.com/main`;
16-
console.log(`API Gateway URL: ${url}`);
1716
return url;
1817
}

0 commit comments

Comments
 (0)