feat: add item duplication with copy-and-edit workflow
Adds POST /api/items/:id/duplicate endpoint, useDuplicateItem hook, and a Duplicate button on ItemCard (collection view only) that opens the new item for editing immediately after creation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -118,4 +118,30 @@ describe("Item Routes", () => {
|
||||
const res = await app.request("/api/items/9999");
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
|
||||
it("POST /api/items/:id/duplicate returns 201 with the copy", async () => {
|
||||
const createRes = await app.request("/api/items", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name: "Tent", categoryId: 1, weightGrams: 1200 }),
|
||||
});
|
||||
const created = await createRes.json();
|
||||
|
||||
const res = await app.request(`/api/items/${created.id}/duplicate`, {
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
expect(res.status).toBe(201);
|
||||
const body = await res.json();
|
||||
expect(body.name).toBe("Tent (copy)");
|
||||
expect(body.weightGrams).toBe(1200);
|
||||
expect(body.id).not.toBe(created.id);
|
||||
});
|
||||
|
||||
it("POST /api/items/999/duplicate returns 404", async () => {
|
||||
const res = await app.request("/api/items/999/duplicate", {
|
||||
method: "POST",
|
||||
});
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user