2023-06-08 10:45:23 +00:00
|
|
|
import { TaggedRawEvent } from "../src/Nostr";
|
2023-05-19 14:15:13 +00:00
|
|
|
import { describe, expect } from "@jest/globals";
|
2023-06-08 10:45:23 +00:00
|
|
|
import { FlatNoteStore, ReplaceableNoteStore } from "../src/NoteCollection";
|
2023-03-28 14:34:01 +00:00
|
|
|
|
|
|
|
describe("NoteStore", () => {
|
|
|
|
describe("flat", () => {
|
|
|
|
test("one event", () => {
|
|
|
|
const ev = { id: "one" } as TaggedRawEvent;
|
|
|
|
const c = new FlatNoteStore();
|
|
|
|
c.add(ev);
|
|
|
|
expect(c.getSnapshotData()).toEqual([ev]);
|
|
|
|
});
|
|
|
|
test("still one event", () => {
|
|
|
|
const ev = { id: "one" } as TaggedRawEvent;
|
|
|
|
const c = new FlatNoteStore();
|
|
|
|
c.add(ev);
|
|
|
|
c.add(ev);
|
|
|
|
expect(c.getSnapshotData()).toEqual([ev]);
|
|
|
|
});
|
|
|
|
test("clears", () => {
|
|
|
|
const ev = { id: "one" } as TaggedRawEvent;
|
|
|
|
const c = new FlatNoteStore();
|
|
|
|
c.add(ev);
|
|
|
|
expect(c.getSnapshotData()).toEqual([ev]);
|
|
|
|
c.clear();
|
|
|
|
expect(c.getSnapshotData()).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("replacable", () => {
|
|
|
|
test("one event", () => {
|
|
|
|
const ev = { id: "test", created_at: 69 } as TaggedRawEvent;
|
|
|
|
const c = new ReplaceableNoteStore();
|
|
|
|
c.add(ev);
|
|
|
|
expect(c.getSnapshotData()).toEqual(ev);
|
|
|
|
});
|
|
|
|
test("dont replace with older", () => {
|
|
|
|
const ev = { id: "test", created_at: 69 } as TaggedRawEvent;
|
|
|
|
const evOlder = { id: "test2", created_at: 68 } as TaggedRawEvent;
|
|
|
|
const c = new ReplaceableNoteStore();
|
|
|
|
c.add(ev);
|
|
|
|
c.add(evOlder);
|
|
|
|
expect(c.getSnapshotData()).toEqual(ev);
|
|
|
|
});
|
|
|
|
test("replace with newer", () => {
|
|
|
|
const ev = { id: "test", created_at: 69 } as TaggedRawEvent;
|
|
|
|
const evNewer = { id: "test2", created_at: 70 } as TaggedRawEvent;
|
|
|
|
const c = new ReplaceableNoteStore();
|
|
|
|
c.add(ev);
|
|
|
|
c.add(evNewer);
|
|
|
|
expect(c.getSnapshotData()).toEqual(evNewer);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|