Skip to content

Commit b4afaf3

Browse files
asambstackfrancisf
authored andcommitted
test: add test for status endpoint
1 parent 5f6e03b commit b4afaf3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/core/Proxy.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class Proxy {
6464
headers: request.headers,
6565
};
6666
logger.info(`${HTTPLOG} Received http request ${options}`);
67-
const url = request.url;
68-
if(url.indexOf('/ws-proxy/status') > -1){
67+
if(request.url.indexOf('/status') > -1){
6968
response.writeHead(200, {'content-type': 'application/json; charset=utf-8', 'accept': 'application/json', 'WWW-Authenticate': 'Basic realm="WS Reconnect Proxy"'});
7069
response.end(JSON.stringify({"status" : "Running"}));
7170
return;

test/core/proxy.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { expect } = require('chai');
55
const { spy } = require('sinon');
66
const { kAddNewContext } = require('../../lib/config/constants');
77
const http = require('http');
8+
const { assert } = require('console');
89

910
describe('Proxy', () => {
1011
before(() => {
@@ -26,6 +27,7 @@ describe('Proxy', () => {
2627

2728
this.response = {
2829
writeHead: spy(),
30+
end: spy()
2931
};
3032

3133
this.proxy = new Proxy();
@@ -43,6 +45,21 @@ describe('Proxy', () => {
4345
requestSpy.restore();
4446
});
4547

48+
it('should handle request', () => {
49+
const request = {
50+
pipe: spy(),
51+
url: this.upstreamUrl + 'status',
52+
headers: {
53+
'x-connection-id': 'CONNECTION_ID',
54+
},
55+
};
56+
this.proxy.requestHandler(request, this.response);
57+
expect(this.response.writeHead.calledOnce).to.be.equal(true);
58+
assert(this.response.writeHead.calledWith(200, {'content-type': 'application/json; charset=utf-8', 'accept': 'application/json', 'WWW-Authenticate': 'Basic realm="WS Reconnect Proxy"'}));
59+
expect(this.response.end.calledOnce).to.be.equal(true);
60+
assert(this.response.writeHead.calledWith(JSON.stringify({"status" : "Running"})));
61+
});
62+
4663
it('should set connection id', () => {
4764
this.proxy.connectionHandler(this.socket, this.request);
4865
expect(this.proxy.contexts.has('CONNECTION_ID')).to.be.equal(true);

0 commit comments

Comments
 (0)