forked from Miracle656/wraith
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathodata.test.ts
More file actions
29 lines (25 loc) · 1.12 KB
/
Copy pathodata.test.ts
File metadata and controls
29 lines (25 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { parseODataFilter, parseODataSelect } from "../lib/odata";
describe("OData helper", () => {
const fields = {
contractId: { type: "string" as const },
ledger: { type: "number" as const },
ledgerClosedAt: { type: "date" as const },
eventType: { type: "string" as const },
};
it("parses a safe AND-only filter", () => {
expect(parseODataFilter("ledger gt 100 and contains(contractId,'C')", fields)).toEqual({
AND: [
{ ledger: { gt: 100 } },
{ contractId: { contains: "C", mode: "insensitive" } },
],
});
});
it("rejects unsafe or unsupported filter expressions", () => {
expect(() => parseODataFilter("ledger gt 100 or 1 eq 1", fields)).toThrow(/AND combinations/i);
expect(() => parseODataFilter("contains(ledger,'1')", fields)).toThrow(/string fields/i);
});
it("parses a projection list and rejects unknown fields", () => {
expect(parseODataSelect("contractId, ledger", ["contractId", "ledger"])) .toEqual(["contractId", "ledger"]);
expect(() => parseODataSelect("contractId, hacked", ["contractId"])) .toThrow(/Unsupported \$select field/i);
});
});