()
| 12 | testWrapper(); |
| 13 | |
| 14 | function testWrapper() { |
| 15 | describe('Rule shouldInterceptHttpsReq should be working', () => { |
| 16 | let proxyServer; |
| 17 | let serverInstance; |
| 18 | |
| 19 | beforeAll(done => { |
| 20 | jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000; |
| 21 | printLog('Start server for test_rule_should_intercept_https_req_spec'); |
| 22 | |
| 23 | serverInstance = new Server(); |
| 24 | |
| 25 | proxyServer = ProxyServerUtil.proxyServerWithRule(rule, { |
| 26 | forceProxyHttps: false |
| 27 | }); |
| 28 | |
| 29 | setTimeout(() => { |
| 30 | done(); |
| 31 | }, 2000); |
| 32 | }); |
| 33 | |
| 34 | afterAll(() => { |
| 35 | serverInstance && serverInstance.close(); |
| 36 | proxyServer && proxyServer.close(); |
| 37 | printLog('Close server for test_rule_should_intercept_https_req_spec'); |
| 38 | }); |
| 39 | |
| 40 | it('Should replace the header in proxy if assertion is true', done => { |
| 41 | const url = 'https://localhost:3001/test'; |
| 42 | |
| 43 | proxyGet(url) |
| 44 | .then(proxyRes => { |
| 45 | directGet(url) |
| 46 | .then(directRes => { |
| 47 | expect(proxyRes.statusCode).toEqual(200); |
| 48 | |
| 49 | expect(directRes.statusCode).toEqual(200); |
| 50 | expect(directRes.body + '_hello_world').toEqual(proxyRes.body); |
| 51 | done(); |
| 52 | }) |
| 53 | .catch(error => { |
| 54 | console.error('error happened in direct get: ', error); |
| 55 | done.fail('error happened in direct get'); |
| 56 | }); |
| 57 | }) |
| 58 | .catch(error => { |
| 59 | console.error('error happened in proxy get: ', error); |
| 60 | done.fail('error happened in proxy get'); |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | it('Should not replace the header in proxy if assertion is false', done => { |
| 65 | const url = 'https://localhost:3002/test'; |
| 66 | proxyGet(url) |
| 67 | .then(proxyRes => { |
| 68 | expect(proxyRes.statusCode).toEqual(200); |
| 69 | |
| 70 | directGet(url) |
| 71 | .then(directRes => { |
no test coverage detected