-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathpostProcess.test.ts
More file actions
125 lines (104 loc) · 3.31 KB
/
postProcess.test.ts
File metadata and controls
125 lines (104 loc) · 3.31 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { describe, it, expect } from 'vitest';
import {
calculateHashes,
dedupeUpdates,
linkStaticUpdates,
} from '../postProcess.js';
import type { Updates } from '../../types/index.js';
describe('calculateHashes', () => {
it('generates consistent hashes for same input', async () => {
const updates1: Updates = [
{ dataFormat: 'ICU', source: 'hello', metadata: {} },
];
const updates2: Updates = [
{ dataFormat: 'ICU', source: 'hello', metadata: {} },
];
await calculateHashes(updates1);
await calculateHashes(updates2);
expect(updates1[0].metadata.hash).toBeDefined();
expect(updates1[0].metadata.hash).toBe(updates2[0].metadata.hash);
});
it('generates different hashes for different sources', async () => {
const updates: Updates = [
{ dataFormat: 'ICU', source: 'hello', metadata: {} },
{ dataFormat: 'ICU', source: 'world', metadata: {} },
];
await calculateHashes(updates);
expect(updates[0].metadata.hash).not.toBe(updates[1].metadata.hash);
});
});
describe('dedupeUpdates', () => {
it('removes duplicates with same hash, merges filePaths', () => {
const updates: Updates = [
{
dataFormat: 'ICU',
source: 'hello',
metadata: { hash: 'h1', filePaths: ['pathA'] },
},
{
dataFormat: 'ICU',
source: 'hello',
metadata: { hash: 'h1', filePaths: ['pathB'] },
},
];
dedupeUpdates(updates);
expect(updates).toHaveLength(1);
expect(updates[0].metadata.filePaths).toEqual(['pathA', 'pathB']);
});
it('keeps distinct entries with different hashes', () => {
const updates: Updates = [
{
dataFormat: 'ICU',
source: 'hello',
metadata: { hash: 'h1', filePaths: ['pathA'] },
},
{
dataFormat: 'ICU',
source: 'world',
metadata: { hash: 'h2', filePaths: ['pathB'] },
},
];
dedupeUpdates(updates);
expect(updates).toHaveLength(2);
});
it('handles entries without hashes', () => {
const updates: Updates = [
{ dataFormat: 'ICU', source: 'no-hash', metadata: {} },
{
dataFormat: 'ICU',
source: 'has-hash',
metadata: { hash: 'h1', filePaths: ['pathA'] },
},
];
dedupeUpdates(updates);
expect(updates).toHaveLength(2);
});
});
describe('linkStaticUpdates', () => {
it('groups entries by temporary staticId and assigns shared hash', () => {
const updates: Updates = [
{
dataFormat: 'ICU',
source: 'variant-a',
metadata: { hash: 'ha', staticId: 'temp-static' },
},
{
dataFormat: 'ICU',
source: 'variant-b',
metadata: { hash: 'hb', staticId: 'temp-static' },
},
];
linkStaticUpdates(updates);
// Both should now share the same staticId (derived from their hashes)
expect(updates[0].metadata.staticId).toBe(updates[1].metadata.staticId);
// The staticId should have been replaced (no longer the temporary value)
expect(updates[0].metadata.staticId).not.toBe('temp-static');
});
it('does not modify entries without staticId', () => {
const updates: Updates = [
{ dataFormat: 'ICU', source: 'no-static', metadata: { hash: 'h1' } },
];
linkStaticUpdates(updates);
expect(updates[0].metadata.staticId).toBeUndefined();
});
});