Fix issue #67: Don't show all items on the items sidebar
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-15 16:40:15 +00:00
parent 0caacf434f
commit 495e528124
5 changed files with 103 additions and 37 deletions

View File

@@ -299,6 +299,76 @@ test("an item the world moved out of a folder follows it to the root", async ()
assert.equal(sync.models["../models/Item"].rows[0].folder, null);
});
// --- Only the world's item directory is listed (Syndria98/dragonroll#67) --------------
// The campaign's item list equals the world's items tab: gear that only an actor
// carries is its inventory (kept on the actor document), not a Dragonroll item.
test("an actor's gear is kept off the campaign's item list", async () => {
const sync = loadSyncRoute();
await sync.call("POST /sync/snapshot", {
worldId: "world-1",
items: [worldItem()],
// Thalia carries a potion the world's item directory does not hold.
actors: [{
_id: "actor-1",
name: "Thalia",
items: [{ _id: "potion-1", name: "Potion of Healing", type: "consumable", system: { quantity: 2 } }],
}],
});
const names = sync.models["../models/Item"].rows.map((row) => row.name);
assert.deepEqual(names, ["Longsword"], "only the world's item reaches the list, not the actor's potion");
});
test("the campaign's item list is the world's whole item directory", async () => {
const sync = loadSyncRoute();
await sync.call("POST /sync/snapshot", {
worldId: "world-1",
items: [worldItem(), worldItem({ _id: "item-2", name: "Torch", type: "loot", system: { quantity: 1 } })],
actors: [],
});
assert.deepEqual(
sync.models["../models/Item"].rows.map((row) => row.name).sort(),
["Longsword", "Torch"],
);
});
test("an item carried by a character is listed once, as its world entry", async () => {
const sync = loadSyncRoute();
await sync.call("POST /sync/snapshot", {
worldId: "world-1",
items: [worldItem()],
// The same sword, a second copy embedded in an actor under another id.
actors: [{ _id: "actor-1", name: "Thalia", items: [worldItem({ _id: "sword-copy" })] }],
});
assert.deepEqual(sync.models["../models/Item"].rows.map((row) => row.name), ["Longsword"]);
});
test("a full snapshot prunes gear that only an actor carried", async () => {
const sync = loadSyncRoute({
seed: { items: [{ _id: "potion-1", name: "Potion of Healing", foundryItemId: "embedded-1" }] },
});
// The world's item directory is now empty: nothing but a character holds the potion.
await sync.call("POST /sync/snapshot", {
worldId: "world-1",
items: [],
actors: [{
_id: "actor-1",
name: "Thalia",
items: [{ _id: "embedded-1", name: "Potion of Healing", type: "consumable", system: { quantity: 2 } }],
}],
fullSync: true,
});
assert.deepEqual(sync.models["../models/Item"].rows, [], "the actor's own gear no longer stands in the item list");
});
test("a folder coloured in the world is coloured in the campaign", async () => {
const sync = loadSyncRoute();