diff --git a/plugin b/plugin index d54b424..7a645c3 160000 --- a/plugin +++ b/plugin @@ -1 +1 @@ -Subproject commit d54b424dd6aafdaa18e1dc25915c6684825aa2f0 +Subproject commit 7a645c3e11c14f222405068c4710d30686800013 diff --git a/server/src/controllers/note/note.delete.controller.unit.test.ts b/server/src/controllers/note/note.delete.controller.unit.test.ts index bfac44d..7e57558 100644 --- a/server/src/controllers/note/note.delete.controller.unit.test.ts +++ b/server/src/controllers/note/note.delete.controller.unit.test.ts @@ -3,10 +3,12 @@ import express from "express"; import supertest from "supertest"; import { vi, describe, it, beforeEach, afterEach, expect } from "vitest"; import * as noteDao from "../../db/note.dao"; +import * as bloomFilter from "../../db/bloomFilter.dao"; import EventLogger from "../../logging/EventLogger"; import { deleteNoteController } from "./note.delete.controller"; vi.mock("../../db/note.dao"); +vi.mock("../../db/bloomFilter.dao"); vi.mock("../../logging/EventLogger"); const VALID_USER_ID = "f06536e7df6857fc"; @@ -17,6 +19,7 @@ const MOCK_NOTE_ID = "NOTE_ID"; describe("note.delete.controller", () => { let mockNoteDao = vi.mocked(noteDao); let mockEventLogger = vi.mocked(EventLogger); + let mockBloomFilterDao = vi.mocked(bloomFilter); const test_app = express() .use(express.json()) @@ -41,6 +44,10 @@ describe("note.delete.controller", () => { throw new Error("Note not found"); } }); + + mockBloomFilterDao.getFilter.mockImplementation(async () => { + throw new Error("No BloomFilter found"); + }); }); afterEach(() => { diff --git a/server/src/lib/expiredNoteFilter.ts b/server/src/lib/expiredNoteFilter.ts index 722df2e..70283aa 100644 --- a/server/src/lib/expiredNoteFilter.ts +++ b/server/src/lib/expiredNoteFilter.ts @@ -7,6 +7,7 @@ export const DELETED_NOTES_FILTER_NAME = "deletedNotes" as const; type FilterName = | typeof EXPIRED_NOTES_FILTER_NAME | typeof DELETED_NOTES_FILTER_NAME; + export class NoteIdFilter { _filter: ScalableBloomFilter; _name: string; diff --git a/server/src/lib/expiredNoteFilter.unit.test.ts b/server/src/lib/expiredNoteFilter.unit.test.ts index a71454b..49bba3e 100644 --- a/server/src/lib/expiredNoteFilter.unit.test.ts +++ b/server/src/lib/expiredNoteFilter.unit.test.ts @@ -16,7 +16,7 @@ describe("Deserialization from database", () => { mockedDao.getFilter.mockRejectedValue(new Error("No BloomFilter found")); // test instatiation - const testFilter = await NoteIdFilter.deserializeFromDb(); + const testFilter = await NoteIdFilter.deserializeFromDb("expiredNotes"); expect(mockedDao.getFilter).toHaveBeenCalledWith( "expiredNotes", ScalableBloomFilter @@ -37,7 +37,7 @@ describe("Deserialization from database", () => { mockedDao.getFilter.mockResolvedValue(bloomFilter); // test instatiation - const testFilter = await NoteIdFilter.deserializeFromDb(); + const testFilter = await NoteIdFilter.deserializeFromDb("expiredNotes"); expect(mockedDao.getFilter).toHaveBeenCalledWith( "expiredNotes", ScalableBloomFilter @@ -63,7 +63,7 @@ describe("Filter operations and serialization", () => { }); it("should add multiple noteIds to the filter", async () => { - testFilter = await NoteIdFilter.deserializeFromDb(); + testFilter = await NoteIdFilter.deserializeFromDb("expiredNotes"); testFilter.addNoteIds(["test", "test2"]); expect(testFilter.hasNoteId("test")).toBe(true); expect(testFilter.hasNoteId("test2")).toBe(true); @@ -77,7 +77,7 @@ describe("Filter operations and serialization", () => { }); it("Should have an error rate <1% for 1000 elements", async () => { - testFilter = await NoteIdFilter.deserializeFromDb(); + testFilter = await NoteIdFilter.deserializeFromDb("expiredNotes"); const elements = Array.from({ length: 1000 }, (_, i) => i.toString()); testFilter.addNoteIds(elements); diff --git a/server/src/tasks/deleteExpiredNotes.unit.test.ts b/server/src/tasks/deleteExpiredNotes.unit.test.ts index 95c241e..d6f90e8 100644 --- a/server/src/tasks/deleteExpiredNotes.unit.test.ts +++ b/server/src/tasks/deleteExpiredNotes.unit.test.ts @@ -11,7 +11,7 @@ vi.mock("../lib/expiredNoteFilter", () => { const instance = { addNoteIds: vi.fn(), }; - return { getExpiredNoteFilter: () => instance }; + return { getNoteFilter: (name: string) => instance }; }); vi.spyOn(logger, "error"); @@ -33,12 +33,13 @@ describe("deleteExpiredNotes", () => { insert_time: new Date(), expire_time: new Date(), crypto_version: "v1", + secret_token: "secret_token", }, ]); mockedDao.deleteNotes.mockResolvedValue(1); // mock ExpiredNoteFilter - const mockedFilter = vi.mocked(await filter.getNoteFilter()); + const mockedFilter = vi.mocked(await filter.getNoteFilter("expiredNotes")); mockedFilter.addNoteIds.mockResolvedValue(); // test task call