-
Notifications
You must be signed in to change notification settings - Fork 1
/
errorsTest.js
89 lines (81 loc) · 2.35 KB
/
errorsTest.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
'use strict'
const request = require('supertest')
const app = require('../../app/http/app')
const config = require('../../app/bootstrap/config')
const validate = require('./_validate')
describe('errors', () => {
const nonExistentRoute = '/sud8f6g6aqq1u2e'
it('GET should return 404 on non existing resource', (done) => {
request(app)
.get(nonExistentRoute)
.auth(config.username, config.password)
.expect(404)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) done(err)
else validate.error(res.body).then(done)
})
})
it('DELETE should return 404 on non existing resource', (done) => {
request(app)
.delete(nonExistentRoute)
.auth(config.username, config.password)
.expect(404)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) done(err)
else validate.error(res.body).then(done)
})
})
it('POST should return 404 if resource if not available', (done) => {
request(app)
.post(nonExistentRoute)
.auth(config.username, config.password)
.send({
url: 'https://yahoo.org',
status_code: 301
})
.expect(404)
.expect('Content-Type', /json/)
.end(done)
})
it('[PRECONDITION] Create a resource (needed for the next test case)', (done) => {
request(app)
.put('/lalala')
.auth(config.username, config.password)
.send({
url: 'http://example.org/qwer',
status_code: 308
})
.expect(201)
.end(done)
})
it('PUT should refuse to overwrite an existing resource', (done) => {
request(app)
.put('/lalala')
.auth(config.username, config.password)
.send({
url: 'http://example.org/1234',
status_code: 307
})
.expect(405)
.expect('Allow', 'GET, POST, DELETE')
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) done(err)
else validate.error(res.body).then(done)
})
})
it('should refuse unkown methods, such as PATCH', (done) => {
request(app)
.patch('/lalala')
.auth(config.username, config.password)
.expect(405)
.expect('Allow', 'GET, POST, PUT, DELETE')
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) done(err)
else validate.error(res.body).then(done)
})
})
})