generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/ccm-13151 post endpoint #325
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
Closed
varsha-vanbatte-nhs
wants to merge
4
commits into
feature/CCM-12180-TestsOnPipeline
from
feature/CCM-13151-PostEndpoint
+343
−30
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b1a883
comments for merge
varsha-vanbatte-nhs ecd00ba
Merge remote-tracking branch 'refs/remotes/origin/feature/CCM-12180-T…
varsha-vanbatte-nhs 49a25e8
Ok
varsha-vanbatte-nhs 18cfae8
Merge remote-tracking branch 'origin/feature/CCM-12180-TestsOnPipelin…
francisco-videira-nhs 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
197 changes: 197 additions & 0 deletions
197
tests/component-tests/apiGateway-tests/testCases/update-multiple-letter-status.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,197 @@ | ||
| import { RequestHeaders } from "../../../constants/request-headers"; | ||
| import { SUPPLIERID } from "../../../constants/api-constants"; | ||
| import { | ||
| ErrorMessageBody, | ||
| PostMessageRequestBody, | ||
| } from "../../../helpers/common-types"; | ||
| import { SupplierApiLetters } from "../../../helpers/generate-fetch-test-data"; | ||
|
|
||
| export type PostMessageResponseBody = { | ||
varsha-vanbatte-nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| data: { | ||
| type: string; | ||
| id: string; | ||
| attributes: { | ||
| reasonCode?: string; | ||
| reasonText?: string; | ||
| status: string; | ||
| specificationId: string; | ||
| groupId?: string; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| export function postRequestHeaders(): RequestHeaders { | ||
varsha-vanbatte-nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let requestHeaders: RequestHeaders; | ||
| requestHeaders = { | ||
| "NHSD-Supplier-ID": SUPPLIERID, | ||
| "NHSD-Correlation-ID": "12344", | ||
| "X-Request-ID": "requestId1", | ||
| }; | ||
| return requestHeaders; | ||
| } | ||
|
|
||
| export function postInvalidRequestHeaders(): RequestHeaders { | ||
varsha-vanbatte-nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let requestHeaders: RequestHeaders; | ||
| requestHeaders = { | ||
| "NHSD-Supplier-ID": SUPPLIERID, | ||
| "NHSD-Correlation-ID": "12344", | ||
| // Request Id is missing | ||
| }; | ||
| return requestHeaders; | ||
| } | ||
|
|
||
| export function postValidRequestBody( | ||
| letters: SupplierApiLetters[], | ||
| ): PostMessageRequestBody { | ||
| let requestBody: PostMessageRequestBody; | ||
|
|
||
| requestBody = { | ||
varsha-vanbatte-nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| data: [ | ||
| { | ||
| type: "Letter", | ||
| id: letters[0].id, | ||
| attributes: { | ||
| status: "ACCEPTED", | ||
| }, | ||
| }, | ||
| { | ||
| type: "Letter", | ||
| id: letters[1].id, | ||
| attributes: { | ||
| status: "REJECTED", | ||
| }, | ||
| }, | ||
| { | ||
| type: "Letter", | ||
| id: letters[2].id, | ||
| attributes: { | ||
| status: "PRINTED", | ||
| }, | ||
| }, | ||
| { | ||
| type: "Letter", | ||
| id: letters[3].id, | ||
| attributes: { | ||
| status: "CANCELLED", | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
| return requestBody; | ||
| } | ||
|
|
||
| export function postInvalidStatusRequestBody( | ||
| letters: SupplierApiLetters[], | ||
| ): PostMessageRequestBody { | ||
| let requestBody: PostMessageRequestBody; | ||
|
|
||
| requestBody = { | ||
| data: [ | ||
| { | ||
| type: "Letter", | ||
| id: letters[0].id, | ||
| attributes: { | ||
| status: "ACCEPTED", | ||
| }, | ||
| }, | ||
| { | ||
| type: "Letter", | ||
| id: letters[1].id, | ||
| attributes: { | ||
| status: "SENDING", // Invalid letter status | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
| return requestBody; | ||
| } | ||
|
|
||
| export function postDuplicateIDRequestBody( | ||
| letters: SupplierApiLetters[], | ||
| ): PostMessageRequestBody { | ||
| let requestBody: PostMessageRequestBody; | ||
|
|
||
| requestBody = { | ||
| data: [ | ||
| { | ||
| type: "Letter", | ||
| id: letters[0].id, | ||
| attributes: { | ||
| status: "ACCEPTED", | ||
| }, | ||
| }, | ||
| { | ||
| type: "Letter", | ||
| id: letters[0].id, // Duplicate id | ||
| attributes: { | ||
| status: "REJECTED", | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
| return requestBody; | ||
| } | ||
|
|
||
| export function postInvalidStatusResponseBody(): 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 postDuplicateIDResponseBody(): 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 cannot include multiple letter objects with the same id", | ||
| }, | ||
| ], | ||
| }; | ||
| return responseBody; | ||
| } | ||
|
|
||
| export function post500ErrorResponseBody(): 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: "Unexpected error", | ||
| }, | ||
| ], | ||
| }; | ||
| return responseBody; | ||
| } | ||
122 changes: 122 additions & 0 deletions
122
tests/component-tests/apiGateway-tests/update-multiple-letter-status.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,122 @@ | ||
| import { expect, test } from "@playwright/test"; | ||
| import { SUPPLIERID, SUPPLIER_LETTERS } from "../../constants/api-constants"; | ||
| import getRestApiGatewayBaseUrl from "../../helpers/aws-gateway-helper"; | ||
| import { | ||
| post500ErrorResponseBody, | ||
| postDuplicateIDRequestBody, | ||
| postDuplicateIDResponseBody, | ||
| postInvalidRequestHeaders, | ||
| postInvalidStatusRequestBody, | ||
| postInvalidStatusResponseBody, | ||
| postRequestHeaders, | ||
| postValidRequestBody, | ||
| } from "./testCases/update-multiple-letter-status"; | ||
| import { | ||
| createTestData, | ||
| getLettersBySupplier, | ||
| } from "../../helpers/generate-fetch-test-data"; | ||
|
|
||
| let baseUrl: string; | ||
|
|
||
| test.beforeAll(async () => { | ||
| baseUrl = await getRestApiGatewayBaseUrl(); | ||
| }); | ||
|
|
||
| test.describe("API Gateway Tests to Verify post Status Endpoint", () => { | ||
| test(`post /letters returns 202 and status is updated for multiple letters`, async ({ | ||
| request, | ||
| }) => { | ||
| await createTestData(SUPPLIERID, 4); | ||
| const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 4); | ||
|
|
||
| if (!letters?.length) { | ||
| test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); | ||
| return; | ||
| } | ||
|
|
||
| const headers = postRequestHeaders(); | ||
| const body = postValidRequestBody(letters); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, { | ||
| headers, | ||
| data: body, | ||
| }); | ||
|
|
||
| expect(response.status()).toBe(202); | ||
| }); | ||
|
|
||
| test(`Post /letters returns 400 if request has invalid status`, async ({ | ||
| request, | ||
| }) => { | ||
| await createTestData(SUPPLIERID, 2); | ||
| const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 2); | ||
|
|
||
| if (!letters?.length) { | ||
| test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); | ||
| return; | ||
| } | ||
|
|
||
| const headers = postRequestHeaders(); | ||
| const body = postInvalidStatusRequestBody(letters); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, { | ||
| headers, | ||
| data: body, | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
|
|
||
| expect(response.status()).toBe(400); | ||
| expect(responseBody).toMatchObject(postInvalidStatusResponseBody()); | ||
| }); | ||
|
|
||
| test(`Post /letters returns 400 if request has duplicate id`, async ({ | ||
| request, | ||
| }) => { | ||
| await createTestData(SUPPLIERID, 2); | ||
| const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 2); | ||
|
|
||
| if (!letters?.length) { | ||
| test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); | ||
| return; | ||
| } | ||
|
|
||
| const headers = postRequestHeaders(); | ||
| const body = postDuplicateIDRequestBody(letters); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, { | ||
| headers, | ||
| data: body, | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
|
|
||
| expect(response.status()).toBe(400); | ||
| expect(responseBody).toMatchObject(postDuplicateIDResponseBody()); | ||
| }); | ||
|
|
||
| test(`Post /letters returns 500 if request has invalid header`, async ({ | ||
| request, | ||
| }) => { | ||
| await createTestData(SUPPLIERID, 4); | ||
| const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 4); | ||
|
|
||
| if (!letters?.length) { | ||
| test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); | ||
| return; | ||
| } | ||
|
|
||
| const headers = postInvalidRequestHeaders(); | ||
| const body = postValidRequestBody(letters); | ||
|
|
||
| const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, { | ||
| headers, | ||
| data: body, | ||
| }); | ||
|
|
||
| const responseBody = await response.json(); | ||
|
|
||
| expect(response.status()).toBe(500); | ||
| expect(responseBody).toMatchObject(post500ErrorResponseBody()); | ||
| }); | ||
| }); |
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.