feat(web): add public commission request entrypoint

This commit is contained in:
2026-02-12 21:35:34 +01:00
parent dc0a41a5ae
commit 1fddb6d858
12 changed files with 441 additions and 9 deletions

View File

@@ -2,9 +2,12 @@ import { beforeEach, describe, expect, it, vi } from "vitest"
const { mockDb } = vi.hoisted(() => ({
mockDb: {
$transaction: vi.fn(),
customer: {
create: vi.fn(),
findFirst: vi.fn(),
findMany: vi.fn(),
update: vi.fn(),
},
commission: {
create: vi.fn(),
@@ -18,17 +21,29 @@ vi.mock("./client", () => ({
db: mockDb,
}))
import { createCommission, createCustomer, updateCommissionStatus } from "./commissions"
import {
createCommission,
createCustomer,
createPublicCommissionRequest,
updateCommissionStatus,
} from "./commissions"
describe("commissions service", () => {
beforeEach(() => {
for (const value of Object.values(mockDb)) {
if (typeof value === "function") {
value.mockReset()
continue
}
for (const fn of Object.values(value)) {
if (typeof fn === "function") {
fn.mockReset()
}
}
}
mockDb.$transaction.mockImplementation(async (callback) => callback(mockDb))
})
it("creates customer and commission payloads", async () => {
@@ -51,6 +66,37 @@ describe("commissions service", () => {
expect(mockDb.commission.create).toHaveBeenCalledTimes(1)
})
it("creates a public commission request with customer upsert behavior", async () => {
mockDb.customer.findFirst.mockResolvedValue({
id: "customer-existing",
phone: null,
instagram: null,
})
mockDb.customer.update.mockResolvedValue({
id: "customer-existing",
})
mockDb.commission.create.mockResolvedValue({
id: "commission-2",
})
await createPublicCommissionRequest({
customerName: "Grace Hopper",
customerEmail: "GRACE@EXAMPLE.COM",
customerPhone: "12345",
title: "Landscape commission",
description: "Oil painting request",
budgetMin: 500,
budgetMax: 900,
})
expect(mockDb.customer.findFirst).toHaveBeenCalledWith({
where: { email: "grace@example.com" },
orderBy: { updatedAt: "desc" },
})
expect(mockDb.customer.update).toHaveBeenCalledTimes(1)
expect(mockDb.commission.create).toHaveBeenCalledTimes(1)
})
it("updates commission status", async () => {
mockDb.commission.update.mockResolvedValue({ id: "commission-1", status: "done" })