generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
CCM-12183 Component test for letter PDF #367
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
Open
varsha-vanbatte-nhs
wants to merge
9
commits into
main
Choose a base branch
from
feature/CCM-12183-geLetterPDF
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−1
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3a5b7e5
Added tests for letter PDF
varsha-vanbatte-nhs b71f30a
Fixed linting error
varsha-vanbatte-nhs a752225
Modified tests
varsha-vanbatte-nhs f7fc805
test ssh-sign
Namitha-Prabhu d45cd96
Merge branch 'main' into feature/CCM-12183-geLetterPDF
Namitha-Prabhu fcf7ea3
lint fix
Namitha-Prabhu c5d77f6
added comments for response.url
Namitha-Prabhu 2a488c3
lint
Namitha-Prabhu 47e350d
fix
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
104 changes: 104 additions & 0 deletions
104
tests/component-tests/apiGateway-tests/get-letter-pdf.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,104 @@ | ||
| import { expect, test } from "@playwright/test"; | ||
| import getRestApiGatewayBaseUrl from "../../helpers/aws-gateway-helper"; | ||
| import { getLettersBySupplier } from "../../helpers/generate-fetch-test-data"; | ||
| import { | ||
| DATA, | ||
| SUPPLIERID, | ||
| SUPPLIER_LETTERS, | ||
| } from "../../constants/api-constants"; | ||
| import { createValidRequestHeaders } from "../../constants/request-headers"; | ||
| import { | ||
| error404ResponseBody, | ||
| error500ResponseBody, | ||
| } from "../../helpers/common-types"; | ||
|
|
||
| let baseUrl: string; | ||
|
|
||
| test.beforeAll(async () => { | ||
| baseUrl = await getRestApiGatewayBaseUrl(); | ||
| }); | ||
|
|
||
| test.describe("API Gateway Tests to Verify Get Letter PDF Endpoint", () => { | ||
| test(`Get /letters/{id}/data 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}/${DATA}`, | ||
| { | ||
| headers, | ||
| }, | ||
| ); | ||
|
|
||
| expect(response.status()).toBe(200); | ||
| const responseBody = await response.text(); | ||
| expect(responseBody).toContain("PDF"); | ||
|
|
||
| async function fetchUrl(url: string) { | ||
| const res = await request.get(url, { headers }); | ||
| return { | ||
| status: res.status(), | ||
| headers: res.headers(), | ||
| buffer: await res.body().catch(() => null), | ||
| text: await res.text().catch(() => null), | ||
| }; | ||
| } | ||
|
|
||
| const pdfUrl = await response.url(); // function returns response url though get letter data will automatically redirect to the url in the Location header. | ||
| const parsed = new URL(pdfUrl); | ||
| const expiresParam = parsed.searchParams.get("X-Amz-Expires"); | ||
| const expiresSeconds = Number(expiresParam); | ||
| expect(expiresSeconds).toBe(60); | ||
|
|
||
| const waitMs = Math.max(expiresSeconds * 1000 + 2000, 0); | ||
| await new Promise((resolve) => { | ||
| setTimeout(resolve, waitMs); | ||
| }); | ||
|
|
||
| const after = await fetchUrl(pdfUrl); | ||
| expect(after.status).toBe(403); | ||
| }); | ||
|
|
||
| test(`Get /letters/{id}/data 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}/${DATA}`, | ||
| { | ||
| headers, | ||
| }, | ||
| ); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(404); | ||
| expect(responseBody).toMatchObject(error404ResponseBody()); | ||
| }); | ||
|
|
||
| // CCM-14318: Remove this test | ||
| test(`Get /letters/{id}/data returns 500 if letter is not found for supplierId ${SUPPLIERID}`, async ({ | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| request, | ||
| }) => { | ||
| const id = "non-existing-id-12345"; | ||
| const headers = createValidRequestHeaders(); | ||
| const response = await request.get( | ||
| ` | ||
| ${baseUrl}/${SUPPLIER_LETTERS}/${id}/${DATA}`, | ||
| { | ||
| headers, | ||
| }, | ||
| ); | ||
|
|
||
| const responseBody = await response.json(); | ||
| expect(response.status()).toBe(500); | ||
| expect(responseBody).toMatchObject(error500ResponseBody()); | ||
| }); | ||
| }); | ||
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
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.