Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
345d687
test
Namitha-Prabhu Oct 1, 2025
64e9995
Comp tests
Namitha-Prabhu Oct 9, 2025
d28f7d5
Comp tests
Namitha-Prabhu Oct 9, 2025
8e56956
component tests
Namitha-Prabhu Oct 13, 2025
e658df2
test
Namitha-Prabhu Oct 1, 2025
06f62fd
Comp tests
Namitha-Prabhu Oct 9, 2025
24cc719
Comp tests
Namitha-Prabhu Oct 9, 2025
af781ad
component tests
Namitha-Prabhu Oct 13, 2025
5c26997
Merge branch 'feature/CCM-12179-Component-tests' of https://github.co…
Namitha-Prabhu Oct 13, 2025
84378d6
review comments
Namitha-Prabhu Oct 15, 2025
c17261e
tests on pipeline
Namitha-Prabhu Oct 15, 2025
e4ac798
dependencies
Namitha-Prabhu Oct 15, 2025
aa08f80
tests
Namitha-Prabhu Oct 21, 2025
a91577c
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu Oct 22, 2025
af33e9e
revert test data changes
Namitha-Prabhu Oct 22, 2025
5b8ac87
fix
Namitha-Prabhu Oct 22, 2025
406d529
fix-cicd
Namitha-Prabhu Oct 22, 2025
ed3de2e
fix
Namitha-Prabhu Oct 22, 2025
8359886
to discuss schema
Namitha-Prabhu Oct 23, 2025
765cb82
to discuss schema
Namitha-Prabhu Oct 23, 2025
bf015b7
Remove test from pipeline
Namitha-Prabhu Oct 23, 2025
f482da8
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu Oct 23, 2025
5d8a6c3
Remove test from pipeline
Namitha-Prabhu Oct 23, 2025
9996615
Merge branch 'feature/CCM-12179-Component-tests' of https://github.co…
Namitha-Prabhu Oct 23, 2025
f29c91d
amend workflow
Namitha-Prabhu Oct 23, 2025
20af907
Review Changes
Namitha-Prabhu Oct 23, 2025
4d5d4e7
review fix
Namitha-Prabhu Oct 27, 2025
77a6544
review fixes
Namitha-Prabhu Oct 27, 2025
9b56f6a
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu Oct 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,103 changes: 875 additions & 228 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"dependencies": {
"@aws-sdk/client-api-gateway": "^3.906.0",
"@playwright/test": "^1.55.1",
"ajv": "^8.17.1",
"js-yaml": "^4.1.0",
"openapi-response-validator": "^12.1.3",
"serve": "^14.2.4"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.21.4",
"@redocly/cli": "^1.34.5",
"@tsconfig/node22": "^22.0.2",
"@types/jest": "^29.5.14",
"@types/js-yaml": "^4.0.9",
"@typescript-eslint/eslint-plugin": "^8.27.0",
"@typescript-eslint/parser": "^8.27.0",
"esbuild": "^0.24.0",
Expand Down
2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ node_modules/
/playwright/.cache/
/allure-results
/target
/playwright/.auth/
/allure-report
89 changes: 89 additions & 0 deletions tests/component-tests/apiGateway-tests/getLetters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { test, expect } from '@playwright/test';
import { SUPPLIER_API_GATEWAY_NAME, SUPPLIER_LETTERS, AWS_REGION } from '../../constants/api_constants';
import { createHeaderWithNoCorrelationId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
import { validateApiResponse } from '../../helpers/validateJsonSchema';
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';

let baseUrl: string;

test.beforeAll(async () => {
const region = AWS_REGION;
baseUrl = await getRestApiGatewayBaseUrl(SUPPLIER_API_GATEWAY_NAME, region);
});

test.describe('API Gateway Tests To Get List Of Pending ', () =>
{
test('GET /letters should return 200 and list items', async ({ request }) =>
{
const header = await createValidRequestHeaders();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
headers: header,
params: {
limit:'2'},
},
);

expect(response.status()).toBe(200);
const responseBody = await response.json();

const validationResult = validateApiResponse("get", "/letters", response.status(), responseBody);
if (validationResult) {
console.error("API response validation failed:", validationResult);
}

expect(validationResult).toBeUndefined();
});

test('GET /letters with invalid apikey should return 403', async ({ request }) => {
const header = await createInvalidRequestHeaders();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
headers: header,
params:{
limit:'2'
},
},
);
expect(response.status()).toBe(403);
});


test('GET /letters with empty correlationId should return 500', async ({ request }) => {
const header = await createHeaderWithNoCorrelationId();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
headers: header,
params:{
limit:'2'
},
},
);
expect(response.status()).toBe(500);
const responseBody = await response.json();

const validationResult = validateApiResponse("get", "/letters", response.status(), responseBody);
if (validationResult) {
console.error("API response validation failed:", validationResult);
}

expect(validationResult).toBeUndefined();
});

test('GET /letters with invalid query param return 400', async ({ request }) => {
const header = await createValidRequestHeaders();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
headers: header,
params:{
limit:'?'
},
});
expect(response.status()).toBe(400);
const responseBody = await response.json();

const validationResult = validateApiResponse("get", "/letters", response.status(), responseBody);
if (validationResult) {
console.error("API response validation failed:", validationResult);
}

expect(validationResult).toBeUndefined();
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@

import { createValidRequestHeaders, RequestHeaders } from '../../../constants/request_headers';
import { test } from '@playwright/test';

type APIPatchMessageRequestTestCase = {
testCase: string;
id: string,
body?: PatchMessageRequestBody;
expectedStatus: number;
expectedResponse?: PatchMessageResponseBody | PatchErrorMessageBody;
};

