test( "given that CUBEJS_ENABLE_TLS is true, " + "should create an http server listening to PORT to redirect to https", async () => { // arrange process.env.CUBEJS_ENABLE_TLS = "true"; const server = new CubeServer(); // act await server.listen(); // assert expect(http.createServer).toHaveBeenCalledTimes(1); expect(http.createServer.mock.calls[0][0].toString()).toMatchSnapshot(); expect(server.redirector).toBe(http.__mockServer); expect(http.__mockServer.listen).toHaveBeenCalledTimes(1); expect(http.__mockServer.listen.mock.calls[0][0]).toBe(4000); } );
test("given an option object, should pass the options object to the created server instance", async () => { // arrange process.env.CUBEJS_ENABLE_TLS = "true"; let options = { key: true, cert: true }; let server = new CubeServer(); // act await server.listen(options); // assert expect(https.createServer.mock.calls[0][0]).toBe(options); // arrange process.env.CUBEJS_ENABLE_TLS = "false"; options = { key: true, cert: true }; server = new CubeServer(); // act await server.listen(options); // assert expect(http.createServer.mock.calls[1][0]).toBe(options); });
describe('Requests tests', function () { it('Should return promise', function () { http.request.mockImplementation(mockedResponse) https.request.mockImplementation(mockedResponse) const promise = req.post(httpUrl, httpOptions.headers['Content-Type'], {}, testData) expect(typeof promise).toBe('object') expect(typeof promise.then).toBe('function') expect( http.request.mock.calls[0][0] ).toEqual(httpOptions) req.post(leanUrl, httpOptions.headers['Content-Type'], testData) expect( https.request.mock.calls[0][0].port ).toEqual(httpsPort) req.post(leanUrl2, httpOptions.headers['Content-Type'], testData) expect( http.request.mock.calls[1][0].port ).toEqual(httpPort) }) it('Should be able to run https and http', () => { const promise = req.post(httpsUrl, httpsOptions.headers['Content-Type'], {}, testData) expect(typeof promise).toBe('object') }) })