Fix issue #96: When right clicking actor on foundry, show action to force sync to dragonroll
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-15 22:53:03 +00:00
parent dcc6d7a14b
commit 967c704801
7 changed files with 115 additions and 14 deletions

View File

@@ -328,6 +328,46 @@ test("an actor the world has never been seen as becomes one row, and the next im
assert.equal(sync.models["../models/Actor"].rows[0].foundryActorId, "actor-9");
});
// A forced sync from the module's context menu (Syndria98/dragonroll#96) replaces
// everything the campaign holds for the actor; a live change is a merge and leaves the
// fields the world says nothing about to the campaign.
test("a forced actor sync clears what the campaign wrote; a live change keeps it", async () => {
const sync = loadFoundryWriters({
seed: { actors: [{
_id: "actor-1",
name: "Thalia",
foundryActorId: "actor-1",
traits: "A trait the campaign wrote",
tools: ["Thieves' tools"],
languages: ["Elvish"],
skills: { perception: true },
savingThrows: { dex: true },
currency: { gp: 50 },
}] },
});
// The world says nothing about any of those: the fields a live edit leaves out.
const worldActor = { _id: "actor-1", name: "Thalia", type: "character", system: {} };
await sync.writers.saveFoundryActor(sync.campaign, worldActor, false, false);
let row = sync.models["../models/Actor"].rows[0];
assert.equal(row.traits, "A trait the campaign wrote", "a live push leaves what the campaign wrote alone");
assert.deepEqual(row.tools, ["Thieves' tools"]);
assert.deepEqual(row.languages, ["Elvish"]);
assert.deepEqual(row.skills, { perception: true });
assert.deepEqual(row.savingThrows, { dex: true });
assert.deepEqual(row.currency, { gp: 50 });
await sync.writers.saveFoundryActor(sync.campaign, worldActor, false, true);
row = sync.models["../models/Actor"].rows[0];
assert.equal(row.name, "Thalia", "the actor is still the one the world sent");
assert.equal(row.traits, "", "a forced sync clears the trait the campaign wrote");
assert.deepEqual(row.tools, [], "and the tools, languages, skills, saving throws and coin it held");
assert.deepEqual(row.languages, []);
assert.deepEqual(row.skills, {});
assert.deepEqual(row.savingThrows, {});
assert.deepEqual(row.currency, {});
});
test("a hand-made item folds into the import instead of doubling, and keeps being updated", async () => {
const sync = loadFoundryWriters({
seed: { items: [{ _id: "item-1", name: "Longsword", quantity: 1 }] },