Fix failing tests

This commit is contained in:
Maxime Cannoodt 2022-12-04 21:44:45 +01:00
parent 3fd77199fc
commit 39a55e4a01
5 changed files with 16 additions and 7 deletions

2
plugin

@ -1 +1 @@
Subproject commit d54b424dd6aafdaa18e1dc25915c6684825aa2f0
Subproject commit 7a645c3e11c14f222405068c4710d30686800013

View File

@ -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(() => {

View File

@ -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;

View File

@ -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);

View File

@ -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