45 lines
2.1 KiB
TypeScript
45 lines
2.1 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, expect, test } from "vitest";
|
|
import { readFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import path from "node:path";
|
|
|
|
const source = readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), "users.db.server.ts"), "utf8");
|
|
|
|
describe("users db wrapper", () => {
|
|
test("allows user profile updates to persist light or dark mode", () => {
|
|
expect(source).toContain("lightOrDarkMode?: string");
|
|
});
|
|
|
|
test("provides a tenant-scoped user details helper for app routes", () => {
|
|
expect(source).toContain("export async function getTenantScopedUsersWithDetails(tenantId: string)");
|
|
expect(source).toContain("tenants: {\n where: {\n tenantId,\n },");
|
|
expect(source).toContain("roles: {\n where: {\n tenantId,\n },");
|
|
});
|
|
|
|
test("keeps core user registration free of CRM and marketing side effects", () => {
|
|
expect(source).not.toContain("~/modules/crm/services/CrmService");
|
|
expect(source).not.toContain("marketingSubscriber: true");
|
|
expect(source).not.toContain("Created user contact");
|
|
});
|
|
|
|
test("returns the persisted default tenant after user registration", () => {
|
|
expect(source).toContain("defaultTenantId: user.defaultTenantId");
|
|
});
|
|
|
|
test("parallelizes admin user pagination queries", () => {
|
|
expect(source).toContain("const [userRoots, totalItems] = await Promise.all([");
|
|
expect(source).toContain("db.user.findMany({");
|
|
expect(source).toContain("db.user.count({\n where,\n }),");
|
|
expect(source).toContain("const items = await hydrateAdminUserDetails(userRoots);");
|
|
});
|
|
|
|
test("consumes password-reset state with one conditional update", () => {
|
|
expect(source).toContain("export async function consumePasswordResetTokenAndUpdatePassword");
|
|
expect(source).toContain("verifyToken: expectedVerifyToken");
|
|
expect(source).toContain("equals: expectedVerifyTokenCreatedAt");
|
|
expect(source).toContain("gt: minimumVerifyTokenCreatedAt");
|
|
expect(source).toContain("if (result.count !== 1)");
|
|
});
|
|
});
|