-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathindexTest.js
117 lines (102 loc) · 3.21 KB
/
indexTest.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
"use strict";
//Define the modules required to mocha testing
const assert = require("chai").assert;
const http = require ("http");
const expect = require("chai").expect;
const should = require("should");
const aws = require ("aws-sdk");
const seeder = require("../src/seeder.js");
const Plugin = require("../index.js");
const serverlessMock = require("./serverlessMock");
function get(url) {
return new Promise(function(resolve, reject) {
http.get(url, function(incoming) {
resolve(incoming);
}).on("error", reject);
});
}
function getWithRetry(url, retryCount, previousError) {
retryCount = retryCount || 0;
if (retryCount >= 3) {
return Promise.reject(new Error("Exceeded retry count for get of " + url + ": " + previousError.message));
}
return get(url)
.catch(function(error) {
return new Promise(function(resolve) { setTimeout(resolve, 10000); })
.then(function() {
return getWithRetry(url, retryCount + 1, error);
});
});
}
describe("Port function",function(){
let service;
before(function(){
this.timeout(60000);
service = new Plugin(serverlessMock, { stage: "test" });
return service.installHandler();
});
it("Port should return number",function(){
assert(typeof service.port, "number");
});
it("Port value should be >= 0 and < 65536",function() {
this.timeout(40000);
return service.startHandler()
.then(function() {
return new Promise(function(resolve) { setTimeout(resolve, 2000); });
})
.then(function() {
return getWithRetry(`http://localhost:${service.port}/shell/`);
})
.then(function(response){
assert.equal(response.statusCode, 200);
});
});
after(function(){
return service.endHandler();
});
});
describe("Check the dynamodb function",function(){
it("Endpoint should listen to the port",function () {
let server;
before(function () {
server = dynamodbOptions.listen(port);
});
after(function () {
assert.ok;
});
});
it("Should be an object",function(){
let dynamoOptions = Plugin.prototype.dynamodbOptions;
let raw = new aws.DynamoDB(dynamoOptions);
raw.should.be.type("object");
});
it("Should be an object",function(){
let dynamoOptions = Plugin.prototype.dynamodbOptions;
let doc = new aws.DynamoDB(dynamoOptions);
doc.should.be.type("object");
});
});
describe ("Start handler function",function(){
it ("Should not be null",function(){
let handler = Plugin.prototype.startHandler;
assert(handler =! null);
});
});
describe ("createTable functon",function(){
it ("Should check as a function",function(){
const tbl = Plugin.prototype.createTable;
assert.equal(typeof tbl, "function");
});
});
describe ("dropTable functon",function(){
it ("Should check as a function",function(){
const tbl = Plugin.prototype.dropTable;
assert.equal(typeof tbl, "function");
});
});
describe ("Check the Seeder file",function(){
it("Table name shoud be a string",function(){
let tblName = seeder.writeSeeds.name;
expect(tblName).to.be.a("string");
});
});