-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dynamo.test.js
80 lines (73 loc) · 2.98 KB
/
Dynamo.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const assert = require('assert')
const Test = require('thunk-test')
const Dynamo = require('./Dynamo')
const combinedTest = Test.all([
Test('Dynamo.AttributeValue', Dynamo.AttributeValue)
.case('hey', { S: 'hey' })
.case('', { S: '' })
.case(1, { N: '1' })
.case(1.015, { N: '1.015' })
.case(0, { N: '0' })
.case(-1, { N: '-1' })
.case(true, { BOOL: true })
.case(null, { NULL: true })
.case(undefined, { NULL: true })
.case({ a: 1, b: ['a', true] }, { M: { a: { N: '1' }, b: { L: [{ S: 'a' }, { BOOL: true }] } } })
.throws(NaN, new TypeError('unknown value NaN')),
Test('Dynamo.attributeValueToJSON', Dynamo.attributeValueToJSON)
.case({ S: 'hey' }, 'hey')
.case({ S: '' }, '')
.case({ N: '1' }, 1)
.case({ N: '1.015' }, 1.015)
.case({ N: '0' }, 0)
.case({ N: '-1' }, -1)
.case({ BOOL: true }, true)
.case({ NULL: true }, null)
.case({ NULL: false }, null)
.case({ M: { a: { N: '1' }, b: { L: [{ S: 'a' }, { BOOL: true }] } } }, { a: 1, b: ['a', true] })
.throws(NaN, new TypeError('unknown attributeValue NaN')),
Test('Dynamo.itemResponseToJSON', Dynamo.itemResponseToJSON)
.case({ Item: { a: { S: 'hey' } } }, { a: 'hey' })
.case({ Item: { b: { S: '' } } }, { b: '' })
.case({ Item: { c: { N: '1' } } }, { c: 1 })
.case({ Item: { a: { M: { a: { N: '1' }, b: { L: [{ S: 'a' }, { BOOL: true }] } } } } }, { a: { a: 1, b: ['a', true] } }),
Test('Dynamo.AttributeType', Dynamo.AttributeType)
.case('string', 'S')
.case('S', 'S')
.case('number', 'N')
.case('N', 'N')
.case('binary', 'B')
.case('B', 'B')
.throws('?', new TypeError('unknown type for ?')),
Test('Dynamo', Dynamo)
.case({ endpoint: 'http://localhost:8000' }, async function (dynamo) {
await dynamo.deleteTable('test-1').catch(() => {})
await dynamo.waitFor('test-1', 'tableNotExists')
await dynamo.deleteTable('test-2').catch(() => {})
await dynamo.waitFor('test-2', 'tableNotExists')
{
const response = await dynamo.createTable('test-1', [{ a: 'string' }, { b: 'number' }])
assert.strictEqual(response.TableDescription.TableName, 'test-1')
}
{
const response = await dynamo.createTable('test-2', [{ a: 'string' }, { b: 'number' }], {
BillingMode: 'PAY_PER_REQUEST',
})
assert.strictEqual(response.TableDescription.TableName, 'test-2')
assert.strictEqual(response.TableDescription.BillingModeSummary.BillingMode, 'PAY_PER_REQUEST')
}
await dynamo.deleteTable('test-1').catch(() => {})
await dynamo.waitFor('test-1', 'tableNotExists')
await dynamo.deleteTable('test-2').catch(() => {})
await dynamo.waitFor('test-2', 'tableNotExists')
})
.case({
endpoint: 'http://localhost:8000',
}, async function (dynamo) {
assert.strictEqual(dynamo.connection.config.endpoint, 'http://localhost:8000')
}),
])
if (process.argv[1] == __filename) {
combinedTest()
}
module.exports = combinedTest