Files
template-app/modules/inventory/__tests__/service.test.ts
T
2026-11-14 09:56:45 +00:00

37 lines
1.4 KiB
TypeScript

// Prepared request binding is required; injected test ports preserve kind capabilities.
import { AppError, Container } from "@conusai-kit/core"
import { describe, expect, it } from "vitest"
import { inventoryServiceOf } from "../adapters/service.js"
import { INVENTORY_SERVICE, type InventoryService } from "../core/ports.js"
const service = {
bindingId: "01900000-0000-7000-8000-000000000001",
createItem: async () => {
throw new Error("not called")
},
} as unknown as InventoryService
describe("inventoryServiceOf", () => {
it("hands a read handler the bound service's reads only, and an effect handler all of it", () => {
const root = new Container()
root.value(INVENTORY_SERVICE, service)
const read = inventoryServiceOf(root.restrict("read"), "read") as unknown as Record<string, unknown>
expect(read.createItem).toBeUndefined()
expect(read.bindingId).toBe("01900000-0000-7000-8000-000000000001")
expect(inventoryServiceOf(root.restrict("effect"), "effect").createItem).toBe(service.createItem)
})
it("refuses a request without a prepared partition binding", () => {
let thrown: unknown
try {
inventoryServiceOf(new Container(), "read")
} catch (error) {
thrown = error
}
expect(thrown).toBeInstanceOf(AppError)
expect((thrown as AppError).problem).toMatchObject({ status: 409, code: "service_partition_missing" })
expect((thrown as AppError).problem.detail).not.toContain("token")
})
})