|
5 | 5 | pruneIds, |
6 | 6 | pruneIdArrays, |
7 | 7 | pruneUUIDs, |
8 | | - pruneHashes |
| 8 | + pruneHashes, |
| 9 | + IdHash |
9 | 10 | } from '../src/utils'; |
10 | 11 |
|
11 | 12 | describe('snapshot utilities', () => { |
@@ -46,6 +47,7 @@ describe('snapshot utilities', () => { |
46 | 47 | const row: Record<string, unknown> = { id: null, user_id: undefined }; |
47 | 48 | expect(pruneIds(row)).toEqual({ id: null, user_id: undefined }); |
48 | 49 | }); |
| 50 | + |
49 | 51 | }); |
50 | 52 |
|
51 | 53 | describe('pruneIdArrays', () => { |
@@ -113,6 +115,7 @@ describe('snapshot utilities', () => { |
113 | 115 | name: 'Alice' |
114 | 116 | }); |
115 | 117 | }); |
| 118 | + |
116 | 119 | }); |
117 | 120 |
|
118 | 121 | describe('snapshot', () => { |
@@ -177,5 +180,72 @@ describe('snapshot utilities', () => { |
177 | 180 | expect(snapshot(null)).toBe(null); |
178 | 181 | expect(snapshot(undefined)).toBe(undefined); |
179 | 182 | }); |
| 183 | + |
| 184 | + }); |
| 185 | + |
| 186 | + describe('IdHash support', () => { |
| 187 | + it('pruneIds uses IdHash to map IDs to numbered placeholders', () => { |
| 188 | + const idHash: IdHash = { 'uuid-1': 1, 'uuid-2': 2 }; |
| 189 | + const row = { id: 'uuid-1', user_id: 'uuid-2', org_id: 'unknown', name: 'Alice' }; |
| 190 | + expect(pruneIds(row, idHash)).toEqual({ |
| 191 | + id: '[ID-1]', |
| 192 | + user_id: '[ID-2]', |
| 193 | + org_id: '[ID]', |
| 194 | + name: 'Alice' |
| 195 | + }); |
| 196 | + }); |
| 197 | + |
| 198 | + it('prune applies IdHash mapping when provided', () => { |
| 199 | + const idHash: IdHash = { '1': 1, '2': 2 }; |
| 200 | + const row = { id: 1, user_id: 2, name: 'Alice' }; |
| 201 | + expect(prune(row, idHash)).toEqual({ |
| 202 | + id: '[ID-1]', |
| 203 | + user_id: '[ID-2]', |
| 204 | + name: 'Alice' |
| 205 | + }); |
| 206 | + }); |
| 207 | + |
| 208 | + it('snapshot uses IdHash to preserve ID relationships', () => { |
| 209 | + const idHash: IdHash = { |
| 210 | + 'user-uuid-1': 1, |
| 211 | + 'user-uuid-2': 2, |
| 212 | + 'post-uuid-1': 3 |
| 213 | + }; |
| 214 | + const data = [ |
| 215 | + { id: 'user-uuid-1', name: 'Alice', post_id: 'post-uuid-1' }, |
| 216 | + { id: 'user-uuid-2', name: 'Bob', post_id: 'post-uuid-1' } |
| 217 | + ]; |
| 218 | + expect(snapshot(data, idHash)).toEqual([ |
| 219 | + { id: '[ID-1]', name: 'Alice', post_id: '[ID-3]' }, |
| 220 | + { id: '[ID-2]', name: 'Bob', post_id: '[ID-3]' } |
| 221 | + ]); |
| 222 | + }); |
| 223 | + |
| 224 | + it('snapshot uses IdHash with nested objects', () => { |
| 225 | + const idHash: IdHash = { 'org-1': 1, 'user-1': 2 }; |
| 226 | + const data = { |
| 227 | + org: { id: 'org-1', name: 'Acme' }, |
| 228 | + user: { id: 'user-1', org_id: 'org-1' } |
| 229 | + }; |
| 230 | + expect(snapshot(data, idHash)).toEqual({ |
| 231 | + org: { id: '[ID-1]', name: 'Acme' }, |
| 232 | + user: { id: '[ID-2]', org_id: '[ID-1]' } |
| 233 | + }); |
| 234 | + }); |
| 235 | + |
| 236 | + it('snapshot uses IdHash with string labels', () => { |
| 237 | + const idHash: IdHash = { |
| 238 | + 'uuid-user-1': 'user1', |
| 239 | + 'uuid-user-2': 'user2', |
| 240 | + 'uuid-group-1': 'group1', |
| 241 | + 'uuid-group-2': 'group2' |
| 242 | + }; |
| 243 | + const data = [ |
| 244 | + { actor_id: 'uuid-user-2', entity_id: 'uuid-group-2', is_admin: true } |
| 245 | + ]; |
| 246 | + expect(snapshot(data, idHash)).toEqual([ |
| 247 | + { actor_id: '[ID-user2]', entity_id: '[ID-group2]', is_admin: true } |
| 248 | + ]); |
| 249 | + }); |
180 | 250 | }); |
181 | 251 | }); |
0 commit comments