|
| 1 | +const { Table, Entity } = require('../index') |
| 2 | +const { DocumentClient } = require('./bootstrap-tests') |
| 3 | + |
| 4 | +const TestTable = new Table({ |
| 5 | + name: 'test-table', |
| 6 | + partitionKey: 'pk', |
| 7 | + sortKey: 'sk', |
| 8 | + DocumentClient |
| 9 | +}) |
| 10 | + |
| 11 | +const TestEntity = new Entity({ |
| 12 | + name: 'TestEntity', |
| 13 | + autoExecute: false, |
| 14 | + attributes: { |
| 15 | + email: { type: 'string', partitionKey: true }, |
| 16 | + sort: { type: 'string', sortKey: true }, |
| 17 | + test: 'string' |
| 18 | + }, |
| 19 | + table: TestTable |
| 20 | +}) |
| 21 | + |
| 22 | +const TestTable2 = new Table({ |
| 23 | + name: 'test-table', |
| 24 | + partitionKey: 'pk', |
| 25 | + sortKey: 'sk', |
| 26 | + DocumentClient |
| 27 | +}) |
| 28 | + |
| 29 | +const TestEntity2 = new Entity({ |
| 30 | + name: 'TestEntity', |
| 31 | + autoExecute: false, |
| 32 | + attributes: { |
| 33 | + pk: { type: 'string', partitionKey: true }, |
| 34 | + sk: { type: 'string', sortKey: true }, |
| 35 | + test: 'string' |
| 36 | + }, |
| 37 | + table: TestTable2 |
| 38 | +}) |
| 39 | + |
| 40 | +describe.skip('get - integration',()=>{ |
| 41 | + |
| 42 | + it('gets the key from inputs (async)', async () => { |
| 43 | + const { TableName, Key } = await TestEntity.get({ pk: 'test-pk', sk: 'test-sk' }) |
| 44 | + expect(TableName).toBe('test-table') |
| 45 | + expect(Key).toEqual({ pk: 'test-pk', sk: 'test-sk' }) |
| 46 | + }) |
| 47 | + |
| 48 | + it('gets the key from input aliases (async)', async () => { |
| 49 | + let { TableName, Key } = await TestEntity.get({ email: 'test-pk', sort: 'test-sk' }) |
| 50 | + expect(TableName).toBe('test-table') |
| 51 | + expect(Key).toEqual({ pk: 'test-pk', sk: 'test-sk' }) |
| 52 | + }) |
| 53 | + |
| 54 | + it('filters out extra data (async)', async () => { |
| 55 | + let { TableName, Key } = await TestEntity.get({ pk: 'test-pk', sk: 'test-sk', test: 'test' }) |
| 56 | + expect(TableName).toBe('test-table') |
| 57 | + expect(Key).toEqual({ pk: 'test-pk', sk: 'test-sk' }) |
| 58 | + }) |
| 59 | + |
| 60 | + it('coerces key values to correct types (async)', async () => { |
| 61 | + let { TableName, Key } = await TestEntity.get({ pk: 1, sk: true }) |
| 62 | + expect(TableName).toBe('test-table') |
| 63 | + expect(Key).toEqual({ pk: '1', sk: 'true' }) |
| 64 | + }) |
| 65 | + |
| 66 | + it('fails with undefined input (async)', async () => { |
| 67 | + expect(TestEntity.get()).rejects.toThrow(`'pk' or 'email' is required`) |
| 68 | + }) |
| 69 | + |
| 70 | + it('fails when missing the sortKey (async)', () => { |
| 71 | + expect(TestEntity.get({ pk: 'test-pk' })).rejects.toThrow(`'sk' or 'sort' is required`) |
| 72 | + }) |
| 73 | + |
| 74 | + it('fails when missing partitionKey (no alias) (async)', () => { |
| 75 | + expect(TestEntity2.get()).rejects.toThrow(`'pk' is required`) |
| 76 | + }) |
| 77 | + |
| 78 | + it('fails when missing the sortKey (no alias) (async)', () => { |
| 79 | + expect(TestEntity2.get({ pk: 'test-pk' })).rejects.toThrow(`'sk' is required`) |
| 80 | + }) |
| 81 | + |
| 82 | +}) |
0 commit comments