forked from forwardemail/superagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.js
More file actions
126 lines (110 loc) · 3.3 KB
/
flags.js
File metadata and controls
126 lines (110 loc) · 3.3 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
121
122
123
124
125
126
var EventEmitter = require('events').EventEmitter
, request = require('../../')
, express = require('express')
, assert = require('assert')
, app = express();
app.get('/error', function(req, res){
throw new Error('oh noes');
});
app.get('/login', function(req, res){
res.status(200).send('<form id="login"></form>');
});
app.get('/bad-request', function(req, res){
res.status(400).end();
});
app.get('/unauthorized', function(req, res){
res.status(401).end();
});
app.get('/not-acceptable', function(req, res){
res.status(406).end();
});
app.get('/no-content', function(req, res){
res.status(204).end();
});
app.listen(3004);
describe('flags', function(){
describe('with 4xx response', function(){
it('should set res.error and res.clientError', function(done){
request
.get('http://localhost:3004/notfound')
.end(function(err, res){
assert(err);
assert(!res.ok, 'response should not be ok');
assert(res.error, 'response should be an error');
assert(res.clientError, 'response should be a client error');
assert(!res.serverError, 'response should not be a server error');
done();
});
})
})
describe('with 5xx response', function(){
it('should set res.error and res.serverError', function(done){
request
.get('http://localhost:3004/error')
.end(function(err, res){
assert(err);
assert(!res.ok, 'response should not be ok');
assert(!res.notFound, 'response should not be notFound');
assert(res.error, 'response should be an error');
assert(!res.clientError, 'response should not be a client error');
assert(res.serverError, 'response should be a server error');
done();
});
})
})
describe('with 404 Not Found', function(){
it('should res.notFound', function(done){
request
.get('http://localhost:3004/notfound')
.end(function(err, res){
assert(err);
assert(res.notFound, 'response should be .notFound');
done();
});
})
})
describe('with 400 Bad Request', function(){
it('should set req.badRequest', function(done){
request
.get('http://localhost:3004/bad-request')
.end(function(err, res){
assert(err);
assert(res.badRequest, 'response should be .badRequest');
done();
});
})
})
describe('with 401 Bad Request', function(){
it('should set res.unauthorized', function(done){
request
.get('http://localhost:3004/unauthorized')
.end(function(err, res){
assert(err);
assert(res.unauthorized, 'response should be .unauthorized');
done();
});
})
})
describe('with 406 Not Acceptable', function(){
it('should set res.notAcceptable', function(done){
request
.get('http://localhost:3004/not-acceptable')
.end(function(err, res){
assert(err);
assert(res.notAcceptable, 'response should be .notAcceptable');
done();
});
})
})
describe('with 204 No Content', function(){
it('should set res.noContent', function(done){
request
.get('http://localhost:3004/no-content')
.end(function(err, res){
assert(!err);
assert(res.noContent, 'response should be .noContent');
done();
});
})
})
})