forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.test.ts
53 lines (49 loc) · 2.21 KB
/
dataset.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
// stock
import { describe, it, vi, beforeEach } from 'vitest';
import { expect } from 'vitest';
// data
import weather from '$lib/mock_data/csv/csv.csv?raw';
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';
import mock_merge_data from '$lib/mock_data/merge/merge.json';
// utilities
import * as utils from '$lib/utils';
// graph
import { getDataset, getSimpleDataset, getMarkdownToChatDataset } from './test/mocks/dataset';
describe('Full pipeline run test', () => {
beforeEach(() => {
vi.restoreAllMocks();
});
it('Find by compute type', async () => {
const dataset = getSimpleDataset();
const nodes = dataset.graph.findByComputeType('markdown_v0');
expect(nodes[0].node.data.compute_type).toEqual('markdown_v0');
});
it('Simple pipeline run test', async () => {
const dataset = getSimpleDataset();
await dataset.processNodes('run');
const markdown = dataset.graph.find('markdown').node;
expect(markdown.data.output).toEqual('sk-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
});
it('Full pipeline run test', async () => {
vi.spyOn(utils, 'readFileFromGCS').mockResolvedValue(weather);
vi.spyOn(utils, 'uploadJSONToGCS').mockResolvedValue(
`uploads/123/test/cluster_extraction.json`
);
const uploadJSONToGCSSpy = vi
.spyOn(utils, 'uploadJSONToGCS')
.mockResolvedValue(`uploads/123/test/cluster_extraction.json`);
const dataset = getDataset();
await dataset.processNodes('run');
expect(dataset.graph.find('jq_v1').node.data.output[0].interview).toEqual('Alice');
expect(dataset.graph.find('cluster_extraction').node.data.output).toEqual(
mock_cluster_extraction_data
);
expect(uploadJSONToGCSSpy.mock.calls[0][0].data.output).toEqual(mock_cluster_extraction_data);
expect(dataset.graph.find('argument_extraction').node.data.output).toEqual(
mock_argument_extraction_data
);
expect(uploadJSONToGCSSpy.mock.calls[1][0].data.output).toEqual(mock_argument_extraction_data);
expect(dataset.graph.find('merge').node.data.output).toEqual(mock_merge_data);
});
});