Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ config:: _install-dependencies version # Configure development environment (main
npm install
(cd docs && make install && cd ..)

test-component:
(cd tests && npm install && npm run test:component)

version:
rm -f .version
Expand Down
901 changes: 774 additions & 127 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
94 changes: 94 additions & 0 deletions tests/component-tests/apiGateway-tests/getLetters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { test, expect } from '@playwright/test';
import { SUPPLIER_LETTERS } from '../../constants/api_constants';
import { createHeaderWithNoCorrelationId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
import { validateApiResponse } from '../../helpers/validateJsonSchema';
import { link } from 'fs';

let baseUrl: string;

test.beforeAll(async () => {
baseUrl = await getRestApiGatewayBaseUrl();
});

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

expect(response.status()).toBe(200);
const responseBody = await response.json();
expect(responseBody.data.length.toString()).toEqual('2');

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 authentication should return 403', async ({ request }) => {
const header = createInvalidRequestHeaders();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
headers: header,
params:{
limit:'2'
},
},
);
expect(response.status()).toBe(403);
const responseBody = await response.json();
expect(responseBody).toMatchObject({
Message : 'User is not authorized to access this resource with an explicit deny in an identity-based policy' }
);
});

test('GET /letters with empty correlationId should return 500', async ({ request }) => {
const header = createHeaderWithNoCorrelationId();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
headers: header,
params:{
limit:'2'
},
},
);
expect(response.status()).toBe(500);
const responseBody = await response.json();
expect(responseBody.errors[0].code).toBe('NOTIFY_INTERNAL_SERVER_ERROR');
expect(responseBody.errors[0].detail).toBe("The request headers don't contain the APIM correlation id");

});

test('GET /letters with invalid query param return 400', async ({ request }) => {
const header = createValidRequestHeaders();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
headers: header,
params:{
limit:'?'
},
});
expect(response.status()).toBe(400);
const responseBody = await response.json();
expect(responseBody).toMatchObject({
errors: [
{
id: '12345',
code: 'NOTIFY_INVALID_REQUEST',
links: {
about: 'https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier'
},
status: '400',
title: 'Invalid request',
detail: 'The limit parameter is not a number'
}
]
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

import { RequestHeaders } from '../../../constants/request_headers';
import { supplierId } from '../../../constants/api_constants';
import { ErrorMessageBody } from '../../../helpers/commonTypes';

export type PatchMessageRequestBody = {
data: {
type: string;
id: string;
attributes: {
reasonCode?: string | 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 function patchRequestHeaders(): RequestHeaders {
let requestHeaders: RequestHeaders;
requestHeaders = {
headerauth1: process.env.HEADERAUTH || '',
'NHSD-Supplier-ID': supplierId,
'NHSD-Correlation-ID': '12344',
'X-Request-ID': 'requestId1'
};
return requestHeaders;
};


export function patchValidRequestBody (id: string, status: string) : PatchMessageRequestBody{
let requestBody: PatchMessageRequestBody;

requestBody = {
data: {
 attributes: {
  status: status,
},
type: 'Letter',
id: id
}

};
return requestBody;
}

export function patchFailureRequestBody (id: string, status: string) : PatchMessageRequestBody{
let requestBody: PatchMessageRequestBody;

requestBody = {
data: {
attributes: {
status: status,
reasonCode: 123,
reasonText: 'Test Reason'
},
type: 'Letter',
id: id
}

};
return requestBody;
}

export function patch400ErrorResponseBody () : ErrorMessageBody{
let responseBody: ErrorMessageBody;
responseBody = {
errors: [
{
id : '12344',
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"
}
]
};
return responseBody;
};

export function patch500ErrorResponseBody (id: string) : ErrorMessageBody{
let responseBody: ErrorMessageBody;
responseBody = {
errors: [
{
id: "12344",
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 ${id} not found for supplier ${supplierId}`
}
]
};
return responseBody;
}
131 changes: 131 additions & 0 deletions tests/component-tests/apiGateway-tests/updateLetterStatus.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { test, expect } from '@playwright/test';
import { SUPPLIER_LETTERS, supplierId } from '../../constants/api_constants';
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
import { patch400ErrorResponseBody, patch500ErrorResponseBody, patchFailureRequestBody, patchRequestHeaders, patchValidRequestBody } from './testCases/UpdateLetterStatus';
import { createTestData, deleteLettersBySupplier, getLettersBySupplier } from '../../helpers/generate_fetch_testData';
import { randomUUID } from 'crypto';
import { createInvalidRequestHeaders } from '../../constants/request_headers';

let baseUrl: string;

test.beforeAll(async () => {
baseUrl = await getRestApiGatewayBaseUrl();
});

test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
test(`Patch /letters returns 200 and status is updated to ACCEPTED`, async ({ request }) => {

await createTestData(supplierId);
const letters = await getLettersBySupplier(supplierId, 'PENDING', 1);

if (!letters?.length) {
test.fail(true, `No PENDING letters found for supplier ${supplierId}`);
return;
}
const letter = letters[0];
const headers = patchRequestHeaders();
const body = patchValidRequestBody(letter.id, 'ACCEPTED');

const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${letter.id}`, {
headers: headers,
data: body
});

const res = await response.json();
expect(response.status()).toBe(200);
expect(res).toMatchObject({
data:{
attributes: {
status: 'ACCEPTED',
specificationId: letter.specificationId,
groupId: letter.groupId,
},
id: letter.id,
type: 'Letter'
}
});

await deleteLettersBySupplier(letter.id);
});

test(`Patch /letters returns 200 and status is updated to REJECTED`, async ({ request }) => {

await createTestData(supplierId);
const letters = await getLettersBySupplier(supplierId, 'PENDING', 1);

if (!letters?.length) {
test.fail(true, `No PENDING letters found for supplier ${supplierId}`);
return;
}
const letter = letters[0];
const headers = patchRequestHeaders();
const body = patchFailureRequestBody(letter.id, 'REJECTED');

const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${letter.id}`, {
headers: headers,
data: body
});

const res = await response.json();
expect(response.status()).toBe(200);
expect(res).toMatchObject({
data:{
attributes: {
status: 'REJECTED',
specificationId: letter.specificationId,
groupId: letter.groupId,
},
id: letter.id,
type: 'Letter'
}
});

await deleteLettersBySupplier(letter.id);
});

test(`Patch /letters returns 400 if request Body is invalid`, async ({ request }) => {

const id = randomUUID()
const headers = patchRequestHeaders();
const body = patchValidRequestBody(id, '');

const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, {
headers: headers,
data: body
});

const res = await response.json();

expect(response.status()).toBe(400);
expect(res).toMatchObject(patch400ErrorResponseBody());
});

test(`Patch /letters returns 500 if Id doesn't exist for SupplierId`, async ({ request }) => {
const headers = patchRequestHeaders();
const id = randomUUID()
const body = patchValidRequestBody(id, 'PENDING');

const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, {
headers: headers,
data: body
});

const res = await response.json();
expect(response.status()).toBe(500);
expect(res).toMatchObject(patch500ErrorResponseBody(id));
});

test(`Patch /letters returns 403 for invalid headers`, async ({ request }) => {
const headers = await createInvalidRequestHeaders();
const id = randomUUID()
const body = patchValidRequestBody(id, 'PENDING');

const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, {
headers: headers,
data: body
});

const res = await response.json();
expect(response.status()).toBe(403);
});
});
Loading
Loading