forked from dscdac/serverless-dynamodb-local
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestItems.js
120 lines (114 loc) · 2.97 KB
/
testItems.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"use strict";
const assert = require("chai").assert;
const http = require ("http");
const expect = require("chai").expect;
const should = require("should");
const aws = require ("aws-sdk");
aws.config.update({ accessKeyId: "localAccessKey", secretAccessKey: "localSecretAccessKey", region: "localRegion"});
var db = new aws.DynamoDB({ endpoint: "http://localhost:8000" });
var dbClient = new aws.DynamoDB.DocumentClient({ endpoint: "http://localhost:8000"});
describe("#Add Items", function() {
this.timeout(50000);
it("should add item to table", function(done) {
{
var params = {
TableName:"MyMovie",
Item:{
"year": 2017,
"title": "Big Movie",
"info":{
"plot": "Nothing happens at all.",
"rating": 0
}
}
};
dbClient.put(params, function(err, data) {
if (err) {
should.not.exist(data);
} else {
assert.isNotNull(data.Attributes);
assert.isOk(true, "This will pass");
}
done();
});
};
});
});
describe("#Update Items", function(){
this.timeout(50000);
it("should update the items", function(done){
var params = {
TableName:"MyMovie",
Key:{
"year": 2017,
"title": "Big Movie"
},
UpdateExpression: "set info.rating = :r, info.plot=:p, info.actors=:a",
ExpressionAttributeValues:{
":r":5.4,
":p":"Everything happens all at once.",
":a":["Steve", "Jonson", "Cethie"]
},
ReturnValues:"UPDATED_NEW"
};
dbClient.update(params, function(err,data){
if(err){
should.exist(err);
} else {
assert.isNotNull(data.Attributes);
assert.isOk(true, "This will pass");
}
done();
});
});
});
describe("#Delete Items", function(){
this.timeout(50000);
it("should delete the items", function(done){
var params = {
TableName:"Movies10",
Key:{
"year":2017,
"title":"Big Movie"
},
ConditionExpression:"info.rating <= :val",
ExpressionAttributeValues: {
":val": 5.0
}
};
dbClient.delete(params, function(err, data) {
if (err) {
should.exist(err);
} else {
should.not.exist(data);
}
done();
});
});
});
describe("#Retrieving from database",function(){
this.timeout(50000);
var params = {
TableName : "Movies10",
KeyConditionExpression: "#yr = :yyyy",
ExpressionAttributeNames:{
"#yr": "year"
},
ExpressionAttributeValues: {
":yyyy":2017
}
};
it ("Getting data from the table", function(done){
this.timeout(50000);
dbClient.query(params, function(err, data) {
if (err) {
should.exist(err);
} else {
data.Items.forEach(function(item) {
assert.equal(item.year + ": " + item.title, "2017: Big Movie", "==Matching the values.");
});
}
done();
});
});
});