-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmapToUpdates.test.ts
More file actions
111 lines (98 loc) · 2.9 KB
/
mapToUpdates.test.ts
File metadata and controls
111 lines (98 loc) · 2.9 KB
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
106
107
108
109
110
111
import { describe, it, expect } from 'vitest';
import { mapExtractionResultsToUpdates } from '../mapToUpdates.js';
import type { ExtractionResult } from '@generaltranslation/python-extractor';
describe('mapExtractionResultsToUpdates', () => {
it('maps empty results to empty updates', () => {
const updates = mapExtractionResultsToUpdates([]);
expect(updates).toEqual([]);
});
it('maps single result with all metadata fields', () => {
const results: ExtractionResult[] = [
{
dataFormat: 'ICU',
source: 'Hello, {name}!',
metadata: {
id: 'greeting',
context: 'casual',
maxChars: 100,
filePaths: ['app.py'],
staticId: 'static-1',
},
},
];
const updates = mapExtractionResultsToUpdates(results);
expect(updates).toHaveLength(1);
expect(updates[0]).toEqual({
dataFormat: 'ICU',
source: 'Hello, {name}!',
metadata: {
id: 'greeting',
context: 'casual',
maxChars: 100,
filePaths: ['app.py'],
staticId: 'static-1',
},
});
});
it('passes through dataFormat correctly', () => {
const results: ExtractionResult[] = [
{
dataFormat: 'JSX',
source: '<p>Hello</p>',
metadata: {},
},
];
const updates = mapExtractionResultsToUpdates(results);
expect(updates[0].dataFormat).toBe('JSX');
});
it('handles missing optional metadata', () => {
const results: ExtractionResult[] = [
{
dataFormat: 'ICU',
source: 'Simple string',
metadata: {},
},
];
const updates = mapExtractionResultsToUpdates(results);
expect(updates).toHaveLength(1);
expect(updates[0].metadata).toEqual({});
expect(updates[0].metadata.id).toBeUndefined();
expect(updates[0].metadata.context).toBeUndefined();
expect(updates[0].metadata.maxChars).toBeUndefined();
});
it('preserves filePaths array', () => {
const results: ExtractionResult[] = [
{
dataFormat: 'ICU',
source: 'Multi-file string',
metadata: {
filePaths: ['routes/index.py', 'routes/auth.py'],
},
},
];
const updates = mapExtractionResultsToUpdates(results);
expect(updates[0].metadata.filePaths).toEqual([
'routes/index.py',
'routes/auth.py',
]);
});
it('maps multiple results', () => {
const results: ExtractionResult[] = [
{
dataFormat: 'ICU',
source: 'Hello',
metadata: { id: 'hello' },
},
{
dataFormat: 'ICU',
source: 'Goodbye',
metadata: { id: 'goodbye', context: 'farewell' },
},
];
const updates = mapExtractionResultsToUpdates(results);
expect(updates).toHaveLength(2);
expect(updates[0].source).toBe('Hello');
expect(updates[1].source).toBe('Goodbye');
expect(updates[1].metadata.context).toBe('farewell');
});
});