-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathintegration.js
225 lines (188 loc) · 6.3 KB
/
integration.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
var expect = require('chai').expect;
var bidController = require('../../server/bids/bidController.js');
var productController = require('../../server/products/productController.js');
var userController = require('../../server/users/userController.js');
var request = require('supertest');
var app = require('../../server/server.js');
var token;
var testUser;
var updatedUser;
var testProduct;
var testProductId;
describe('the userController', function () {
describe('the userController object', function () {
it('should be an object', function () {
expect(userController).to.be.a('object');
});
it('should have all the necessary methods', function () {
expect(userController).to.have.property('signin');
expect(userController).to.have.property('signup');
expect(userController).to.have.property('checkAuth');
expect(userController).to.have.property('userInfo');
expect(userController).to.have.property('updateUser');
expect(userController).to.have.property('getUserLocation');
});
});
});
describe('the userController methods', function () {
var generateUserEmail = function () {
var chars = '1234567890abcdefghijklmnopqrstuvwxyz';
var email = '';
for (var i = 0; i < 10; i++) {
email += chars[Math.floor(Math.random() * chars.length)];
}
email+='@user.com';
return email;
};
describe('Sign up a user', function () {
var testEmail = generateUserEmail();
testUser = {
email : testEmail,
password : 'test',
firstName : 'tester',
lastName : 'testerson',
phoneNumber: '1231231234',
zip : 94112
};
it('should sign up a new user and return a token', function (done) {
request(app)
.post('/api/users/signup')
.send(testUser)
.end(function (err, res) {
if (err) throw err;
expect(res.body.token).to.exist;
token = res.body.token;
done();
});
});
it('should find new user on the database', function (done) {
request(app)
.get('/api/users/profile')
.set('x-access-token', token)
.end(function (err, res) {
if (err) throw err;
expect(res.body.userInfo).to.exist;
done();
});
});
it('should error when looking for user and token is not provided', function (done) {
request(app)
.get('/api/users/profile')
.expect(401)
.end(done);
});
});
describe('Sign in a user', function () {
it('should sign in the user and return a token', function (done) {
request(app)
.post('/api/users/signin')
.send({email: testUser.email, password: testUser.password})
.end(function (err, res) {
expect(res.body.token).to.exist;
done();
});
});
it('should fail to sign in when wrong password is supplied', function (done) {
request(app)
.post('/api/users/signin')
.send({email: testUser.email, password: 'wrongpassword'})
.expect(400)
.end(done);
});
});
describe('Update a user', function () {
updatedUser = {
firstName : 'updater',
lastName : 'updaterson',
email : testUser.email,
phoneNumber: '0980980987',
address1: '123 45th st.',
address2: 'Apt 67',
city: 'San Francisco',
state: 'CA',
zip: 94112
};
it('should successfully update a user', function (done) {
request(app)
.post('/api/users/update')
.set('x-access-token', token)
.send(updatedUser)
.expect(200)
.end(done);
});
});
});
describe('the productController', function () {
describe('the productController object', function () {
it('should be an object', function () {
expect(productController).to.be.a('object');
});
it('should have all the necessary methods', function () {
expect(productController).to.have.property('allProducts');
expect(productController).to.have.property('productsByTags');
expect(productController).to.have.property('newProduct');
expect(productController).to.have.property('updateProduct');
expect(productController).to.have.property('addTags');
expect(productController).to.have.property('removeTags');
expect(productController).to.have.property('deleteProduct');
expect(productController).to.have.property('userProducts');
expect(productController).to.have.property('productTags');
});
});
});
describe('the productController methods', function () {
describe('create a product, find it, and delete it', function () {
testProduct = {
product: {
name: 'testProduct',
photoURL: 'www.testproducturl.com/test.jpg',
price: 100
},
tags: ['test', 'data']
};
it('should create a new product', function (done) {
request(app)
.post('/api/products')
.set('x-access-token', token)
.send(testProduct)
.expect(200)
.end(done);
});
it('should find at least 1 product', function (done) {
request(app)
.get('/api/products')
.set('x-access-token', token)
.end(function (err, res) {
for (var i = 0; i < res.body.products.length; i++) {
if (res.body.products[i].name === testProduct.product.name) {
testProductId = res.body.products[i].id;
}
}
expect(res.body.products).to.have.length.above(0);
expect(testProduct).to.not.be.undefined;
done();
});
});
it('should delete the product', function (done) {
request(app)
.delete('/api/products/' + testProductId)
.set('x-access-token', token)
.expect(200)
.end(done);
});
});
});
describe('the bidController', function () {
describe('the bidController object', function () {
it('should be an object', function () {
expect(bidController).to.be.a('object');
});
it('should have all the necessary methods', function () {
expect(bidController).to.have.property('newBid');
expect(bidController).to.have.property('oldMessageHandler');
expect(bidController).to.have.property('allBids');
expect(bidController).to.have.property('deleteBid');
expect(bidController).to.have.property('messageHandler');
});
});
});