Skip to content

Commit

Permalink
core: tagging an empty note should not create a content item
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Aug 14, 2023
1 parent d384aa9 commit 7ff5f00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/core/__tests__/content.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ test("adding a deleted content should not throw", () =>
})
).resolves.toBeUndefined();
}));

test("tagging an empty note should not create an invalid content item", () =>
databaseTest().then(async (db) => {
const id = await db.notes.add({ title: "Hello" });
const contentId = await db.notes.note(id)._note.contentId;
expect(contentId).toBeUndefined();
expect(await db.content.all()).toHaveLength(0);

await db.notes.note(id).tag("tag1");

expect(await db.content.all()).toHaveLength(0);
}));
2 changes: 1 addition & 1 deletion packages/core/src/collections/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class Notes extends Collection {
if (oldNote) note.dateEdited = Date.now();
}

if (noteArg.localOnly !== undefined) {
if (note.contentId && noteArg.localOnly !== undefined) {
await this._db.content.add({
id: note.contentId,
localOnly: !!noteArg.localOnly
Expand Down

0 comments on commit 7ff5f00

Please sign in to comment.