Fix issue #61: Fix tests
Some checks failed
Test / test (push) Successful in 2s
Build and Deploy Nuxt / build (push) Has been cancelled

This commit is contained in:
Gitea OpenCode Agent
2026-10-15 14:20:26 +00:00
committed by Aran Roig
parent cdafd1f53a
commit 0567096588
5 changed files with 46 additions and 13 deletions

View File

@@ -57,7 +57,7 @@ function matches(document, filter = {}) {
});
}
function fakeModel(table, seed = []) {
function fakeModel(table, seed = [], campaignId) {
const rows = [];
let counter = 0;
@@ -76,7 +76,9 @@ function fakeModel(table, seed = []) {
Object.defineProperty(Document.prototype, "id", { get() { return this._id; } });
for (const data of seed) {
const row = new Document({ [table === "folder" ? "target" : "name"]: undefined, ...data });
// A seeded row belongs to the campaign the requests are made against unless the
// seed says otherwise: the routes scope every lookup by campaign.
const row = new Document({ campaign: campaignId, [table === "folder" ? "target" : "name"]: undefined, ...data });
row.isNew = false;
rows.push(row);
}
@@ -373,9 +375,12 @@ test("every folder listing says which campaign list it belongs to", () => {
// field existed carry none at all. tests/entry-folders.test.js runs these routes.
for (const route of ["note.js", "folder.js"]) {
const source = read("backend", "src", "routes", route);
const listings = source.match(/Folder\.find\(/g) ?? [];
// The listings that gather a campaign's folders are the ones shown as a section's
// tree. A walk of one folder's own children (`parentFolder`) is inside a single
// list already: folders are only ever nested within their own section.
const listings = source.match(/Folder\.find\(\{\s*campaign/g) ?? [];
assert.ok(listings.length, `${route} lists folders`);
const filtered = source.match(/Folder\.find\(\{[^{]*Folder\.filterForTarget\((?:'note'|target)\)/g) ?? [];
const filtered = source.match(/Folder\.find\(\{\s*campaign[^{]*Folder\.filterForTarget\((?:'note'|target)\)/g) ?? [];
assert.equal(filtered.length, listings.length, `${route} has a folder listing that names no campaign list`);
}
});
@@ -725,13 +730,15 @@ test("items are grouped under the folder they stand in, nested", () => {
row.kind, row.kind === "folder" ? row.folder.name : row.item.name, row.depth,
]);
// Every folder is followed by what stands in it, one step deeper, and the items that
// stand at the root come last (see BuildItemRows).
assert.deepEqual(shape, [
["folder", "Melee Weapons", 0],
["item", "Longsword", 1],
["folder", "Ranged Weapons", 0],
["folder", "Powder Weapons", 1],
["item", "Pistol", 1],
["item", "Pistol", 2],
["item", "Torch", 0],
["item", "Longsword", 1],
]);
});
@@ -758,9 +765,9 @@ test("an item whose folder is gone, or a folder nested in itself, reads as a roo
);
const shape = rows.map((row) => [row.kind, row.kind === "folder" ? row.folder.name : row.item.name]);
assert.ok(shape.includes(["item", "Torch"]), "the item is not lost with the folder that was removed");
assert.ok(shape.some(([kind, name]) => kind === "item" && name === "Torch"), "the item is not lost with the folder that was removed");
assert.deepEqual(new Set(shape.filter(([kind]) => kind === "folder").map(([, name]) => name)), new Set(["A", "B"]));
assert.equal(rows.filter(([kind]) => kind === "folder").length, 2, "a broken tree is walked once, not forever");
assert.equal(shape.filter(([kind]) => kind === "folder").length, 2, "a broken tree is walked once, not forever");
});
test("every locale labels the folder row", () => {