42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { expect, Page, test } from "@playwright/test";
|
|
import { applyDeterministicPage, e2eHeaders, useE2EUser } from "./helpers.ts";
|
|
|
|
test("lease acceptance workflow (E2E fixtures)", async ({ page }: { page: Page }) => {
|
|
await applyDeterministicPage(page);
|
|
|
|
// Landlord side: navigate to leased homes
|
|
await useE2EUser(page, "landlord");
|
|
await page.goto("/landlord/dashboard");
|
|
const link = page.getByRole("link", { name: /create new lease/i });
|
|
if (await link.count()) {
|
|
await link.click();
|
|
} else {
|
|
await page.goto("/leased-home");
|
|
}
|
|
await expect(page.getByRole("heading", { name: /leased homes/i }))
|
|
.toBeVisible();
|
|
|
|
// Create an invite for an existing e2e lease (server-side fixture)
|
|
const inviteResp = await page.request.post("/api/update/lease_invite", {
|
|
headers: { "Content-Type": "application/json", ...e2eHeaders("landlord") },
|
|
data: { lease_id: "e2e-lease-1" },
|
|
});
|
|
expect(inviteResp.ok()).toBeTruthy();
|
|
|
|
// Tenant accepts the lease
|
|
await useE2EUser(page, "tenant");
|
|
const acceptResp = await page.request.post("/api/update/lease_accept", {
|
|
headers: { "Content-Type": "application/json", ...e2eHeaders("tenant") },
|
|
data: { lease_id: "e2e-lease-1" },
|
|
});
|
|
expect(acceptResp.ok()).toBeTruthy();
|
|
|
|
const body = await acceptResp.json();
|
|
expect(body?.success).toBeTruthy();
|
|
// The response may include the updated lease; ensure status is active if present
|
|
const lease = body?.lease;
|
|
if (lease) {
|
|
expect(lease.lease_status === "active").toBeTruthy();
|
|
}
|
|
});
|