forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jq_v0.test.ts
25 lines (22 loc) · 881 Bytes
/
jq_v0.test.ts
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
import { describe, it, vi } from 'vitest';
import { expect } from 'vitest';
import JqNodeV0, { jq_v0_node_data } from '$lib/compute/jq_v0';
import deepCopy from 'deep-copy';
const log = console.log;
const input = { input: { x: [{ y: 2 }, { y: 4 }] } };
describe('jq function', () => {
it('should process data correctly with JQ filter', async () => {
const node = new JqNodeV0(deepCopy(jq_v0_node_data));
node.data.text = '.x[].y';
const result = await node.compute(input, 'run', log, log, log, '/');
expect(result).toEqual([2, 4]);
vi.restoreAllMocks();
});
it('should handle invalid JQ filter', async () => {
const node = new JqNodeV0(deepCopy(jq_v0_node_data));
node.data.text = 'invalid filter';
const result = await node.compute(input, 'run', log, log, log, '/');
expect(result).toBeUndefined();
vi.restoreAllMocks();
});
});