snort/packages/app/src/System/RequestMerger.test.ts

45 lines
869 B
TypeScript
Raw Normal View History

2023-05-29 21:25:40 +00:00
import { RawReqFilter } from "@snort/nostr";
import { mergeSimilar } from "./RequestMerger";
describe("RequestMerger", () => {
it("should simple merge authors", () => {
const a = {
authors: ["a"],
} as RawReqFilter;
const b = {
authors: ["b"],
} as RawReqFilter;
const merged = mergeSimilar([a, b]);
expect(merged).toMatchObject([
{
authors: ["a", "b"],
},
]);
});
it("should append non-mergable filters", () => {
const a = {
authors: ["a"],
} as RawReqFilter;
const b = {
authors: ["b"],
} as RawReqFilter;
const c = {
limit: 5,
authors: ["a"],
};
const merged = mergeSimilar([a, b, c]);
expect(merged).toMatchObject([
{
authors: ["a", "b"],
},
{
limit: 5,
authors: ["a"],
},
]);
});
});