test: add initial unit integration and e2e coverage
Adds the initial testing baseline for the project: Unit coverage: - Zod schemas for items, assignments, movements, categories, auth, recipients, users, and assets - password hashing and verification helpers - auth role helper functions Integration coverage with PostgreSQL Testcontainers: - item use-cases: create, duplicate names, delete constraints - assignment use-cases: create, insufficient stock, return, double return - asset use-cases: available/assigned creation and lifecycle transitions - user use-cases: create/update, uniqueness, admin safeguards, password reset - category use-cases: create/update/delete constraints - recipient use-cases: create/update and uniqueness constraints E2E smoke coverage with Playwright: - unauthenticated redirect to login - seeded admin login - dashboard load - admin users page - inventory items page - assignments page Also configures: - Vitest - Playwright - PostgreSQL Testcontainers helpers - deterministic E2E admin bootstrap - test artifact ignores Validation: - bun run test: 9 files / 37 tests passed - bun run test:e2e: 3 passed - bunx tsc --noEmit: passed - bunx prisma validate: passed
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { expect, type Page, test } from "@playwright/test"
|
||||
|
||||
async function signInAsAdmin(page: Page) {
|
||||
await page.goto("/login")
|
||||
await page.getByLabel("Username").fill("admin")
|
||||
await page.getByLabel("Password").fill("admin-password")
|
||||
await page.getByRole("button", { name: "Sign In" }).click()
|
||||
await expect(page).toHaveURL("/")
|
||||
}
|
||||
|
||||
test.describe("main app smoke", () => {
|
||||
test("redirects unauthenticated users to login", async ({ page }) => {
|
||||
await page.goto("/admin/users")
|
||||
|
||||
await expect(page).toHaveURL(/\/login/)
|
||||
await expect(page.getByLabel("Username")).toBeVisible()
|
||||
await expect(page.getByRole("button", { name: "Sign In" })).toBeVisible()
|
||||
})
|
||||
|
||||
test("signs in as seeded admin and opens the dashboard", async ({ page }) => {
|
||||
await signInAsAdmin(page)
|
||||
|
||||
await expect(page.getByRole("heading", { name: "Dashboard" })).toBeVisible()
|
||||
await expect(page.getByText("E2E Admin")).toBeVisible()
|
||||
await expect(
|
||||
page.getByRole("link", { name: /Stock Manager/i }),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("admin can open users and inventory pages", async ({ page }) => {
|
||||
await signInAsAdmin(page)
|
||||
|
||||
await page.getByRole("link", { name: "Users" }).click()
|
||||
await expect(page).toHaveURL(/\/admin\/users/)
|
||||
await expect(page.getByRole("heading", { name: "Users" })).toBeVisible()
|
||||
await expect(
|
||||
page.getByRole("cell", { name: "admin@example.test" }),
|
||||
).toBeVisible()
|
||||
|
||||
await page.goto("/inventory/items")
|
||||
await expect(page.getByRole("heading", { name: "Items" })).toBeVisible()
|
||||
await expect(page.getByText("No items found.")).toBeVisible()
|
||||
|
||||
await page.goto("/assignments")
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Assignments" }),
|
||||
).toBeVisible()
|
||||
await expect(page.getByText("No assignments found")).toBeVisible()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user