-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDynamoIndexQueryIterator.test.js
102 lines (92 loc) · 2.7 KB
/
DynamoIndexQueryIterator.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require('rubico/global')
const Test = require('thunk-test')
const assert = require('assert')
const Dynamo = require('./Dynamo')
const DynamoTable = require('./DynamoTable')
const DynamoIndex = require('./DynamoIndex')
const DynamoIndexQueryIterator = require('./DynamoIndexQueryIterator')
const test = new Test('DynamoIndexQueryIterator', async function () {
const testTable = new DynamoTable({
name: 'test_table',
key: [{ id: 'string' }],
endpoint: 'http://localhost:8000/',
region: 'dynamodblocal',
})
await testTable.ready
const testStatusCreateTimeIndex = new DynamoIndex({
table: 'test_table',
key: [{ status: 'string' }, { createTime: 'number' }],
endpoint: 'http://localhost:8000/',
region: 'dynamodblocal',
})
await testStatusCreateTimeIndex.ready
{
let number = -1
while (++number < 50) {
await testTable.putItem({
id: number.toString(),
status: 'pending',
createTime: number + 1,
})
}
}
{
const array = []
const iter = DynamoIndexQueryIterator(
testStatusCreateTimeIndex,
'status = :status AND createTime > :createTime',
{ status: 'pending', createTime: 0 },
)
for await (const item of iter) {
array.push(map(item, Dynamo.attributeValueToJSON))
}
assert.equal(array.length, 50)
assert.equal(array[0].id, '0')
}
{
const array = []
const iter = DynamoIndexQueryIterator(
testStatusCreateTimeIndex,
'status = :status AND createTime > :createTime',
{ status: 'pending', createTime: 0 },
{ batchLimit: 10, scanIndexForward: true },
)
for await (const item of iter) {
array.push(map(item, Dynamo.attributeValueToJSON))
}
assert.equal(array.length, 50)
assert.equal(array[0].id, '0')
}
{
const array = []
const iter = DynamoIndexQueryIterator(
testStatusCreateTimeIndex,
'status = :status AND createTime > :createTime',
{ status: 'pending', createTime: 0 },
{ batchLimit: 10, scanIndexForward: false },
)
for await (const item of iter) {
array.push(map(item, Dynamo.attributeValueToJSON))
}
assert.equal(array.length, 50)
assert.equal(array[0].id, '49')
}
{
const array = []
const iter = DynamoIndexQueryIterator(
testStatusCreateTimeIndex,
'status = :status AND createTime > :createTime',
{ status: 'pending', createTime: 0 },
{ batchLimit: 10, limit: 30, scanIndexForward: true },
)
for await (const item of iter) {
array.push(map(item, Dynamo.attributeValueToJSON))
}
assert.equal(array.length, 30)
assert.equal(array[0].id, '0')
}
}).case()
if (process.argv[1] == __filename) {
test()
}
module.exports = test