-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtesting.js
More file actions
120 lines (119 loc) · 4.38 KB
/
testing.js
File metadata and controls
120 lines (119 loc) · 4.38 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
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
var chai = require('chai');
var sinon = require('sinon');
var expect = chai.expect;
var should = chai.should();
var superagent = require('superagent');
var status = require('http-status');
var app = require("../../server/server.js");
var utils = require('../../common/helpers/utils.js');
describe('/API', function() {
beforeEach(function(done) {
server = app.listen(done);
});
afterEach(function(done) {
server.close(done);
});
it('/Users/signup', function(done) {
superagent
.post('http://localhost:3000/api/Users/signup')
.end(function(err, res) {
expect(err).to.be.instanceof(Error);
expect(res.status).to.equal(status.UNPROCESSABLE_ENTITY);
expect(res.body.error.message.toString()).to.equal("User instance is not valid");
done();
});
});
var tempUserName = utils.randomString(6);
console.log(tempUserName);
it('/Users/signup should return error if User Object don\'t have page property', function(done) {
var sampleUserData = {
"email": tempUserName + '@mailinator.com',
"password": "123"
};
superagent
.post('http://localhost:3000/api/Users/signup')
.send(sampleUserData)
.set('Content-Type', 'application/json')
.end(function(err, res) {
expect(err).to.be.instanceof(Error);
expect(res.status).to.equal(status.UNPROCESSABLE_ENTITY);
expect(res.body.error.message.toString()).to.equal("Page instance is not valid");
done();
});
});
it("api/Users/signup should return error if User Object don't have email property", function(done) {
var sampleUserData ={}
superagent
.post('http://localhost:3000/api/Users/signup')
.send(sampleUserData)
.set('Content-Type', 'application/json')
.end(function(err, res) {
expect(err).to.be.instanceof(Error);
expect(res.status).to.equal(status.UNPROCESSABLE_ENTITY);
expect(res.body.error.message.toString()).to.equal("Email is not valid");
done();
});
});
it("api/Users/signup should return error if User Object don't have email property", function(done) {
var sampleUserData = {
"password": "123",
"page": {}
}
superagent
.post('http://localhost:3000/api/Users/signup')
.send(sampleUserData)
.set('Content-Type', 'application/json')
.end(function(err, res) {
expect(err).to.be.instanceof(Error);
expect(res.status).to.equal(status.UNPROCESSABLE_ENTITY);
expect(res.body.error.message.toString()).to.equal("Email is not valid");
done();
});
});
it("api/Users/signup should return error if User Object don't have Password property", function(done) {
var sampleUserData = {
"email": tempUserName + '@mailinator.com',
"page": {}
}
superagent
.post('http://localhost:3000/api/Users/signup')
.send(sampleUserData)
.set('Content-Type', 'application/json')
.end(function(err, res) {
expect(err).to.be.instanceof(Error);
expect(res.status).to.equal(status.UNPROCESSABLE_ENTITY);
expect(res.body.error.message.toString()).to.equal("Password can't be blank");
done();
});
});
it('/Users/signup should register a user succesfully', function(done) {
this.timeout(15000);
var sampleUserData = {
"email": tempUserName + '@mailinator.com',
"password": "123",
"page": {}
}
superagent
.post('http://localhost:3000/api/Users/signup')
.send(sampleUserData)
.set('Content-Type', 'application/json')
.end(function(err, res) {
expect(err).to.equal(null);
expect(res.status).to.equal(status.OK);
done();
});
});
it('/Users/signup should return a status 200 and message "User already register" if user already register', function(done) {
this.timeout(15000);
var sampleUserData = {}
superagent
.post('http://localhost:3000/api/Users/signup')
.send(sampleUserData)
.set('Content-Type', 'application/json')
.end(function(err, res) {
expect(err).to.be.instanceof(Error);
expect(res.status).to.equal(status.UNPROCESSABLE_ENTITY);
done();
});
});
});