forked from davt49/sei-group-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_test.js
122 lines (110 loc) · 2.88 KB
/
users_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
/* globals api, expect, describe, beforeEach, afterEach, it */
require('../spec_helper')
const User = require('../../models/user')
describe('User tests', () => {
beforeEach(done => {
User.collection.deleteMany()
done()
})
afterEach(done => {
User.collection.deleteMany()
done()
})
describe('POST /api/register', () => {
it('Should return a 201 response', done => {
api
.post('/api/register')
.set('Accept', 'application/json')
.send({
username: 'bob',
email: 'bob@gmail',
password: 'pass',
passwordConfirmation: 'pass',
image: 'imageurl',
lang: 'en',
text: 'Happy traveller, love dogs',
userType: 'traveller'
})
.expect(201, done)
})
it('should create a user', done => {
api
.post('/api/register')
.set('Accept', 'application/json')
.send({
username: 'bob',
email: 'bob@gmail',
password: 'pass',
passwordConfirmation: 'pass',
image: 'imageurl',
lang: 'en',
text: 'Happy traveller, love dogs',
userType: 'traveller'
})
.end((err, res) => {
const user = res.body
expect(user)
.to.have.property('_id')
.and.to.be.a('string')
expect(user)
.to.have.property('username')
.and.to.be.a('string')
expect(user)
.to.have.property('image')
.and.to.be.a('string')
expect(user)
.to.have.property('lang')
.and.to.be.a('string')
expect(user)
.to.have.property('text')
.and.to.be.a('string')
expect(user)
.to.have.property('userType')
.and.to.be.a('string')
done()
})
})
})
describe('POST /api/login', () => {
beforeEach(done => {
User.create({
username: 'bob',
email: 'bob@gmail',
password: 'pass',
passwordConfirmation: 'pass',
image: 'imageurl',
lang: 'en',
text: 'Happy traveller, love dogs',
userType: 'traveller'
})
.then(() => done())
.catch(done)
})
it('Should return a 200 response', done => {
api
.post('/api/login')
.set('Accept', 'application/json')
.send({
email: 'bob@gmail',
password: 'pass'
})
.expect(200, done)
})
it('Should return a 200 response', done => {
api
.post('/api/login')
.set('Accept', 'application/json')
.send({
email: 'bob@gmail',
password: 'pass'
})
.end((err, res) => {
const token = res.body
expect(token)
.to.have.property('token')
.and.to.be.a('string')
done()
})
})
})
})