forked from Azure/autorest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatetime-rfc1123.js
69 lines (61 loc) · 2.59 KB
/
datetime-rfc1123.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
var express = require('express');
var router = express.Router();
var util = require('util');
var utils = require('../util/utils');
var datetimeRfc1123 = function(coverage) {
router.put('/max', function(req, res, next) {
if (new Date(req.body).toString() === new Date('Fri, 31 Dec 9999 23:59:59 GMT').toString()) {
coverage['putDateTimeRfc1123Max']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for max datetime-rfc1123 in the req " + util.inspect(req.body));
}
});
router.put('/min', function(req, res, next) {
if (new Date(req.body).toString() === new Date('Mon, 01 Jan 0001 00:00:00 GMT').toString()) {
coverage["putDateTimeRfc1123Min"]++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for min datetime-rfc1123 in the req " + util.inspect(req.body));
}
});
router.get('/max/:case', function(req, res, next) {
var ret = '"Fri, 31 Dec 9999 23:59:59 GMT"';
if (req.params.case === 'lowercase') {
coverage["getDateTimeRfc1123MaxUtcLowercase"]++;
ret = ret.toLowerCase();
} else if (req.params.case === 'uppercase') {
coverage["getDateTimeRfc1123MaxUtcUppercase"]++;
ret = ret.toUpperCase();
} else {
utils.send400(res, next, 'Please provide a valid case for datetime-rfc1123 case ' +
'\'uppercase\', \'lowercase\' and not ' + util.inspect(req.params.case));
}
res.status(200).end(ret);
});
router.get('/min', function(req, res, next) {
coverage["getDateTimeRfc1123MinUtc"]++;
res.status(200).end('"Mon, 01 Jan 0001 00:00:00 GMT"');
});
router.get('/:scenario', function(req, res, next) {
if (req.params.scenario === 'null') {
coverage["getDateTimeRfc1123Null"]++;
res.status(200).end();
} else if (req.params.scenario === 'invalid') {
coverage["getDateTimeRfc1123Invalid"]++;
res.status(200).end('"Tue, 01 Dec 2000 00:00:0A ABC"');
} else if (req.params.scenario === 'overflow') {
coverage["getDateTimeRfc1123Overflow"]++;
res.status(200).end('"Sat, 1 Jan 10000 00:00:00 GMT"');
} else if (req.params.scenario === 'underflow') {
coverage["getDateTimeRfc1123Underflow"]++;
res.status(200).end('"Tue, 00 Jan 0000 00:00:00 GMT"');
} else {
res.status(400).send('Request path must contain a valid scenario: ' +
'"null", "invalid", "overflow", "underflow". Provided value is : ', +
util.inspect(req.params.scenario));
}
});
}
datetimeRfc1123.prototype.router = router;
module.exports = datetimeRfc1123;