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