Merge branch 'master' into ai/issue-98
All checks were successful
Test / test (push) Successful in 2s
All checks were successful
Test / test (push) Successful in 2s
This commit is contained in:
@@ -410,6 +410,36 @@ test("an actor that holds no traits does not clear what the campaign has", () =>
|
||||
assert.ok(!("traits" in character), "a live edit that knows nothing about traits leaves the tab as it is");
|
||||
});
|
||||
|
||||
// A forced actor sync from the module's context menu replaces everything the campaign
|
||||
// holds for that actor (Syndria98/dragonroll#96): the fields a live edit leaves out when
|
||||
// the world says nothing are written empty instead of kept, and the campaign's own text
|
||||
// on the actor's flag does not survive it.
|
||||
test("a forced sync writes empty the fields a live edit would leave out", () => {
|
||||
const actor = {
|
||||
name: "Thalia",
|
||||
system: {},
|
||||
items: [],
|
||||
flags: { [MODULE_ID]: { traits: "What the campaign typed", proficiencies: "Armour, tools" } },
|
||||
};
|
||||
|
||||
const live = foundryActorToCharacter(actor);
|
||||
assert.equal(live.traits, "What the campaign typed", "a live edit fills the traits tab from the actor's flag");
|
||||
assert.equal(live.proficiencies, "Armour, tools", "and the free-text proficiencies from it too");
|
||||
assert.ok(
|
||||
!("tools" in live) && !("languages" in live) && !("skills" in live) && !("savingThrows" in live) && !("currency" in live),
|
||||
"and says nothing about the toggles and lists the world has no data for"
|
||||
);
|
||||
|
||||
const replaced = foundryActorToCharacter(actor, true);
|
||||
assert.equal(replaced.traits, "", "a forced sync clears the traits the campaign typed");
|
||||
assert.equal(replaced.proficiencies, "", "down to the free-text proficiencies");
|
||||
assert.deepEqual(replaced.tools, []);
|
||||
assert.deepEqual(replaced.languages, []);
|
||||
assert.deepEqual(replaced.skills, {});
|
||||
assert.deepEqual(replaced.savingThrows, {});
|
||||
assert.deepEqual(replaced.currency, {});
|
||||
});
|
||||
|
||||
// --- The module sends the names a sheet outside Foundry can read -----------------
|
||||
|
||||
function makeWorld({ actor, config = {}, worldItems = [] }) {
|
||||
|
||||
@@ -329,6 +329,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 }] },
|
||||
|
||||
@@ -207,6 +207,7 @@ test("autosync on: Foundry CRUD events keep syncing with Dragonroll", async () =
|
||||
const pushes = world.syncRequests();
|
||||
assert.equal(pushes.length, 1);
|
||||
assert.equal(pushes[0].body.actors[0]._id, "actor-1");
|
||||
assert.equal(pushes[0].body.replace, false, "a live actor change never asks Dragonroll to replace the campaign's edits");
|
||||
});
|
||||
|
||||
test("autosync off: CRUD requests stop syncing", async () => {
|
||||
@@ -260,6 +261,7 @@ test("force sync sends selected actors to Dragonroll even with autosync off", as
|
||||
const pushes = world.syncRequests();
|
||||
assert.equal(pushes.length, 1);
|
||||
assert.equal(pushes[0].body.fullSync, false, "a forced actor never prunes the campaign");
|
||||
assert.equal(pushes[0].body.replace, true, "a forced sync replaces everything the campaign holds for those actors");
|
||||
assert.deepEqual(pushes[0].body.actors.map((actor) => actor._id), ["actor-2"]);
|
||||
assert.deepEqual(world.notifications.filter(([kind]) => kind !== "info"), []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user