diff --git a/dragonroll-foundry/module.json b/dragonroll-foundry/module.json
index 8430a92d..e34fecbd 100644
--- a/dragonroll-foundry/module.json
+++ b/dragonroll-foundry/module.json
@@ -2,7 +2,7 @@
"id": "dragonroll-foundry",
"title": "Dragonroll Foundry API",
"description": "Links a Foundry world to a Dragonroll campaign and exposes a client-side API for world data.",
- "version": "0.5.0",
+ "version": "0.5.1",
"library": true,
"compatibility": {
"minimum": "12",
diff --git a/dragonroll-foundry/scripts/api.js b/dragonroll-foundry/scripts/api.js
index ca12d589..cb840c77 100644
--- a/dragonroll-foundry/scripts/api.js
+++ b/dragonroll-foundry/scripts/api.js
@@ -1432,7 +1432,7 @@ async function applyDragonrollNotePage(page, entry) {
const title = notePageTitle(entry);
const html = notePageHtml(entry.content);
const updates = {};
- if (String(page.title?.text ?? page.title ?? "") !== title) updates["title.text"] = title;
+ if (String(page.name ?? "") !== title) updates.name = title;
if (String(page.text?.content ?? "") !== html) updates["text.content"] = html;
if (!dragonrollNoteId(page)) updates[`flags.${MODULE_ID}.noteId`] = String(entry._id);
if (Object.keys(updates).length) await page.update(updates);
@@ -1440,7 +1440,9 @@ async function applyDragonrollNotePage(page, entry) {
async function createDragonrollNotePage(journal, entry) {
const pages = await journal.createEmbeddedDocuments("JournalEntryPage", [{
- title: { text: notePageTitle(entry) },
+ // A page's display title is its `name`; `title` only holds the table-of-contents
+ // flags (`show`/`level`). Missing `name` fails the document's validation.
+ name: notePageTitle(entry),
text: { content: notePageHtml(entry.content) },
flags: { [MODULE_ID]: { noteId: String(entry._id) } },
}], { renderSheet: false });
diff --git a/tests/foundry-note-journal.test.js b/tests/foundry-note-journal.test.js
index b18ca08c..2dd81e78 100644
--- a/tests/foundry-note-journal.test.js
+++ b/tests/foundry-note-journal.test.js
@@ -255,7 +255,7 @@ function makeWorld({ markdown = true } = {}) {
const page = {
id: `page-${state.nextId++}`,
documentName: "JournalEntryPage",
- title: data.title,
+ name: data.name,
text: { content: data.text?.content ?? "" },
flags: data.flags ?? {},
writes: 0,
@@ -285,6 +285,8 @@ function makeWorld({ markdown = true } = {}) {
async update(update) { return writeFoundryPaths(this, update); },
async createEmbeddedDocuments(documentName, docs) {
assert.equal(documentName, "JournalEntryPage", "the notes' pages are journal pages");
+ // Foundry's own page validation refuses a page without a name.
+ for (const doc of docs) assert.ok(doc.name, "a journal page needs a non-empty name");
const created = docs.map((doc) => makePage(this, doc));
pages.push(...created);
return created;
@@ -428,7 +430,7 @@ test("the campaign's notes become pages of one Dragonroll journal", async () =>
assert.equal(world.journals().length, 1, "one journal carries the campaign's notes");
const journal = world.journals()[0];
assert.equal(journal.name, "Dragonroll");
- assert.deepEqual(journal.pages.contents.map((page) => [page.title.text, page.text.content]), [
+ assert.deepEqual(journal.pages.contents.map((page) => [page.name, page.text.content]), [
["Session 1", "**The start**"],
["Tavern Brawl", "A rope, a chandelier."],
], "each note is a page, its markdown rendered by Foundry's own renderer");
@@ -440,6 +442,19 @@ test("the campaign's notes become pages of one Dragonroll journal", async () =>
], "and the campaign remembers each note's page");
});
+test("reconciling again does not double the journal or its pages", async () => {
+ const world = await makeWorld().linkedSetup();
+ world.remoteNotes = [sessionNote(), tavernNote()];
+
+ await world.runIntervals();
+ await world.runIntervals();
+ await world.runIntervals();
+
+ assert.equal(world.journals().length, 1, "the journal is made once, not per reconcile");
+ assert.equal(world.journals()[0].pages.contents.length, 2, "and each note stands as the one page it was given");
+ assert.equal(world.mapNoteRequests().length, 2, "an already-mapped note is not mapped again");
+});
+
test("an existing journal named Dragonroll is used, not doubled", async () => {
const world = await makeWorld().linkedSetup();
const gmsOwn = world.addJournal("Dragonroll");
@@ -448,7 +463,7 @@ test("an existing journal named Dragonroll is used, not doubled", async () => {
await world.runIntervals();
assert.equal(world.journals().length, 1, "the journal the world already had is the notes' one");
- assert.deepEqual(gmsOwn.pages.contents.map((page) => page.title.text), ["Session 1"]);
+ assert.deepEqual(gmsOwn.pages.contents.map((page) => page.name), ["Session 1"]);
assert.equal(gmsOwn.getFlag(MODULE_ID, "notesJournal"), true, "and it is marked, so renaming it keeps the notes' home findable");
});
@@ -463,7 +478,7 @@ test("a note edited in Dragonroll rewrites its page", async () => {
const journal = world.journals()[0];
assert.equal(journal.pages.contents.length, 1, "the note still stands as the same single page");
- assert.deepEqual(journal.pages.contents[0].title.text, "Session 1 — revisited");
+ assert.deepEqual(journal.pages.contents[0].name, "Session 1 — revisited");
assert.equal(journal.pages.contents[0].text.content, "**A different start**");
assert.equal(world.mapNoteRequests().length, 1, "the pairing the world reads back needs no remapping");
});
@@ -474,11 +489,11 @@ test("a note deleted in Dragonroll takes its page with it", async () => {
await world.runIntervals();
const journal = world.journals()[0];
- const gmsPage = world.addPage(journal, { title: { text: "My own notes" }, text: { content: "not from Dragonroll" } });
+ const gmsPage = world.addPage(journal, { name: "My own notes", text: { content: "not from Dragonroll" } });
world.remoteNotes = world.remoteNotes.filter((note) => note._id !== "note-2");
await world.runIntervals();
- assert.deepEqual(journal.pages.contents.map((page) => page.title.text), ["Session 1", "My own notes"],
+ assert.deepEqual(journal.pages.contents.map((page) => page.name), ["Session 1", "My own notes"],
"the deleted note's page goes; the GM's own page stays");
assert.ok(journal.pages.contents.includes(gmsPage));
});
@@ -497,13 +512,13 @@ test("pages already in step with the campaign are not rewritten", async () => {
test("the campaign's page mapping claims a page whose flag was lost", async () => {
const world = await makeWorld().linkedSetup();
const journal = world.addJournal("Dragonroll");
- const orphan = world.addPage(journal, { title: { text: "Old name" }, text: { content: "old" } });
+ const orphan = world.addPage(journal, { name: "Old name", text: { content: "old" } });
world.remoteNotes = [{ _id: "note-1", title: "Session 1", content: "**The start**", foundryPageId: orphan.id }];
await world.runIntervals();
assert.equal(journal.pages.contents.length, 1, "no second page under the same title");
- assert.equal(orphan.title.text, "Session 1");
+ assert.equal(orphan.name, "Session 1");
assert.equal(orphan.getFlag(MODULE_ID, "noteId"), "note-1", "and the page is marked again");
});