snort/packages/system/tests/RequestSplitter.test.ts

89 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-06-08 10:45:23 +00:00
import { ReqFilter } from "../src";
2023-05-19 14:15:13 +00:00
import { describe, expect } from "@jest/globals";
2023-06-08 10:45:23 +00:00
import { diffFilters } from "../src/RequestSplitter";
2023-06-12 13:15:45 +00:00
import { expandFilter } from "../src/RequestExpander";
2023-03-28 14:34:01 +00:00
describe("RequestSplitter", () => {
test("single filter add value", () => {
const a: Array<ReqFilter> = [{ kinds: [0], authors: ["a"] }];
const b: Array<ReqFilter> = [{ kinds: [0], authors: ["a", "b"] }];
2023-06-12 13:15:45 +00:00
const diff = diffFilters(a.flatMap(expandFilter), b.flatMap(expandFilter), true);
expect(diff).toEqual({
added: [{ kinds: [0], authors: ["b"] }],
removed: [],
changed: true,
});
2023-03-28 14:34:01 +00:00
});
test("single filter remove value", () => {
const a: Array<ReqFilter> = [{ kinds: [0], authors: ["a"] }];
const b: Array<ReqFilter> = [{ kinds: [0], authors: ["b"] }];
2023-06-12 13:15:45 +00:00
const diff = diffFilters(a.flatMap(expandFilter), b.flatMap(expandFilter), true);
expect(diff).toEqual({
added: [{ kinds: [0], authors: ["b"] }],
removed: [{ kinds: [0], authors: ["a"] }],
changed: true,
});
2023-03-28 14:34:01 +00:00
});
test("single filter change critical key", () => {
const a: Array<ReqFilter> = [{ kinds: [0], authors: ["a"], since: 100 }];
const b: Array<ReqFilter> = [{ kinds: [0], authors: ["a", "b"], since: 101 }];
2023-06-12 13:15:45 +00:00
const diff = diffFilters(a.flatMap(expandFilter), b.flatMap(expandFilter), true);
expect(diff).toEqual({
added: [{ kinds: [0], authors: ["a", "b"], since: 101 }],
removed: [{ kinds: [0], authors: ["a"], since: 100 }],
changed: true,
});
2023-03-28 14:34:01 +00:00
});
test("multiple filter add value", () => {
const a: Array<ReqFilter> = [
2023-03-28 14:34:01 +00:00
{ kinds: [0], authors: ["a"] },
{ kinds: [69], authors: ["a"] },
];
const b: Array<ReqFilter> = [
2023-03-28 14:34:01 +00:00
{ kinds: [0], authors: ["a", "b"] },
{ kinds: [69], authors: ["a", "c"] },
];
2023-06-12 13:15:45 +00:00
const diff = diffFilters(a.flatMap(expandFilter), b.flatMap(expandFilter), true);
2023-03-28 14:34:01 +00:00
expect(diff).toEqual({
added: [
2023-03-28 14:34:01 +00:00
{ kinds: [0], authors: ["b"] },
{ kinds: [69], authors: ["c"] },
],
removed: [],
2023-03-28 14:34:01 +00:00
changed: true,
});
});
test("multiple filter remove value", () => {
const a: Array<ReqFilter> = [
2023-03-28 14:34:01 +00:00
{ kinds: [0], authors: ["a"] },
{ kinds: [69], authors: ["a"] },
];
const b: Array<ReqFilter> = [
2023-03-28 14:34:01 +00:00
{ kinds: [0], authors: ["b"] },
{ kinds: [69], authors: ["c"] },
];
2023-06-12 13:15:45 +00:00
const diff = diffFilters(a.flatMap(expandFilter), b.flatMap(expandFilter), true);
2023-03-28 14:34:01 +00:00
expect(diff).toEqual({
added: [
2023-03-28 14:34:01 +00:00
{ kinds: [0], authors: ["b"] },
{ kinds: [69], authors: ["c"] },
],
removed: [{ kinds: [0, 69], authors: ["a"] }],
2023-03-28 14:34:01 +00:00
changed: true,
});
});
test("add filter", () => {
const a: Array<ReqFilter> = [{ kinds: [0], authors: ["a"] }];
const b: Array<ReqFilter> = [
2023-03-28 14:34:01 +00:00
{ kinds: [0], authors: ["a"] },
{ kinds: [69], authors: ["c"] },
];
2023-06-12 13:15:45 +00:00
const diff = diffFilters(a.flatMap(expandFilter), b.flatMap(expandFilter), true);
2023-03-28 14:34:01 +00:00
expect(diff).toEqual({
added: [{ kinds: [69], authors: ["c"] }],
removed: [],
2023-03-28 14:34:01 +00:00
changed: true,
});
});
});