-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathjsonata.test.ts
53 lines (50 loc) · 1.43 KB
/
jsonata.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import JsonataNode, { jsonata_node_data } from '$lib/compute/jsonata_v0';
import deepCopy from 'deep-copy';
import { describe, it } from 'vitest';
import { expect } from 'vitest';
describe('JsonataNode class', () => {
it('evaluates JSONata expressions', async () => {
const nodeData = deepCopy(jsonata_node_data);
nodeData.data.text = '$sum(numbers)';
const node = new JsonataNode(nodeData);
const inputData = { json: { numbers: [1, 2, 3] } };
const output = await node.compute(
inputData,
null,
() => {},
() => {},
() => {},
''
);
expect(output).toEqual(6);
});
it('returns undefined if no expression is provided', async () => {
const nodeData = deepCopy(jsonata_node_data);
const node = new JsonataNode(nodeData);
const inputData = { json: { numbers: [1, 2, 3] } };
const output = await node.compute(
inputData,
null,
() => {},
() => {},
() => {},
''
);
expect(output).toBeUndefined();
});
it('catches errors when evaluating expressions', async () => {
const nodeData = deepCopy(jsonata_node_data);
nodeData.data.text = 'invalid expression';
const node = new JsonataNode(nodeData);
const inputData = { json: { numbers: [1, 2, 3] } };
const output = await node.compute(
inputData,
null,
() => {},
() => {},
() => {},
''
);
expect(output).toBeUndefined();
});
});