export type PatchMessageRequestBody = {
data: {
type: string;
id: string;
attributes: {
reasonCode?: number;
reasonText?: string;
status: string;
};
};
};

export type PatchMessageResponseBody = {
data: {
type: string;
id: string;
attributes: {
reasonCode?: number;
reasonText?: string;
status: string;
specificationId:string;
groupId?:string;
};
};
};

export type ErrorLink = {
about: string;
};

type PatchErrorResponse = {
id: string;
code: string;
links: ErrorLink;
status: string;
title: string;
detail: string;
};

export type PatchErrorMessageBody = {
errors: PatchErrorResponse[];
};



export const apiPatchMessageRequestTestData: APIPatchMessageRequestTestCase[] = [
{
testCase: '200 response if record is updated with status REJECTED',
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
body: {
data: {
type: 'Letter',
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
attributes: {
reasonCode: 123,
reasonText: 'Test Reason Text',
status: 'REJECTED',
},
}
},
expectedStatus: 200,
expectedResponse: {
data: {
type: 'Letter',
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
attributes: {
reasonCode: 123,
reasonText: 'Test Reason Text',
status: 'REJECTED',
specificationId:'specification-id',
groupId:'group-id'
},
}
},
},

{
testCase: '200 response if record is updated with status ACCEPTED',
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
body: {
data: {
type: 'Letter',
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
attributes: {
status: 'ACCEPTED',
},
}
},
expectedStatus: 200,
expectedResponse: {
data: {
type: 'Letter',
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
attributes: {
reasonCode: 123,
reasonText: 'Test Reason Text',
status: 'ACCEPTED',
specificationId:'specification-id',
groupId:'group-id'
},
}
},
},

{
testCase: '400 response if request body is invalid',
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
body: {
data: {
type: 'Letter',
id: '00c61654-24f0-410e-a77e-04deef7d1eeb',
attributes: {
reasonCode: 123,
reasonText: 'Test Reason Text',
status: '',
},
}
},
expectedStatus: 400,
expectedResponse: {
errors: [{
id: '1234',
code: 'NOTIFY_INVALID_REQUEST',
links: {
about: "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"
},
status: '400',
title: 'Invalid request',
detail: 'The request body is invalid'
}]
},
},

{
testCase: '500 response if id doesnt exist supplierid',
id: '0',
body: {
data: {
type: 'Letter',
id: '0',
attributes: {
status: 'ACCEPTED',
},
}
},
expectedStatus: 500,
expectedResponse: {
errors: [{
id: '1234',
code: 'NOTIFY_INTERNAL_SERVER_ERROR',
links: {
about: "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"
},
status: '500',
title: 'Internal server error',
detail: 'Letter with id 0 not found for supplier supplier-id'
}]
},
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test, expect } from '@playwright/test';
import { SUPPLIER_API_GATEWAY_NAME, SUPPLIER_LETTERS, AWS_REGION } from '../../constants/api_constants';
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
import { createValidRequestHeaders } from '../../constants/request_headers';
import { apiPatchMessageRequestTestData } from './testCases/UpdateLetterStatus';

let baseUrl: string;

test.beforeAll(async () => {
const region = AWS_REGION;
baseUrl = await getRestApiGatewayBaseUrl(SUPPLIER_API_GATEWAY_NAME, region);
});

test.describe('API Gateway Tests To Verify Patch Status Endpoint ', () => {
apiPatchMessageRequestTestData.forEach(({ testCase, id, body, expectedStatus, expectedResponse }) => {
test(`Patch /letters returns ${testCase}`, async ({ request }) => {
const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${id}` ,{
headers: await createValidRequestHeaders(),
data: body
},
);
const res = await response.json();

expect(response.status()).toBe(expectedStatus);
expect(res).toEqual(expectedResponse);
});
});
});
19 changes: 9 additions & 10 deletions tests/config/main.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { config as baseConfig } from './playwright.base.config';
import { getReporters } from './reporters';
import {defineConfig, PlaywrightTestConfig } from '@playwright/test';
import baseConfig from './playwright.base.config';
import { getReporters } from './reporters';
import path from 'path';

const localConfig: PlaywrightTestConfig = {
...baseConfig,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: getReporters('api-test'),
...baseConfig,
//globalSetup: require.resolve('./setup/globalSetup'),
//globalTeardown: require.resolve('./setup/globalTeardown'),
testIgnore: [],
projects: [
{
name: 'sandbox',
testMatch: 'tests/messages/get_single_letter/*.spec.ts',
name: 'component-tests',
testDir: path.resolve(__dirname, '../component-tests'),
testMatch: '**/*.spec.ts',
},
],
};

export default localConfig;
export default defineConfig(localConfig);
20 changes: 2 additions & 18 deletions tests/config/playwright.base.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { defineConfig, PlaywrightTestConfig } from '@playwright/test';

const baseUrl = process.env.NHSD_APIM_PROXY_URL || 'http://localhost:3000/';
const envMaxInstances = Number.parseInt(process.env.WORKERS_MAX_INST!) || 10;
/**
* See https://playwright.dev/docs/test-configuration.
*/
export const config: PlaywrightTestConfig = {
testDir: '../sandbox/messages/get_single_letter/',
testMatch: '*.spec.ts/',
/* Maximum time one test can run for. */
timeout: 60 * 1000,
workers: envMaxInstances,
Expand All @@ -24,19 +22,5 @@ export const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,

/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: baseUrl,
ignoreHTTPSErrors: true,
trace: 'on-first-retry',
/* Slows down Playwright operations by the specified amount of milliseconds. */
launchOptions: {
slowMo: 0,
},
},
};
export default config;
export default defineConfig(config);
Loading
Loading