generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
CCM- 11597: Tests for getLetters and Mi Endpoint #224
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
5 commits
Select commit
Hold shift + click to select a range
95a0396
tests
Namitha-Prabhu 7822a77
Merge branch 'main' into feature/CCM-11597-GetLetterTests
Namitha-Prabhu 69a7224
ignore errors
timireland 7b02f4e
review
Namitha-Prabhu 06561ba
Merge branch 'main' into feature/CCM-11597-GetLetterTests
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
110 changes: 110 additions & 0 deletions
110
tests/component-tests/apiGateway-tests/createMi.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,110 @@ | ||
| import {test, expect} from '@playwright/test'; | ||
| import { getRestApiGatewayBaseUrl } from "../../helpers/awsGatewayHelper"; | ||
| import { MI_ENDPOINT } from '../../constants/api_constants'; | ||
| import { createHeaderWithNoCorrelationId, createHeaderWithNoRequestId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers'; | ||
| import { miInvalidDateRequest, miInvalidRequest, miValidRequest } from './testCases/createMi'; | ||
| import { time } from 'console'; | ||
| import { error400InvalidDate, error400ResponseBody, error403ResponseBody, error404ResponseBody, requestId500Error } from '../../helpers/commonTypes'; | ||
|
|
||
| let baseUrl: string; | ||
|
|
||
| test.beforeAll(async () => { | ||
| baseUrl = await getRestApiGatewayBaseUrl(); | ||
| }); | ||
|
|
||
| test.describe('API Gateway Tests to Verify Mi Endpoint', () => { | ||
| test(`Post /mi returns 200 when a valid request is passed`, async ({ request }) => { | ||
|
|
||
| const headers = createValidRequestHeaders(); | ||
| const body = miValidRequest(); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(201); | ||
| expect(responseBody.data.attributes).toMatchObject({ | ||
| groupId: 'group123', | ||
| lineItem: 'envelope-business-standard', | ||
| quantity: 10, | ||
| specificationId: 'Test-Spec-Id', | ||
| stockRemaining: 100, | ||
| timestamp: body.data.attributes.timestamp, | ||
| }); | ||
| expect(responseBody.data.type).toBe('ManagementInformation'); | ||
| }); | ||
|
|
||
| test(`Post /mi returns 400 when a invalid request is passed`, async ({ request }) => { | ||
| const headers = createValidRequestHeaders(); | ||
| const body = miInvalidRequest(); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(400); | ||
| expect(responseBody).toMatchObject(error400ResponseBody()); | ||
| }); | ||
|
|
||
| test(`Post /mi returns 403 when a authentication header is not passed`, async ({ request }) => { | ||
| const headers = createInvalidRequestHeaders(); | ||
| const body = miValidRequest(); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(403); | ||
| expect(responseBody).toMatchObject(error403ResponseBody()); | ||
| }); | ||
|
|
||
| test(`Post /mi returns 500 when a correlationId is not passed`, async ({ request }) => { | ||
| const headers = createHeaderWithNoCorrelationId(); | ||
| const body = miValidRequest(); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const res = await response.json(); | ||
| expect(response.status()).toBe(500); | ||
| expect(res.errors[0].detail).toBe("The request headers don't contain the APIM correlation id"); | ||
| }); | ||
|
|
||
| test(`Post /mi returns 500 when a x-request-id is not passed`, async ({ request }) => { | ||
| const headers = createHeaderWithNoRequestId(); | ||
| const body = miValidRequest(); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(500); | ||
| expect(responseBody).toMatchObject(requestId500Error()); | ||
| }); | ||
|
|
||
| test(`Post /mi returns 400 when a invalid Date is passed`, async ({ request }) => { | ||
| const headers = createValidRequestHeaders(); | ||
| const body = miInvalidDateRequest(); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(400); | ||
| expect(responseBody).toMatchObject(error400InvalidDate()); | ||
| }); | ||
|
|
||
|
|
||
| }); |
71 changes: 71 additions & 0 deletions
71
tests/component-tests/apiGateway-tests/getLetterStatus.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,71 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper'; | ||
| import { getLettersBySupplier } from '../../helpers/generate_fetch_testData'; | ||
| import { SUPPLIER_LETTERS, SUPPLIERID } from '../../constants/api_constants'; | ||
| import { createValidRequestHeaders } from '../../constants/request_headers'; | ||
| import { error404ResponseBody, error500ResponseBody } from '../../helpers/commonTypes'; | ||
|
|
||
| let baseUrl: string; | ||
|
|
||
| test.beforeAll(async () => { | ||
| baseUrl = await getRestApiGatewayBaseUrl(); | ||
| }); | ||
|
|
||
| test.describe('API Gateway Tests to Verify Get Letter Status Endpoint', () => { | ||
| test(`Get /letters/{id} returns 200 and valid response for a given id`, async ({ request }) => { | ||
|
|
||
| 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 = createValidRequestHeaders(); | ||
| const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${letter.id}`, { | ||
| headers: headers, | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
|
|
||
| expect(response.status()).toBe(200); | ||
| expect(responseBody).toMatchObject({ | ||
| data:{ | ||
| attributes: { | ||
| status: 'PENDING', | ||
| specificationId: letter.specificationId, | ||
| groupId: letter.groupId, | ||
| }, | ||
| id: letter.id, | ||
| type: 'Letter' | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| test(`Get /letters/{id} returns 404 if no resource is found for id`, async ({ request }) => | ||
| { | ||
| const id = '11'; | ||
| const headers = createValidRequestHeaders(); | ||
| const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, { | ||
| headers: headers, | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(404); | ||
| expect(responseBody).toMatchObject(error404ResponseBody()); | ||
| }); | ||
|
|
||
| test(`Get /letters/{id} returns 500 if letter is not found for supplierId ${SUPPLIERID}`, async ({ request }) => | ||
| { | ||
| const id = 'non-existing-id-12345'; | ||
| const headers = createValidRequestHeaders(); | ||
| const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, { | ||
| headers: headers, | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(500); | ||
| expect(responseBody).toMatchObject(error500ResponseBody(id)); | ||
| }); | ||
|
|
||
| }); |
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
70 changes: 70 additions & 0 deletions
70
tests/component-tests/apiGateway-tests/testCases/createMi.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,70 @@ | ||
|
|
||
|
|
||
|
|
||
| export type MiRequestBody = { | ||
| data: { | ||
| type: string; | ||
| attributes: { | ||
| groupId: string; | ||
| lineItem: string; | ||
| quantity: number; | ||
| specificationId: string; | ||
| stockRemaining: number; | ||
| timestamp: string; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| export function miValidRequest() : MiRequestBody{ | ||
| let requestBody: MiRequestBody; | ||
|
|
||
| requestBody = { | ||
| data: { | ||
| attributes: { | ||
| groupId: 'group123', | ||
| lineItem: 'envelope-business-standard', | ||
| quantity: 10, | ||
| specificationId: 'Test-Spec-Id', | ||
| stockRemaining: 100, | ||
| timestamp: new Date().toISOString(), | ||
| }, | ||
| type: 'ManagementInformation', | ||
| }}; | ||
| return requestBody; | ||
| } | ||
|
|
||
| export function miInvalidRequest() : MiRequestBody{ | ||
| let requestBody: MiRequestBody; | ||
|
|
||
| requestBody = { | ||
| data: { | ||
| attributes: { | ||
| groupId: 'group123', | ||
| lineItem: 'envelope-business-standard', | ||
| quantity: 10, | ||
| specificationId: 'Test-Spec-Id', | ||
| stockRemaining: 100, | ||
| timestamp: new Date().toISOString(), | ||
| }, | ||
| type: '?', | ||
| }}; | ||
| return requestBody; | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export function miInvalidDateRequest() : MiRequestBody{ | ||
| let requestBody: MiRequestBody; | ||
|
|
||
| requestBody = { | ||
| data: { | ||
| attributes: { | ||
| groupId: 'group123', | ||
| lineItem: 'envelope-business-standard', | ||
| quantity: 10, | ||
| specificationId: 'Test-Spec-Id', | ||
| stockRemaining: 100, | ||
| timestamp: '2021-10-28T', | ||
| }, | ||
| type: 'ManagementInformation', | ||
| }}; | ||
| return requestBody; | ||
| } | ||
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
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.