-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.test.js
70 lines (63 loc) · 1.56 KB
/
api.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
const request = require('supertest-as-promised')
const {expect} = require('chai')
const db = require('APP/db')
const User = require('APP/db/models/user')
const app = require('./start')
describe('/api/users', () => {
describe('when not logged in', () => {
it('GET /:id fails 401 (Unauthorized)', () =>
request(app)
.get(`/api/users/1`)
.expect(401)
)
it('POST creates a user', () =>
request(app)
.post('/api/users')
.send({
email: '[email protected]',
password: '12345'
})
.expect(201)
)
it('POST redirects to the user it just made', () =>
request(app)
.post('/api/users')
.send({
email: '[email protected]',
password: '23456',
})
.redirects(1)
.then(res => expect(res.body).to.contain({
email: '[email protected]'
}))
)
})
})
describe('/api/products', () => {
it('GET /', () =>
request(app)
.get(`/api/products/1`)
.expect(200)
)
it('POST creates a user', () =>
request(app)
.post('/api/users')
.send({
email: '[email protected]',
password: '12345'
})
.expect(201)
)
it('POST redirects to the user it just made', () =>
request(app)
.post('/api/users')
.send({
email: '[email protected]',
password: '23456',
})
.redirects(1)
.then(res => expect(res.body).to.contain({
email: '[email protected]'
}))
)
})