@@ -5,6 +5,7 @@ const { expect } = require('chai');
55const { spy } = require ( 'sinon' ) ;
66const { kAddNewContext } = require ( '../../lib/config/constants' ) ;
77const http = require ( 'http' ) ;
8+ const { assert } = require ( 'console' ) ;
89
910describe ( '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