Keep a continued draft on screen, ask before Edit drops rewritten copy, and retry clearing the draft after publish.

This commit is contained in:
adilallo committed 2026-11-22 18:31:07 -07:00
1 parent 54a4871ad1
commit 7c08766092
11 files changed
+361 -41

No files matched your search

+55 -6
View File
@@ -123,6 +123,60 @@ describe("POST /api/rules", () => {
expect(deleteRuleDraftForUserMock).toHaveBeenCalledWith("user-1");
});
it("retries draft deletion after publish and still returns the rule", async () => {
publishedRuleCreateMock.mockResolvedValueOnce({
id: "rule-solo",
title: "T",
summary: null,
createdAt: new Date("2026-01-01T00:00:00.000Z"),
});
deleteRuleDraftForUserMock
.mockRejectedValueOnce(new Error("draft delete failed"))
.mockResolvedValueOnce(undefined);
const res = await POST(
new NextRequest("https://x.test/api/rules", {
method: "POST",
body: JSON.stringify({
title: "T",
summary: null,
document: {},
}),
}),
undefined,
);
expect(res.status).toBe(200);
expect(deleteRuleDraftForUserMock).toHaveBeenCalledTimes(2);
});
it("publishes when draft deletion keeps failing", async () => {
publishedRuleCreateMock.mockResolvedValueOnce({
id: "rule-solo",
title: "T",
summary: null,
createdAt: new Date("2026-01-01T00:00:00.000Z"),
});
deleteRuleDraftForUserMock.mockRejectedValue(
new Error("draft delete failed"),
);
const res = await POST(
new NextRequest("https://x.test/api/rules", {
method: "POST",
body: JSON.stringify({
title: "T",
summary: null,
document: {},
}),
}),
undefined,
);
expect(res.status).toBe(200);
expect(deleteRuleDraftForUserMock).toHaveBeenCalledTimes(3);
});
it("stores place and group type from the published document", async () => {
publishedRuleCreateMock.mockResolvedValueOnce({
id: "rule-counts",
@@ -259,12 +313,7 @@ describe("POST /api/rules", () => {
createdAt: new Date("2026-01-02T00:00:00.000Z"),
};
transactionMock.mockImplementation(
async (
fn: (tx: {
publishedRule: { create: typeof vi.fn };
ruleStakeholder: { create: typeof vi.fn };
}) => Promise<unknown>,
) => {
async (fn: (tx: { publishedRule: { create: typeof vi.fn }; ruleStakeholder: { create: typeof vi.fn } }) => Promise<unknown>) => {
const tx = {
publishedRule: {
create: vi.fn().mockResolvedValue(created),