-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
197 lines (190 loc) · 6.4 KB
/
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// © 2013 Triton Digital, Inc.
"use strict";
var chai = require("chai");
var expect = chai.expect;
var packageJson = require('./package.json');
var model = require('./model');
var ObjectId = require('mongodb').ObjectID;
var business = require('./business');
var StatusResponse = require('./lib/statusResponse').StatusResponse;
var prevValue = '';
function asyncAssertionCheck(done, f) {
try {
f();
done();
} catch(e) {
done(e);
}
}
describe('Setup tests', function () {
this.timeout(0);
before(function (done) {
model.initDb(
function (err) {
if (err) {
var statusResponse = new StatusResponse('error', 'System Error. Please try again', '', 'initDb', err);
console.log(JSON.stringify(statusResponse));
done(err);
}
else {
console.log('initDb SUCCESS');
done();
}
}
);
});//before
describe('Test isAlive (business)',
function () {
it('should return a success status response', function (done) {
business.isAlive(
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.status).to.equal('success');
});
}
);
});
}
);
describe('Test Data Access (business)',
function () {
it('should return a list of all members', function (done) {
business.listMembers(null,null, null,
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
});
}
);
});
it('should return a page of 10 members', function (done) {
var pageSpec = {pageLength:10, pageNum: 0};
business.listMembers(null, pageSpec, null,
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
expect(statusResponse.data.length).to.equal(pageSpec.pageLength);
prevValue = statusResponse.data[0]._id; //for compare later
});
}
);
});
it('should return a different page of 10 members', function (done) {
var pageSpec = {pageLength:10, pageNum: 1};
business.listMembers(null, pageSpec, null,
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
expect(statusResponse.data.length).to.equal(pageSpec.pageLength);
expect(statusResponse.data[0]._id).to.not.equal(prevValue);
});
}
);
});
it('should return a page of 10 members with reduced payload', function (done) {
var pageSpec = {pageLength:10, pageNum: 1};
business.listMembers(null, pageSpec, {first_name:1, last_name:1},
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
expect(statusResponse.data.length).to.equal(pageSpec.pageLength);
expect(statusResponse.data[0].city).to.not.exist;
});
}
);
});
it('should return a page of 20 members', function (done) {
var pageSpec = {pageLength:20, pageNum: 0};
business.listMembers(null, pageSpec, null,
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
expect(statusResponse.data.length).to.equal(pageSpec.pageLength);
});
}
);
});
it('should return a page of 50 members', function (done) {
var pageSpec = {pageLength:50, pageNum: 0};
business.listMembers(null, pageSpec, null,
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
expect(statusResponse.data.length).to.equal(pageSpec.pageLength);
prevValue = statusResponse.data.length; //for compare later
});
}
);
});
it('should return a page of members, filtered by state=GA', function (done) {
var filterSpec = {field:'state', value: 'GA'};
var pageSpec = {pageLength:50, pageNum: 0};
business.listMembers(filterSpec,pageSpec, null,
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
expect(statusResponse.data.length).to.be.lessThan(prevValue);
});
}
);
});
it('should return filtered list using contains', function (done) {
var matchString = 'han';
business.filterMembersByName(matchString, {},
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
var elem0 = statusResponse.data[0];
var sTmp = elem0.first_name + elem0.last_name;
expect(sTmp.indexOf(matchString)).to.be.greaterThan(-1); //make sure our match string is in our result somewhere
});
}
);
});
it('should return filtered list with reduced payload', function (done) {
var matchString = 'han';
business.filterMembersByName(matchString, {first_name:1, last_name:1},
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.array;
expect(statusResponse.data[0].city).to.not.exist;
});
}
);
});
it('should return a single document by Id', function (done) {
var id = '55b996ead4dbc1641d7239bd';
business.getMember(id,
function (err, statusResponse) {
asyncAssertionCheck(done, function () {
expect(err).to.not.exist;
expect(statusResponse.data).to.exist;
expect(statusResponse.data).to.be.an.object;
expect(statusResponse.data._id.toString()).to.equal(id); //make sure our match string is in our result somewhere
});
}
);
});
}
);
});