Skip to content

Commit 14415a5

Browse files
committed
refactor some tests for greater readability
1 parent 62e4b75 commit 14415a5

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

Diff for: test/lib-http-proxy-passes-web-outgoing-test.js

+21-24
Original file line numberDiff line numberDiff line change
@@ -6,113 +6,110 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
66
beforeEach(function() {
77
this.req = {
88
headers: {
9-
host: "x2.com"
9+
host: "ext-auto.com"
1010
}
1111
};
1212
this.proxyRes = {
1313
statusCode: 301,
1414
headers: {
15-
location: "http://f.com/"
15+
location: "http://backend.com/"
1616
}
1717
};
18+
this.options = {
19+
target: "http://backend.com"
20+
};
1821
});
1922

2023
context('rewrites location host with hostRewrite', function() {
2124
beforeEach(function() {
22-
this.options = {
23-
hostRewrite: "x.com"
24-
};
25+
this.options.hostRewrite = "ext-manual.com";
2526
});
2627
[301, 302, 307, 308].forEach(function(code) {
2728
it('on ' + code, function() {
2829
this.proxyRes.statusCode = code;
2930
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
30-
expect(this.proxyRes.headers.location).to.eql('http://'+this.options.hostRewrite+'/');
31+
expect(this.proxyRes.headers.location).to.eql('http://ext-manual.com/');
3132
});
3233
});
3334

3435
it('not on 200', function() {
3536
this.proxyRes.statusCode = 200;
3637
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
37-
expect(this.proxyRes.headers.location).to.eql('http://f.com/');
38+
expect(this.proxyRes.headers.location).to.eql('http://backend.com/');
3839
});
3940

4041
it('not when hostRewrite is unset', function() {
4142
delete this.options.hostRewrite;
4243
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
43-
expect(this.proxyRes.headers.location).to.eql('http://f.com/');
44+
expect(this.proxyRes.headers.location).to.eql('http://backend.com/');
4445
});
4546

4647
it('takes precedence over autoRewrite', function() {
4748
this.options.autoRewrite = true;
4849
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
49-
expect(this.proxyRes.headers.location).to.eql('http://'+this.options.hostRewrite+'/');
50+
expect(this.proxyRes.headers.location).to.eql('http://ext-manual.com/');
5051
});
5152
});
5253

5354
context('rewrites location host with autoRewrite', function() {
5455
beforeEach(function() {
55-
this.options = {
56-
autoRewrite: true,
57-
};
56+
this.options.autoRewrite = true;
5857
});
5958
[301, 302, 307, 308].forEach(function(code) {
6059
it('on ' + code, function() {
6160
this.proxyRes.statusCode = code;
6261
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
63-
expect(this.proxyRes.headers.location).to.eql('http://'+this.req.headers.host+'/');
62+
expect(this.proxyRes.headers.location).to.eql('http://ext-auto.com/');
6463
});
6564
});
6665

6766
it('not on 200', function() {
6867
this.proxyRes.statusCode = 200;
6968
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
70-
expect(this.proxyRes.headers.location).to.eql('http://f.com/');
69+
expect(this.proxyRes.headers.location).to.eql('http://backend.com/');
7170
});
7271

7372
it('not when autoRewrite is unset', function() {
7473
delete this.options.autoRewrite;
7574
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
76-
expect(this.proxyRes.headers.location).to.eql('http://f.com/');
75+
expect(this.proxyRes.headers.location).to.eql('http://backend.com/');
7776
});
7877
});
7978

8079
context('rewrites location protocol with protocolRewrite', function() {
8180
beforeEach(function() {
82-
this.options = {
83-
protocolRewrite: 'https',
84-
};
81+
this.options.protocolRewrite = 'https';
8582
});
8683
[301, 302, 307, 308].forEach(function(code) {
8784
it('on ' + code, function() {
8885
this.proxyRes.statusCode = code;
8986
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
90-
expect(this.proxyRes.headers.location).to.eql('https://f.com/');
87+
expect(this.proxyRes.headers.location).to.eql('https://backend.com/');
9188
});
9289
});
9390

9491
it('not on 200', function() {
9592
this.proxyRes.statusCode = 200;
9693
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
97-
expect(this.proxyRes.headers.location).to.eql('http://f.com/');
94+
expect(this.proxyRes.headers.location).to.eql('http://backend.com/');
9895
});
9996

10097
it('not when protocolRewrite is unset', function() {
10198
delete this.options.protocolRewrite;
10299
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
103-
expect(this.proxyRes.headers.location).to.eql('http://f.com/');
100+
expect(this.proxyRes.headers.location).to.eql('http://backend.com/');
104101
});
105102

106103
it('works together with hostRewrite', function() {
107-
this.options.hostRewrite = 'x.com'
104+
this.options.hostRewrite = 'ext-manual.com'
108105
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
109-
expect(this.proxyRes.headers.location).to.eql('https://x.com/');
106+
expect(this.proxyRes.headers.location).to.eql('https://ext-manual.com/');
110107
});
111108

112109
it('works together with autoRewrite', function() {
113110
this.options.autoRewrite = true
114111
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
115-
expect(this.proxyRes.headers.location).to.eql('https://x2.com/');
112+
expect(this.proxyRes.headers.location).to.eql('https://ext-auto.com/');
116113
});
117114
});
118115
});

0 commit comments

Comments
 (0)