-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTestUtils.util.js
More file actions
56 lines (51 loc) · 1.37 KB
/
TestUtils.util.js
File metadata and controls
56 lines (51 loc) · 1.37 KB
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
/**
* Created by pedro.f.marquez.soto on 2/16/2017.
*/
import dynalite from 'dynalite';
import AWS from 'aws-sdk';
var dynaliteServer = dynalite({createTableMs: 50});
module.exports.mockDB = () => {
AWS.config.update({
region: "us-west-2",
endpoint: "http://localhost:4567"
});
var dynamodb = new AWS.DynamoDB();
return new Promise((resolve, reject) => {
dynaliteServer.listen(4567, function(err) {
dynamodb.listTables({},function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
if(data.TableNames.length <= 0){
dynamodb.createTable({
TableName : "TacoGallery",
KeySchema: [
{ AttributeName: "id", KeyType: "HASH"}, //Partition key
{ AttributeName: "name", KeyType: "RANGE" } //Sort key
],
AttributeDefinitions: [
{ AttributeName: "id", AttributeType: "S" },
{ AttributeName: "name", AttributeType: "S" }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}},
function(err, data) {
if (err) {
console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
reject(err);
} else {
setTimeout(()=>{
resolve(data);
},1000)
}
});
}
else{
resolve();
}
}
});
});
});
}