Skip to content

Commit

Permalink
Add Join Record to more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Nov 1, 2024
1 parent 01591a0 commit 03aad06
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/join_form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
submitAndCheckToast,
expectSuccess,
sampleJoinRecord,
findJoinRecord,
} from "@/tests/util";
import { isDeepStrictEqual } from "util";

Expand Down Expand Up @@ -89,8 +90,22 @@ test("confirm city", async ({ page }) => {

await submitConfirmationDialogExpected(page, 2000);

// Check that the Join Record's code is correct.
let joinRecord = await findJoinRecord(page);
let code = "409"
if (joinRecord.code !== code) {
throw new Error(`JoinRecord code (${joinRecord.code}) did not match expected code (${code})`);
}

await page.locator("[name='confirm']").click();

// Make sure the JoinRecord updated properly
await page.waitForTimeout(1000);
joinRecord = await findJoinRecord(page);
if (joinRecord.code !== "201") {
throw new Error(`JoinRecord code (${joinRecord.code}) did not match expected code (201)`);
}

await expectSuccess(page, 1000);
});

Expand Down Expand Up @@ -358,4 +373,11 @@ test("fail nj", async ({ page }) => {
page,
"Non-NYC registrations are not supported at this time",
);

// Check that the Join Record's code is correct.
let joinRecord = await findJoinRecord(page);
let code = "400"
if (joinRecord.code !== code) {
throw new Error(`JoinRecord code (${joinRecord.code}) did not match expected code (${code})`);
}
});
17 changes: 17 additions & 0 deletions tests/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getJoinRecordFromS3 } from "@/app/join_record";
import { JoinRecord } from "@/app/types";
import { JoinFormValues } from "@/components/JoinForm/JoinForm";
import { expect, Page } from "@playwright/test";
Expand Down Expand Up @@ -163,3 +164,19 @@ export async function submitConfirmationDialogExpected(
await page.waitForTimeout(timeout);
await expect(page.locator("[id='alert-dialog-title']")).toBeVisible();
}

export async function findJoinRecord(page: Page): Promise<JoinRecord> {
const joinRecordKey = await page.getAttribute(
'[data-testid="test-join-record-key"]',
"data-state",
);

if (joinRecordKey === null) {
throw new Error("Got null join record");
}

// This is wacky because playwright has to run this and therefore
// needs our dotenv.
const joinRecord: JoinRecord = await getJoinRecordFromS3(joinRecordKey);
return joinRecord;
}

0 comments on commit 03aad06

Please sign in to comment.