forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.test.ts
54 lines (48 loc) · 1.7 KB
/
report.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
54
import ReportNode, { report_node_data } from '$lib/compute/report_v0';
import deepCopy from 'deep-copy';
import { describe, it } from 'vitest';
import { expect } from 'vitest';
describe('ReportNode class', () => {
it('should set the output of the node to the input data', async () => {
const node = new ReportNode(deepCopy(report_node_data));
const inputData = { json: { key: 'value' } };
const result = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(result).toEqual({ key: 'value' });
expect(node.data.output).toEqual({ key: 'value' });
expect(node.data.dirty).toBe(false);
});
it('should handle empty input data', async () => {
const node = new ReportNode(deepCopy(report_node_data));
const inputData = {};
const result = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(result).toBeUndefined();
expect(node.data.output).toBeUndefined();
expect(node.data.dirty).toBe(false);
});
it('should not mutate the input node', async () => {
const originalNodeData = deepCopy(report_node_data);
const node = new ReportNode(originalNodeData);
const inputData = { json: { key: 'value' } };
await node.compute(inputData, 'run', console.log, console.error, console.log, 'test_slug');
// Check if dirty flag is updated
expect(node.data.dirty).toBe(false);
// Ensure other properties remain unchanged
expect(node.id).toEqual(originalNodeData.id);
expect(node.type).toEqual(originalNodeData.type);
expect(node.position).toEqual(originalNodeData.position);
});
});