@@ -4,24 +4,21 @@ const DynamoDB = require('aws-sdk/clients/dynamodb');
4
4
const DynamoDBStreams = require ( 'aws-sdk/clients/dynamodbstreams' ) ;
5
5
const DynamoDBStreamReadable = require ( '..' ) ;
6
6
7
- const fromCallback = fun =>
8
- new Promise ( ( resolve , reject ) => {
9
- fun ( ( err , data ) => ( err ? reject ( err ) : resolve ( data ) ) ) ;
7
+ const delay = timeout =>
8
+ new Promise ( resolve => {
9
+ setTimeout ( resolve , timeout ) ;
10
10
} ) ;
11
- const wait = duration => fromCallback ( cb => setTimeout ( cb , duration ) ) ;
11
+
12
12
const batchWriteItem = ( dynamodb , tableName , items ) =>
13
- fromCallback ( cb =>
14
- dynamodb . batchWriteItem (
15
- {
16
- RequestItems : {
17
- [ tableName ] : items . map ( document => ( {
18
- PutRequest : document
19
- } ) )
20
- }
21
- } ,
22
- cb
23
- )
24
- ) ;
13
+ dynamodb
14
+ . batchWriteItem ( {
15
+ RequestItems : {
16
+ [ tableName ] : items . map ( document => ( {
17
+ PutRequest : document
18
+ } ) )
19
+ }
20
+ } )
21
+ . promise ( ) ;
25
22
26
23
test . before ( t => {
27
24
t . context . dynamodb = new DynamoDB ( {
@@ -44,34 +41,32 @@ test.beforeEach(async t => {
44
41
const tableName = uuid ( ) ;
45
42
t . context . tableName = tableName ;
46
43
47
- const table = await fromCallback ( cb =>
48
- dynamodb . createTable (
49
- {
50
- TableName : tableName ,
51
- AttributeDefinitions : [
52
- {
53
- AttributeName : 'Id' ,
54
- AttributeType : 'S'
55
- }
56
- ] ,
57
- KeySchema : [
58
- {
59
- AttributeName : 'Id' ,
60
- KeyType : 'HASH'
61
- }
62
- ] ,
63
- StreamSpecification : {
64
- StreamEnabled : true ,
65
- StreamViewType : 'NEW_AND_OLD_IMAGES'
66
- } ,
67
- ProvisionedThroughput : {
68
- ReadCapacityUnits : 1 ,
69
- WriteCapacityUnits : 1
44
+ const table = await dynamodb
45
+ . createTable ( {
46
+ TableName : tableName ,
47
+ AttributeDefinitions : [
48
+ {
49
+ AttributeName : 'Id' ,
50
+ AttributeType : 'S'
70
51
}
52
+ ] ,
53
+ KeySchema : [
54
+ {
55
+ AttributeName : 'Id' ,
56
+ KeyType : 'HASH'
57
+ }
58
+ ] ,
59
+ StreamSpecification : {
60
+ StreamEnabled : true ,
61
+ StreamViewType : 'NEW_AND_OLD_IMAGES'
71
62
} ,
72
- cb
73
- )
74
- ) ;
63
+ ProvisionedThroughput : {
64
+ ReadCapacityUnits : 1 ,
65
+ WriteCapacityUnits : 1
66
+ }
67
+ } )
68
+ . promise ( ) ;
69
+
75
70
t . context . table = table ;
76
71
} ) ;
77
72
@@ -96,15 +91,12 @@ test.serial('reads records that already exist', async t => {
96
91
await batchWriteItem ( dynamodb , tableName , documents ) ;
97
92
98
93
t . deepEqual (
99
- await fromCallback ( cb =>
100
- dynamodb . scan (
101
- {
102
- TableName : tableName ,
103
- Select : 'COUNT'
104
- } ,
105
- cb
106
- )
107
- ) ,
94
+ await dynamodb
95
+ . scan ( {
96
+ TableName : tableName ,
97
+ Select : 'COUNT'
98
+ } )
99
+ . promise ( ) ,
108
100
{ Count : documents . length , ScannedCount : documents . length }
109
101
) ;
110
102
@@ -173,7 +165,7 @@ test.serial('reads ongoing records', t => {
173
165
reject ( err ) ;
174
166
} ) ;
175
167
} ) ,
176
- wait ( 100 ) . then ( ( ) => batchWriteItem ( dynamodb , tableName , documents ) )
168
+ delay ( 100 ) . then ( ( ) => batchWriteItem ( dynamodb , tableName , documents ) )
177
169
] ) ;
178
170
} ) ;
179
171
@@ -234,7 +226,7 @@ test.serial('reads latest records', async t => {
234
226
reject ( err ) ;
235
227
} ) ;
236
228
} ) ,
237
- wait ( 100 ) . then ( ( ) => batchWriteItem ( dynamodb , tableName , subsequentDocuments ) )
229
+ delay ( 100 ) . then ( ( ) => batchWriteItem ( dynamodb , tableName , subsequentDocuments ) )
238
230
] ) ;
239
231
} ) ;
240
232
0 commit comments