Skip to content

Commit d2f2a77

Browse files
committed
misc tests
1 parent da319a4 commit d2f2a77

File tree

4 files changed

+898
-1
lines changed

4 files changed

+898
-1
lines changed

__tests__/bootstrap-tests.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ module.exports.DocumentClient = new AWS.DynamoDB.DocumentClient({
2828
})
2929

3030
// Delay helper
31-
module.exports.delay = ms => new Promise(res => setTimeout(res, ms))
31+
module.exports.delay = ms => new Promise(res => setTimeout(res, ms))
32+
33+
34+
module.exports.DocumentClient2 = new AWS.DynamoDB.DocumentClient({
35+
region: 'us-east-1',
36+
credentials: new AWS.SharedIniFileCredentials({profile: ''}),
37+
// convertEmptyValues: false
38+
})

__tests__/entity.get.int.test.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)