Skip to content

Commit 600b670

Browse files
authored
test(table/query+scan): add coverage for hidden properties (dynamodb-toolbox#313)
* wip * revert
1 parent bacc1ae commit 600b670

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed

src/__tests__/table.query.unit.test.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const TestEntity = new Entity({
3030
name: 'TestEntity',
3131
autoExecute: false,
3232
attributes: {
33-
email: { type: 'string', partitionKey: true },
34-
sort: { type: 'string', sortKey: true },
33+
email: { type: 'string', partitionKey: true, hidden: true },
34+
sort: { type: 'string', sortKey: true, hidden: true },
3535
test: 'string',
3636
testSet: 'set',
3737
},
@@ -466,12 +466,10 @@ describe('query', () => {
466466
let result = await TestEntity.query('test-pk');
467467
expect(result).toEqual({
468468
Items: [
469-
{
470-
email: 'test-pk',
471-
sort: 'test-sk',
469+
expect.objectContaining({
472470
testSet: ['test1', 'test2'],
473471
entity: 'TestEntity',
474-
},
472+
}),
475473
],
476474
LastEvaluatedKey: null,
477475
});
@@ -507,4 +505,31 @@ describe('query', () => {
507505
LastEvaluatedKey: null,
508506
});
509507
});
508+
509+
it('should not return hidden properties', async () => {
510+
DocumentClient.query = jest.fn().mockReturnValue({
511+
promise: jest.fn().mockResolvedValue({
512+
Items: [
513+
{
514+
pk: 'test-pk',
515+
sk: 'test-sk',
516+
test: 'some-string',
517+
_et: 'TestEntity',
518+
},
519+
],
520+
LastEvaluatedKey: null,
521+
}),
522+
});
523+
524+
let result = await TestEntity.query('test-pk');
525+
expect(result).toEqual({
526+
Items: [
527+
{
528+
test: 'some-string',
529+
entity: 'TestEntity',
530+
},
531+
],
532+
LastEvaluatedKey: null,
533+
});
534+
});
510535
});

src/__tests__/table.scan.unit.test.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const TestEntity = new Entity({
1313
name: 'TestEntity',
1414
autoExecute: false,
1515
attributes: {
16-
email: { type: 'string', partitionKey: true },
17-
sort: { type: 'string', sortKey: true },
16+
email: { type: 'string', partitionKey: true, hidden: true },
17+
sort: { type: 'string', sortKey: true, hidden: true },
1818
test: 'string',
1919
testSet: { type: 'set' },
2020
},
@@ -194,12 +194,10 @@ describe('scan', () => {
194194
});
195195
expect(result).toEqual({
196196
Items: [
197-
{
198-
email: 'test-pk',
199-
sort: 'test-sk',
197+
expect.objectContaining({
200198
testSet: ['test1', 'test2'],
201199
entity: 'TestEntity',
202-
},
200+
}),
203201
],
204202
LastEvaluatedKey: null,
205203
});
@@ -225,11 +223,36 @@ describe('scan', () => {
225223
});
226224
expect(result).toEqual({
227225
Items: [
228-
{
229-
pk: 'test-pk',
230-
sk: 'test-sk',
226+
expect.objectContaining({
231227
testSet: DocumentClient.createSet(['test1', 'test2']),
232228
_et: 'TestEntity',
229+
})
230+
],
231+
LastEvaluatedKey: null,
232+
});
233+
});
234+
235+
it('should not return hidden properties', async () => {
236+
DocumentClient.scan = jest.fn().mockReturnValue({
237+
promise: jest.fn().mockResolvedValue({
238+
Items: [
239+
{
240+
pk: 'test-pk',
241+
sk: 'test-sk',
242+
test: 'some-string',
243+
_et: 'TestEntity',
244+
},
245+
],
246+
LastEvaluatedKey: null,
247+
}),
248+
});
249+
250+
let result = await TestEntity.scan();
251+
expect(result).toEqual({
252+
Items: [
253+
{
254+
test: 'some-string',
255+
entity: 'TestEntity',
233256
},
234257
],
235258
LastEvaluatedKey: null,

0 commit comments

Comments
 (0)