fix(housekeeping): address task 14 review round 2
This commit is contained in:
1 parent
d09eaa33d6
commit
c524b305d7
17 files changed
+614
-130
No files matched your search
+53
-1
@@ -2,6 +2,18 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { HousekeepingCapabilityContext } from "../../../foundation/contracts";
|
||||
import { executeContentDatabaseMutation } from "./mutation-runtime-database";
|
||||
|
||||
const sqlMocks = vi.hoisted(() => ({
|
||||
join: vi.fn((chunks: unknown[], separator: unknown) => ({
|
||||
chunks,
|
||||
separator,
|
||||
})),
|
||||
raw: vi.fn((statement: string) => statement),
|
||||
tagged: vi.fn((strings: TemplateStringsArray, ...values: unknown[]) => ({
|
||||
strings: Array.from(strings),
|
||||
values,
|
||||
})),
|
||||
}));
|
||||
|
||||
const database = vi.hoisted(() => {
|
||||
let selected: Record<string, unknown> = { id: 7, title: "Existing" };
|
||||
const set = vi.fn((values: Record<string, unknown>) => ({
|
||||
@@ -13,7 +25,9 @@ const database = vi.hoisted(() => {
|
||||
const where = vi.fn(() => ({ limit }));
|
||||
const from = vi.fn(() => ({ where }));
|
||||
const select = vi.fn(() => ({ from }));
|
||||
const execute = vi.fn(async () => undefined);
|
||||
return {
|
||||
execute,
|
||||
set,
|
||||
update,
|
||||
select,
|
||||
@@ -25,12 +39,16 @@ const database = vi.hoisted(() => {
|
||||
|
||||
vi.mock("drizzle-orm", () => ({
|
||||
eq: vi.fn(),
|
||||
sql: Object.assign(vi.fn(), { raw: vi.fn() }),
|
||||
sql: Object.assign(sqlMocks.tagged, {
|
||||
join: sqlMocks.join,
|
||||
raw: sqlMocks.raw,
|
||||
}),
|
||||
}));
|
||||
vi.mock("@/lib/db", () => {
|
||||
const table = new Proxy({}, { get: (_target, key) => String(key) });
|
||||
return {
|
||||
db: {
|
||||
execute: database.execute,
|
||||
select: database.select,
|
||||
update: database.update,
|
||||
},
|
||||
@@ -142,4 +160,38 @@ describe("Content database mutation runtime partial updates", () => {
|
||||
expect(database.set.mock.calls[0]?.[0]).toHaveProperty(expectedKey);
|
||||
},
|
||||
);
|
||||
|
||||
it("updates only submitted prefix columns and preserves omitted icon, effect, and active", async () => {
|
||||
const snapshot = await executeContentDatabaseMutation(
|
||||
"prefix.change",
|
||||
{ action: "update", id: 7, text: "Renamed" },
|
||||
context,
|
||||
undefined,
|
||||
);
|
||||
const assignments = sqlMocks.join.mock.calls.at(-1)?.[0] as
|
||||
| Array<{ strings: string[]; values: unknown[] }>
|
||||
| undefined;
|
||||
expect(assignments).toHaveLength(1);
|
||||
expect(assignments?.[0]?.strings.join(" ")).toContain("text =");
|
||||
expect(assignments?.[0]?.strings.join(" ")).not.toMatch(
|
||||
/icon|effect|active/u,
|
||||
);
|
||||
expect(snapshot?.after).toEqual({ id: 7, text: "Renamed" });
|
||||
});
|
||||
|
||||
it("submits an explicit false prefix active patch without touching other columns", async () => {
|
||||
const snapshot = await executeContentDatabaseMutation(
|
||||
"prefix.change",
|
||||
{ action: "update", id: 7, active: false },
|
||||
context,
|
||||
undefined,
|
||||
);
|
||||
const assignments = sqlMocks.join.mock.calls.at(-1)?.[0] as
|
||||
| Array<{ strings: string[]; values: unknown[] }>
|
||||
| undefined;
|
||||
expect(assignments).toHaveLength(1);
|
||||
expect(assignments?.[0]?.strings.join(" ")).toContain("active =");
|
||||
expect(assignments?.[0]?.values).toEqual([0]);
|
||||
expect(snapshot?.after).toEqual({ id: 7, active: 0 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user