generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
CCM 12179: Add Component Tests #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
345d687
test
Namitha-Prabhu 64e9995
Comp tests
Namitha-Prabhu d28f7d5
Comp tests
Namitha-Prabhu 8e56956
component tests
Namitha-Prabhu e658df2
test
Namitha-Prabhu 06f62fd
Comp tests
Namitha-Prabhu 24cc719
Comp tests
Namitha-Prabhu af781ad
component tests
Namitha-Prabhu 5c26997
Merge branch 'feature/CCM-12179-Component-tests' of https://github.co…
Namitha-Prabhu 84378d6
review comments
Namitha-Prabhu c17261e
tests on pipeline
Namitha-Prabhu e4ac798
dependencies
Namitha-Prabhu aa08f80
tests
Namitha-Prabhu a91577c
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu af33e9e
revert test data changes
Namitha-Prabhu 5b8ac87
fix
Namitha-Prabhu 406d529
fix-cicd
Namitha-Prabhu ed3de2e
fix
Namitha-Prabhu 8359886
to discuss schema
Namitha-Prabhu 765cb82
to discuss schema
Namitha-Prabhu bf015b7
Remove test from pipeline
Namitha-Prabhu f482da8
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu 5d8a6c3
Remove test from pipeline
Namitha-Prabhu 9996615
Merge branch 'feature/CCM-12179-Component-tests' of https://github.co…
Namitha-Prabhu f29c91d
amend workflow
Namitha-Prabhu 20af907
Review Changes
Namitha-Prabhu 4d5d4e7
review fix
Namitha-Prabhu 77a6544
review fixes
Namitha-Prabhu 9b56f6a
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,5 @@ node_modules/ | |
| /playwright/.cache/ | ||
| /allure-results | ||
| /target | ||
| /playwright/.auth/ | ||
| /allure-report | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| }); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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' | ||
| } | ||
| ] | ||
| }); | ||
| }); | ||
| }); | ||
114 changes: 114 additions & 0 deletions
114
tests/component-tests/apiGateway-tests/testCases/UpdateLetterStatus.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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
131
tests/component-tests/apiGateway-tests/updateLetterStatus.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expect(res).toMatchObject(patch500ErrorResponseBody(id)); | ||
| }); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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); | ||
| }); | ||
| }); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.