From a46409ff44a23bb30543ed377ee564c3bfaf51ef Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 30 Apr 2024 19:29:20 +0500 Subject: [PATCH] core: add more fts trigger tests --- packages/core/__tests__/fts-triggers.test.ts | 89 +++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/packages/core/__tests__/fts-triggers.test.ts b/packages/core/__tests__/fts-triggers.test.ts index b0d87d841..4f7fbf628 100644 --- a/packages/core/__tests__/fts-triggers.test.ts +++ b/packages/core/__tests__/fts-triggers.test.ts @@ -18,7 +18,7 @@ along with this program. If not, see . */ import { expect, test } from "vitest"; -import { databaseTest } from "./utils"; +import { TEST_NOTE, databaseTest, noteTest } from "./utils"; test("updating deleted content should not throw", () => databaseTest().then(async (db) => { @@ -87,3 +87,90 @@ test("updating deleted note should not throw", () => db.notes.collection.update([id], { synced: true }, { sendEvent: false }) ).resolves.toBeFalsy(); })); + +test("overwriting unlocked content with locked content should update search index", () => + noteTest({ + content: { + data: "hello world", + type: "tiptap" + } + }).then(async ({ db, id }) => { + await db.content.collection.upsert({ + id: "something", + locked: false, + data: "What is this?", + noteId: id, + dateCreated: Date.now(), + dateEdited: Date.now(), + synced: false, + dateModified: Date.now() + }); + + await db.content.collection.put([ + { + id: "something", + locked: true, + data: { + alg: "as", + cipher: "s", + format: "base64", + iv: "", + length: 20, + salt: "" + }, + noteId: id, + dateCreated: Date.now(), + dateEdited: Date.now(), + synced: false, + dateModified: Date.now() + } + ]); + + expect(await db.lookup.notes("what is this").ids()).not.toContain(id); + })); + +test("overwriting content with deleted content should update search index", () => + noteTest({ + content: { + data: "hello world", + type: "tiptap" + } + }).then(async ({ db, id }) => { + await db.content.collection.upsert({ + id: "something", + locked: false, + data: "What is this?", + noteId: id, + dateCreated: Date.now(), + dateEdited: Date.now(), + synced: false, + dateModified: Date.now() + }); + + await db.content.collection.put([ + { + id: "something", + deleted: true, + synced: true, + dateModified: Date.now() + } + ]); + + expect(await db.lookup.notes("what is this").ids()).not.toContain(id); + })); + +test("overwriting note with deleted note should update search index", () => + noteTest({ + title: "I am title" + }).then(async ({ db, id }) => { + await db.notes.collection.put([ + { + id, + deleted: true, + synced: true, + dateModified: Date.now() + } + ]); + + expect(await db.lookup.notes("title").ids()).not.toContain(id); + }));