forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge.test.ts
105 lines (100 loc) · 3.08 KB
/
merge.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { describe, it } from 'vitest';
import { expect } from 'vitest';
import MergeNode, { merge_node_data } from '$lib/compute/merge_v0';
import deepCopy from 'deep-copy';
import mock_cluster_extraction_data from '$lib/mock_data/cluster_extraction/cluster_extraction.json';
import mock_argument_extraction_data from '$lib/mock_data/argument_extraction/argument_extraction.json';
describe('MergeNode class', () => {
it('merges cluster_extraction and argument_extraction data', async () => {
const node = new MergeNode(deepCopy(merge_node_data));
const inputData = {
cluster_extraction: mock_cluster_extraction_data,
argument_extraction: mock_argument_extraction_data
};
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null
);
expect(output).toHaveProperty('topics');
expect(output.topics).toBeInstanceOf(Array);
output.topics.forEach((topic) => {
expect(topic).toHaveProperty('subtopics');
topic.subtopics.forEach((subtopic) => {
expect(subtopic).toHaveProperty('claims');
expect(subtopic.claims).toBeInstanceOf(Array);
});
});
});
it('does not merge if cluster_extraction data is missing', async () => {
const node = new MergeNode(deepCopy(merge_node_data));
const inputData = {
argument_extraction: mock_argument_extraction_data
};
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null
);
expect(output).toBeUndefined();
});
it('does not merge if argument_extraction data is missing', async () => {
const node = new MergeNode(deepCopy(merge_node_data));
const inputData = {
cluster_extraction: mock_cluster_extraction_data
};
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null
);
expect(output).toBeUndefined();
});
it('does not merge if cluster_extraction data has no topics', async () => {
const node = new MergeNode(deepCopy(merge_node_data));
const inputData = {
cluster_extraction: { ...mock_cluster_extraction_data, topics: undefined },
argument_extraction: mock_argument_extraction_data
};
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null
);
expect(output).toBeUndefined();
});
it('sets node data output to the merged data and dirty to false after merge', async () => {
const node = new MergeNode(deepCopy(merge_node_data));
const inputData = {
cluster_extraction: mock_cluster_extraction_data,
argument_extraction: mock_argument_extraction_data
};
await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug',
null
);
expect(node.data.output).toHaveProperty('topics');
expect(node.data.dirty).toBe(false);
});
});