forked from strongloop/microgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththrow.policy.laptop.test.js
53 lines (45 loc) · 1.33 KB
/
throw.policy.laptop.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
// © Copyright IBM Corporation 2016,2017.
// Node module: microgateway
// LICENSE: Apache 2.0, https://www.apache.org/licenses/LICENSE-2.0
'use strict';
var supertest = require('supertest');
var mg = require('../lib/microgw');
var dsCleanupFile = require('./support/utils').dsCleanupFile;
var resetLimiterCache = require('../lib/rate-limit/util').resetLimiterCache;
describe('throw policy', function() {
var request;
before(function(done) {
process.env.CONFIG_DIR = __dirname + '/definitions/throw';
process.env.NODE_ENV = 'production';
resetLimiterCache();
mg.start(3000)
.then(function() {
request = supertest('http://localhost:3000');
})
.then(done)
.catch(function(err) {
console.error(err);
done(err);
});
});
after(function(done) {
dsCleanupFile();
mg.stop()
.then(done, done)
.catch(done);
delete process.env.CONFIG_DIR;
delete process.env.NODE_ENV;
});
it('throw-and-catch', function(done) {
request
.get('/throw/basic')
.set('X-ERROR-ID', 'foo')
.expect(200, /Caught the foo error: Throw on purpose/, done);
});
it('throw-without-catch', function(done) {
request
.get('/throw/basic')
.set('X-ERROR-ID', 'bar')
.expect(500, /{"name":"bar","message":"Throw on purpose"}/, done);
});
});