-
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
base: feature/CCM-12180-TestsOnPipeline
Are you sure you want to change the base?
Changes from all commits
4b1a883
ecd00ba
49a25e8
18cfae8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 = { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| data: { | ||||||
| type: string; | ||||||
| id: string; | ||||||
| attributes: { | ||||||
| reasonCode?: string; | ||||||
| reasonText?: string; | ||||||
| status: string; | ||||||
| specificationId: string; | ||||||
| groupId?: string; | ||||||
| }; | ||||||
| }; | ||||||
| }; | ||||||
|
|
||||||
| export function postRequestHeaders(): RequestHeaders { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| let requestHeaders: RequestHeaders; | ||||||
| requestHeaders = { | ||||||
| "NHSD-Supplier-ID": SUPPLIERID, | ||||||
| "NHSD-Correlation-ID": "12344", | ||||||
| "X-Request-ID": "requestId1", | ||||||
| }; | ||||||
| return requestHeaders; | ||||||
| } | ||||||
|
|
||||||
| export function postInvalidRequestHeaders(): RequestHeaders { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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 = { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth including the reasonText and reasonCode in at least one of these? |
||||||
| 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; | ||||||
| } | ||||||
| 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()); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,16 @@ | ||||||
| export type PostMessageRequestBody = { | ||||||
| data: PostRequest[]; | ||||||
| }; | ||||||
|
|
||||||
| type PostRequest = { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| type: string; | ||||||
| id: string; | ||||||
| attributes: { | ||||||
| reasonCode?: string; | ||||||
| reasonText?: string; | ||||||
| status: string; | ||||||
| }; | ||||||
| }; | ||||||
|
|
||||||
| export type ErrorLink = { | ||||||
| about: string; | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response body of the
POST /lettersis empty - it only returns a 202 (accepted).See https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier#post-/letters