@squiz/db-lib 1.77.0 → 1.77.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,11 +43,34 @@ const testEntityDefinition: EntityDefinition = {
43
43
  // Concrete test repository
44
44
  class TestRepo extends ExternalizedDynamoDbRepository<TestItemShape, TestItem> {
45
45
  public mockSuperUpdateItem?: jest.Mock;
46
+ public mockSuperGetItem?: jest.Mock;
47
+ public mockSuperCreateItem?: jest.Mock;
46
48
 
47
49
  constructor(dbManager: DynamoDbManager<any>, storage: S3ExternalStorage, overrides: Partial<EntityDefinition> = {}) {
48
50
  super('test-table', dbManager, 'test_item', { ...testEntityDefinition, ...overrides }, TestItem, storage);
49
51
  }
50
52
 
53
+ // Expose protected methods for testing
54
+ public async testPrepareValueForStorage(value: TestItem): Promise<TestItem> {
55
+ return await (this as any).prepareValueForStorage(value);
56
+ }
57
+
58
+ public async testHydrateFromExternalStorage(record?: TestItem): Promise<TestItem | undefined> {
59
+ return await (this as any).hydrateFromExternalStorage(record);
60
+ }
61
+
62
+ public testIsDynamoItemSizeLimitError(error: unknown): boolean {
63
+ return (this as any).isDynamoItemSizeLimitError(error);
64
+ }
65
+
66
+ public testIsContentInS3(item: TestItem): boolean {
67
+ return (this as any).isContentInS3(item);
68
+ }
69
+
70
+ public testGetKeyFieldsValues(obj: Record<string, unknown>): Record<string, unknown> {
71
+ return (this as any).getKeyFieldsValues(obj);
72
+ }
73
+
51
74
  // Override updateItem to allow mocking super.updateItem
52
75
  public async updateItem(value: Partial<TestItemShape>): Promise<TestItem | undefined> {
53
76
  if (this.mockSuperUpdateItem) {
@@ -74,6 +97,7 @@ const createDbManager = (clientOverrides: Record<string, jest.Mock> = {}) =>
74
97
  put: jest.fn(),
75
98
  delete: jest.fn(),
76
99
  update: jest.fn(),
100
+ query: jest.fn(),
77
101
  ...clientOverrides,
78
102
  },
79
103
  repositories: {} as any,
@@ -99,176 +123,417 @@ const createTestItem = (overrides: Partial<TestItem> = {}): TestItem => {
99
123
  };
100
124
 
101
125
  describe('ExternalizedDynamoDbRepository', () => {
102
- it('externalizes data to S3 when prepareValueForStorage is called', async () => {
103
- const storage = {
104
- ...createStorage(),
105
- save: jest.fn().mockResolvedValue({ location: { type: 's3', key: 'item-key' }, size: 500 }),
106
- } as unknown as S3ExternalStorage;
107
- const repo = new TestRepo(createDbManager(), storage);
108
- const item = createTestItem();
109
-
110
- const storedValue = await (repo as any).prepareValueForStorage(item);
111
-
112
- expect(storage.save).toHaveBeenCalled();
113
- // storedValue is a minimal payload - original item is NOT mutated
114
- expect(storedValue.data).toEqual([]);
115
- expect(storedValue.storageLocation).toEqual({ type: 's3', key: 'item-key' });
126
+ describe('prepareValueForStorage', () => {
127
+ it('externalizes data to S3 when prepareValueForStorage is called', async () => {
128
+ const storage = {
129
+ ...createStorage(),
130
+ save: jest.fn().mockResolvedValue({ location: { type: 's3', key: 'item-key' }, size: 500 }),
131
+ } as unknown as S3ExternalStorage;
132
+ const repo = new TestRepo(createDbManager(), storage);
133
+ const item = createTestItem();
134
+
135
+ const storedValue = await repo.testPrepareValueForStorage(item);
136
+
137
+ expect(storage.save).toHaveBeenCalled();
138
+ // storedValue is a minimal payload - original item is NOT mutated
139
+ expect(storedValue.data).toEqual([]);
140
+ expect(storedValue.storageLocation).toEqual({ type: 's3', key: 'item-key' });
141
+ });
142
+
143
+ it('removes existing storageLocation before saving to S3', async () => {
144
+ const storage = {
145
+ ...createStorage(),
146
+ save: jest.fn().mockResolvedValue({ location: { type: 's3', key: 'new-key' }, size: 500 }),
147
+ } as unknown as S3ExternalStorage;
148
+ const repo = new TestRepo(createDbManager(), storage);
149
+ const item = createTestItem();
150
+ (item as any).storageLocation = { type: 's3', key: 'old-key' };
151
+
152
+ await repo.testPrepareValueForStorage(item);
153
+
154
+ // Verify save was called without storageLocation in the payload
155
+ const savedPayload = (storage.save as jest.Mock).mock.calls[0][2];
156
+ expect(savedPayload.storageLocation).toBeUndefined();
157
+ });
116
158
  });
117
159
 
118
- it('creates item with storageLocation preserved', async () => {
119
- const client = createDbManager().client as any;
120
- (client.put as jest.Mock).mockResolvedValue({});
121
- const storage = {
122
- ...createStorage(),
123
- save: jest.fn().mockResolvedValue({ location: { type: 's3', key: 'item-key' }, size: 500 }),
124
- } as unknown as S3ExternalStorage;
160
+ describe('createItem', () => {
161
+ it('creates item with storageLocation preserved', async () => {
162
+ const client = createDbManager().client as any;
163
+ (client.put as jest.Mock).mockResolvedValue({});
164
+ const storage = {
165
+ ...createStorage(),
166
+ save: jest.fn().mockResolvedValue({ location: { type: 's3', key: 'item-key' }, size: 500 }),
167
+ load: jest.fn().mockResolvedValue(createTestItem()),
168
+ } as unknown as S3ExternalStorage;
125
169
 
126
- const repo = new TestRepo({ client } as any, storage);
127
- const item = createTestItem();
170
+ const repo = new TestRepo({ client } as any, storage);
171
+ const item = createTestItem();
128
172
 
129
- // Use prepareValueForStorage to externalize data and set storageLocation
130
- const preparedItem = await (repo as any).prepareValueForStorage(item);
173
+ // Use prepareValueForStorage to externalize data and set storageLocation
174
+ const preparedItem = await repo.testPrepareValueForStorage(item);
131
175
 
132
- // Verify the prepared value has minimal payload (empty data)
133
- expect(preparedItem.data).toEqual([]);
134
- expect(preparedItem.storageLocation).toEqual({ type: 's3', key: 'item-key' });
176
+ // Verify the prepared value has minimal payload (empty data)
177
+ expect(preparedItem.data).toEqual([]);
178
+ expect(preparedItem.storageLocation).toEqual({ type: 's3', key: 'item-key' });
179
+
180
+ // Original item should NOT be mutated
181
+ expect(item.storageLocation).toBeUndefined();
182
+ });
135
183
 
136
- // Original item should NOT be mutated
137
- expect(item.storageLocation).toBeUndefined();
184
+ it('automatically externalizes to S3 when createItem exceeds DynamoDB size limit', async () => {
185
+ const client = createDbManager().client as any;
186
+ let callCount = 0;
187
+ (client.put as jest.Mock).mockImplementation(() => {
188
+ callCount++;
189
+ if (callCount === 1) {
190
+ // First call fails with size limit error
191
+ const error = new Error('Item size has exceeded the maximum allowed size');
192
+ (error as any).code = 'ValidationException';
193
+ throw error;
194
+ }
195
+ // Second call succeeds
196
+ return Promise.resolve({});
197
+ });
198
+
199
+ const storage = {
200
+ ...createStorage(),
201
+ save: jest.fn().mockResolvedValue({ location: { type: 's3', key: 'auto-key' }, size: 500 }),
202
+ load: jest.fn().mockResolvedValue(createTestItem()),
203
+ } as unknown as S3ExternalStorage;
204
+
205
+ const repo = new TestRepo({ client } as any, storage);
206
+ const item = createTestItem({ data: [{ key: 'large', value: { content: 'x'.repeat(500000) } }] });
207
+
208
+ await repo.createItem(item);
209
+
210
+ // Should have called save to externalize
211
+ expect(storage.save).toHaveBeenCalled();
212
+ // Should have retried the put
213
+ expect(client.put).toHaveBeenCalledTimes(2);
214
+ });
215
+
216
+ it('cleans up old S3 file when overrideExisting is true', async () => {
217
+ const oldLocation = { type: 's3' as const, key: 'old-key' };
218
+ const newLocation = { type: 's3' as const, key: 'new-key' };
219
+
220
+ const client = createDbManager({
221
+ get: jest.fn().mockResolvedValue({
222
+ Item: {
223
+ id: 'item-1',
224
+ name: 'Old',
225
+ storageLocation: oldLocation,
226
+ },
227
+ }),
228
+ put: jest.fn().mockResolvedValue({}),
229
+ }).client as any;
230
+
231
+ const storage = {
232
+ ...createStorage(),
233
+ save: jest.fn().mockResolvedValue({ location: newLocation, size: 500 }),
234
+ load: jest.fn().mockResolvedValue(createTestItem()),
235
+ } as unknown as S3ExternalStorage;
236
+
237
+ const repo = new TestRepo({ client } as any, storage);
238
+ const item = createTestItem();
239
+ const preparedItem = await repo.testPrepareValueForStorage(item);
240
+
241
+ await repo.createItem(preparedItem, {}, {}, { overrideExisting: true });
242
+
243
+ expect(storage.delete).toHaveBeenCalledWith(oldLocation);
244
+ });
138
245
  });
139
246
 
140
- it('loads payload from external storage when storageLocation is set', async () => {
141
- const storage = createStorage();
142
- const fullData = {
143
- id: 'item-1',
144
- name: 'From S3',
145
- data: [{ key: 'sample', value: { main: [] } }],
146
- };
147
- (storage.load as jest.Mock).mockResolvedValue(fullData);
148
-
149
- const repo = new TestRepo(createDbManager({ get: jest.fn() as any }), storage);
150
- const result = await (repo as any).hydrateFromExternalStorage({
151
- id: 'item-1',
152
- name: 'Placeholder',
153
- data: [],
154
- storageLocation: { type: 's3', key: 'item-key' },
247
+ describe('updateItem', () => {
248
+ it('cleans up old S3 file when updating with new storageLocation', async () => {
249
+ const oldLocation = { type: 's3' as const, key: 'old-key' };
250
+ const newLocation = { type: 's3' as const, key: 'new-key' };
251
+
252
+ const client = createDbManager({
253
+ get: jest.fn().mockResolvedValue({
254
+ Item: {
255
+ id: 'item-1',
256
+ name: 'Test',
257
+ storageLocation: oldLocation,
258
+ },
259
+ }),
260
+ update: jest.fn().mockResolvedValue({
261
+ Attributes: {
262
+ id: 'item-1',
263
+ name: 'Updated',
264
+ storageLocation: newLocation,
265
+ },
266
+ }),
267
+ }).client as any;
268
+
269
+ const storage = createStorage();
270
+ const repo = new TestRepo({ client } as any, storage);
271
+
272
+ const updateValue = {
273
+ id: 'item-1',
274
+ name: 'Updated',
275
+ };
276
+
277
+ const updatedItem = createTestItem({ id: 'item-1', name: 'Updated' });
278
+ (updatedItem as any).storageLocation = newLocation;
279
+
280
+ repo.mockSuperUpdateItem = jest.fn().mockResolvedValue(updatedItem as any);
281
+
282
+ await repo.updateItem(updateValue);
283
+
284
+ expect(storage.delete).toHaveBeenCalledWith(oldLocation);
155
285
  });
156
286
 
157
- expect(storage.load).toHaveBeenCalledWith({ type: 's3', key: 'item-key' });
158
- expect(result?.name).toBe('From S3');
159
- expect(result?.data).toEqual([{ key: 'sample', value: { main: [] } }]);
287
+ it('does not delete S3 file when storageLocation is unchanged', async () => {
288
+ const location = { type: 's3' as const, key: 'same-key' };
289
+
290
+ const client = createDbManager({
291
+ get: jest.fn().mockResolvedValue({
292
+ Item: {
293
+ id: 'item-1',
294
+ name: 'Test',
295
+ storageLocation: location,
296
+ },
297
+ }),
298
+ update: jest.fn().mockResolvedValue({
299
+ Attributes: {
300
+ id: 'item-1',
301
+ name: 'Updated',
302
+ storageLocation: location,
303
+ },
304
+ }),
305
+ }).client as any;
306
+
307
+ const storage = createStorage();
308
+ const repo = new TestRepo({ client } as any, storage);
309
+
310
+ const updateValue = {
311
+ id: 'item-1',
312
+ name: 'Updated',
313
+ };
314
+
315
+ const updatedItem = createTestItem({ id: 'item-1', name: 'Updated' });
316
+ (updatedItem as any).storageLocation = location;
317
+
318
+ repo.mockSuperUpdateItem = jest.fn().mockResolvedValue(updatedItem as any);
319
+
320
+ await repo.updateItem(updateValue);
321
+
322
+ expect(storage.delete).not.toHaveBeenCalled();
323
+ });
160
324
  });
161
325
 
162
- it('deletes externalized payloads when deleting items', async () => {
163
- const client = createDbManager({
164
- get: jest.fn().mockResolvedValue({ Item: { storageLocation: { type: 's3', key: 'item-key' } } }),
165
- delete: jest.fn().mockResolvedValue({}),
166
- }).client as any;
167
- const storage = createStorage();
168
- const repo = new TestRepo({ client } as any, storage);
326
+ describe('getItem', () => {
327
+ it('loads payload from external storage when storageLocation is set', async () => {
328
+ const storage = createStorage();
329
+ const fullData = {
330
+ id: 'item-1',
331
+ name: 'From S3',
332
+ data: [{ key: 'sample', value: { main: [] } }],
333
+ };
334
+ (storage.load as jest.Mock).mockResolvedValue(fullData);
335
+
336
+ const repo = new TestRepo(createDbManager({ get: jest.fn() as any }), storage);
337
+ const result = await repo.testHydrateFromExternalStorage({
338
+ id: 'item-1',
339
+ name: 'Placeholder',
340
+ data: [],
341
+ storageLocation: { type: 's3', key: 'item-key' },
342
+ } as TestItem);
343
+
344
+ expect(storage.load).toHaveBeenCalledWith({ type: 's3', key: 'item-key' });
345
+ expect(result?.name).toBe('From S3');
346
+ expect(result?.data).toEqual([{ key: 'sample', value: { main: [] } }]);
347
+ });
169
348
 
170
- await repo.deleteItem({ id: 'item-1' });
349
+ it('returns inline data when no storageLocation is present', async () => {
350
+ const storage = createStorage();
351
+ const repo = new TestRepo(createDbManager({ get: jest.fn() as any }), storage);
352
+ const inlineRecord = {
353
+ id: 'item-1',
354
+ name: 'Inline Item',
355
+ data: [{ key: 'sample', value: { main: [] } }],
356
+ } as TestItem;
357
+
358
+ const result = await repo.testHydrateFromExternalStorage(inlineRecord);
359
+
360
+ expect(storage.load).not.toHaveBeenCalled();
361
+ expect(result).toBeDefined();
362
+ expect(result?.name).toBe('Inline Item');
363
+ expect(result?.data).toEqual([{ key: 'sample', value: { main: [] } }]);
364
+ });
171
365
 
172
- expect(storage.delete).toHaveBeenCalledWith({ type: 's3', key: 'item-key' });
366
+ it('never includes storageLocation in response', async () => {
367
+ const storage = createStorage();
368
+ const fullData = {
369
+ id: 'item-1',
370
+ name: 'From S3',
371
+ data: [{ key: 'sample', value: { main: [] } }],
372
+ };
373
+ (storage.load as jest.Mock).mockResolvedValue(fullData);
374
+
375
+ const repo = new TestRepo(createDbManager(), storage);
376
+ const result = await repo.testHydrateFromExternalStorage({
377
+ id: 'item-1',
378
+ name: 'Placeholder',
379
+ data: [],
380
+ storageLocation: { type: 's3', key: 'item-key' },
381
+ } as TestItem);
382
+
383
+ // storageLocation is an internal implementation detail and should never be exposed
384
+ expect(result?.storageLocation).toBeUndefined();
385
+ expect(result?.name).toBe('From S3');
386
+ expect(result?.data).toEqual([{ key: 'sample', value: { main: [] } }]);
387
+ });
173
388
  });
174
389
 
175
- it('returns inline data when no storageLocation is present', async () => {
176
- const storage = createStorage();
177
- const repo = new TestRepo(createDbManager({ get: jest.fn() as any }), storage);
178
- const inlineRecord = {
179
- id: 'item-1',
180
- name: 'Inline Item',
181
- data: [{ key: 'sample', value: { main: [] } }],
182
- };
183
-
184
- const result = await (repo as any).hydrateFromExternalStorage(inlineRecord);
185
-
186
- expect(storage.load).not.toHaveBeenCalled();
187
- expect(result).toBeDefined();
188
- expect(result?.name).toBe('Inline Item');
189
- expect(result?.data).toEqual([{ key: 'sample', value: { main: [] } }]);
390
+ describe('deleteItem', () => {
391
+ it('deletes externalized payloads when deleting items', async () => {
392
+ const client = createDbManager({
393
+ get: jest.fn().mockResolvedValue({ Item: { storageLocation: { type: 's3', key: 'item-key' } } }),
394
+ delete: jest.fn().mockResolvedValue({}),
395
+ }).client as any;
396
+ const storage = createStorage();
397
+ const repo = new TestRepo({ client } as any, storage);
398
+
399
+ await repo.deleteItem({ id: 'item-1' });
400
+
401
+ expect(storage.delete).toHaveBeenCalledWith({ type: 's3', key: 'item-key' });
402
+ });
403
+
404
+ it('does not attempt to delete S3 when item has no storageLocation', async () => {
405
+ const client = createDbManager({
406
+ get: jest.fn().mockResolvedValue({ Item: { id: 'item-1', name: 'Test' } }),
407
+ delete: jest.fn().mockResolvedValue({}),
408
+ }).client as any;
409
+ const storage = createStorage();
410
+ const repo = new TestRepo({ client } as any, storage);
411
+
412
+ await repo.deleteItem({ id: 'item-1' });
413
+
414
+ expect(storage.delete).not.toHaveBeenCalled();
415
+ });
190
416
  });
191
417
 
192
- it('cleans up old S3 file when updating with new storageLocation', async () => {
193
- const oldLocation = { type: 's3' as const, key: 'old-key' };
194
- const newLocation = { type: 's3' as const, key: 'new-key' };
195
-
196
- const client = createDbManager({
197
- get: jest.fn().mockResolvedValue({
198
- Item: {
199
- id: 'item-1',
200
- name: 'Test',
201
- storageLocation: oldLocation,
202
- },
203
- }),
204
- update: jest.fn().mockResolvedValue({
205
- Attributes: {
206
- id: 'item-1',
207
- name: 'Updated',
208
- storageLocation: newLocation,
209
- },
210
- }),
211
- }).client as any;
212
-
213
- const storage = createStorage();
214
- const repo = new TestRepo({ client } as any, storage);
215
-
216
- // Update without storageLocation (it will be fetched from DynamoDB)
217
- const updateValue = {
218
- id: 'item-1',
219
- name: 'Updated',
220
- };
221
-
222
- // Create an updated item with the new storageLocation
223
- const updatedItem = createTestItem({ id: 'item-1', name: 'Updated' });
224
- (updatedItem as any).storageLocation = newLocation;
225
-
226
- // Mock super.updateItem using the custom mock hook
227
- repo.mockSuperUpdateItem = jest.fn().mockResolvedValue(updatedItem as any);
228
-
229
- await repo.updateItem(updateValue);
230
-
231
- expect(storage.delete).toHaveBeenCalledWith(oldLocation);
418
+ describe('isDynamoItemSizeLimitError', () => {
419
+ it('detects ValidationException with size message', () => {
420
+ const repo = new TestRepo(createDbManager(), createStorage());
421
+ const error = {
422
+ code: 'ValidationException',
423
+ message: 'Item size has exceeded the maximum allowed size',
424
+ };
425
+
426
+ expect(repo.testIsDynamoItemSizeLimitError(error)).toBe(true);
427
+ });
428
+
429
+ it('detects TransactionCanceledException with size in cancellation reasons', () => {
430
+ const repo = new TestRepo(createDbManager(), createStorage());
431
+ const error = {
432
+ code: 'TransactionCanceledException',
433
+ CancellationReasons: [
434
+ {
435
+ Code: 'ValidationException',
436
+ Message: 'Item size exceeded 400 KB limit',
437
+ },
438
+ ],
439
+ };
440
+
441
+ expect(repo.testIsDynamoItemSizeLimitError(error)).toBe(true);
442
+ });
443
+
444
+ it('detects size keywords in error message', () => {
445
+ const repo = new TestRepo(createDbManager(), createStorage());
446
+ const error = {
447
+ message: 'The item size exceeds the maximum allowed size',
448
+ };
449
+
450
+ expect(repo.testIsDynamoItemSizeLimitError(error)).toBe(true);
451
+ });
452
+
453
+ it('returns false for non-size-related errors', () => {
454
+ const repo = new TestRepo(createDbManager(), createStorage());
455
+ const error = {
456
+ code: 'ResourceNotFoundException',
457
+ message: 'Table not found',
458
+ };
459
+
460
+ expect(repo.testIsDynamoItemSizeLimitError(error)).toBe(false);
461
+ });
462
+
463
+ it('returns false for null/undefined errors', () => {
464
+ const repo = new TestRepo(createDbManager(), createStorage());
465
+
466
+ expect(repo.testIsDynamoItemSizeLimitError(null)).toBe(false);
467
+ expect(repo.testIsDynamoItemSizeLimitError(undefined)).toBe(false);
468
+ });
469
+ });
470
+
471
+ describe('isContentInS3', () => {
472
+ it('returns true when storageLocation exists and large content fields are empty', () => {
473
+ const repo = new TestRepo(createDbManager(), createStorage());
474
+ const item = createTestItem({ data: [] });
475
+ (item as any).storageLocation = { type: 's3', key: 'item-key' };
476
+
477
+ expect(repo.testIsContentInS3(item)).toBe(true);
478
+ });
479
+
480
+ it('returns false when storageLocation exists but large content fields have data', () => {
481
+ const repo = new TestRepo(createDbManager(), createStorage());
482
+ const item = createTestItem({ data: [{ key: 'sample', value: { main: [] } }] });
483
+ (item as any).storageLocation = { type: 's3', key: 'item-key' };
484
+
485
+ expect(repo.testIsContentInS3(item)).toBe(false);
486
+ });
487
+
488
+ it('returns false when no storageLocation', () => {
489
+ const repo = new TestRepo(createDbManager(), createStorage());
490
+ const item = createTestItem();
491
+
492
+ expect(repo.testIsContentInS3(item)).toBe(false);
493
+ });
232
494
  });
233
495
 
234
- it('does not delete S3 file when storageLocation is unchanged', async () => {
235
- const location = { type: 's3' as const, key: 'same-key' };
236
-
237
- const client = createDbManager({
238
- get: jest.fn().mockResolvedValue({
239
- Item: {
240
- id: 'item-1',
241
- name: 'Test',
242
- storageLocation: location,
243
- },
244
- }),
245
- update: jest.fn().mockResolvedValue({
246
- Attributes: {
247
- id: 'item-1',
248
- name: 'Updated',
249
- storageLocation: location,
250
- },
251
- }),
252
- }).client as any;
253
-
254
- const storage = createStorage();
255
- const repo = new TestRepo({ client } as any, storage);
256
-
257
- // Update without storageLocation (it will be fetched from DynamoDB)
258
- const updateValue = {
259
- id: 'item-1',
260
- name: 'Updated',
261
- };
262
-
263
- // Create an updated item with the same storageLocation
264
- const updatedItem = createTestItem({ id: 'item-1', name: 'Updated' });
265
- (updatedItem as any).storageLocation = location;
266
-
267
- // Mock super.updateItem using the custom mock hook
268
- repo.mockSuperUpdateItem = jest.fn().mockResolvedValue(updatedItem as any);
269
-
270
- await repo.updateItem(updateValue);
271
-
272
- expect(storage.delete).not.toHaveBeenCalled();
496
+ describe('getKeyFieldsValues', () => {
497
+ it('preserves key fields and small metadata', () => {
498
+ const repo = new TestRepo(createDbManager(), createStorage());
499
+ const obj = {
500
+ id: 'item-1',
501
+ name: 'Test',
502
+ data: [{ key: 'large', value: { content: 'big' } }],
503
+ };
504
+
505
+ const result = repo.testGetKeyFieldsValues(obj);
506
+
507
+ expect(result.id).toBe('item-1');
508
+ expect(result.name).toBe('Test');
509
+ });
510
+
511
+ it('empties large content fields (fieldsAsJsonString)', () => {
512
+ const repo = new TestRepo(createDbManager(), createStorage());
513
+ const obj = {
514
+ id: 'item-1',
515
+ name: 'Test',
516
+ data: [{ key: 'large', value: { content: 'big' } }],
517
+ };
518
+
519
+ const result = repo.testGetKeyFieldsValues(obj);
520
+
521
+ // data is in fieldsAsJsonString, so should be empty array
522
+ expect(result.data).toEqual([]);
523
+ });
524
+
525
+ it('removes storageLocation from result', () => {
526
+ const repo = new TestRepo(createDbManager(), createStorage());
527
+ const obj = {
528
+ id: 'item-1',
529
+ name: 'Test',
530
+ data: [],
531
+ storageLocation: { type: 's3', key: 'item-key' },
532
+ };
533
+
534
+ const result = repo.testGetKeyFieldsValues(obj);
535
+
536
+ expect(result.storageLocation).toBeUndefined();
537
+ });
273
538
  });
274
539
  });