Skip to content

Commit a752225

Browse files
Modified tests
1 parent b71f30a commit a752225

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

tests/component-tests/apiGateway-tests/get-letter-pdf.spec.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,44 @@ test.describe("API Gateway Tests to Verify Get Letter PDF Endpoint", () => {
3838
);
3939

4040
expect(response.status()).toBe(200);
41-
const responseBody = await response.text();
42-
expect(responseBody).toContain("PDF");
41+
// const responseBody = await response.text();
42+
// expect(responseBody).toContain("PDF");
43+
44+
async function fetchAndValidatePdf(url: string) {
45+
const res = await request.get(url, { headers });
46+
return {
47+
status: res.status(),
48+
headers: res.headers(),
49+
buffer: await res.body().catch(() => null),
50+
text: await res.text().catch(() => null),
51+
};
52+
}
53+
54+
const pdfUrl = await response.url();
55+
const parsed = new URL(pdfUrl);
56+
const expiresParam = parsed.searchParams.get("X-Amz-Expires");
57+
58+
expect(expiresParam).toBeTruthy();
59+
const expiresSeconds = Number(expiresParam);
60+
expect(Number.isFinite(expiresSeconds)).toBeTruthy();
61+
62+
// Validate the URL works immediately
63+
const url = await fetchAndValidatePdf(pdfUrl);
64+
expect(url.status).toBe(200);
65+
expect(url.headers["content-type"] || "").toContain("application/pdf");
66+
67+
const waitMs = Math.max(expiresSeconds * 1000 + 2000, 0);
68+
if (waitMs > 0) {
69+
// Cap wait to avoid extremely long waits
70+
const MAX_WAIT_MS = 120_000; // 2 minutes cap
71+
const effectiveWait = Math.min(waitMs, MAX_WAIT_MS);
72+
await new Promise((resolve) => {
73+
setTimeout(resolve, effectiveWait);
74+
});
75+
76+
const after = await fetchAndValidatePdf(pdfUrl);
77+
expect([400, 403]).toContain(after.status);
78+
}
4379
});
4480

4581
test(`Get /letters/{id}/data returns 404 if no resource is found for id`, async ({

tests/config/playwright.base.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const envMaxInstances = Number.parseInt(process.env.WORKERS_MAX_INST!) || 10;
88
*/
99
export const config: PlaywrightTestConfig = {
1010
/* Maximum time one test can run for. */
11-
timeout: 60 * 1000,
11+
timeout: 80 * 1000,
1212
workers: envMaxInstances,
1313
expect: {
1414
/**

0 commit comments

Comments
 (0)