@@ -11,7 +11,7 @@ import {
11
11
} from '@azure/functions'
12
12
import proxy from '../index'
13
13
import * as ingress from './ingress'
14
- import https from 'https'
14
+ import https , { Agent } from 'https'
15
15
import { ClientRequest } from 'http'
16
16
17
17
const fp : FormPart = {
@@ -112,6 +112,15 @@ describe('Result Endpoint', function () {
112
112
const origin : string = 'https://__ingress_api__'
113
113
const search : string = '?ii=fingerprint-pro-azure%2F__azure_function_version__%2Fingress'
114
114
115
+ const mockEndpoint = ( targetUrl : string ) => {
116
+ requestSpy . mockImplementationOnce ( ( ...args ) => {
117
+ const [ url , options ] = args
118
+ expect ( url . toString ( ) ) . toBe ( targetUrl )
119
+ options . agent = new Agent ( )
120
+ return Reflect . construct ( ClientRequest , args )
121
+ } )
122
+ }
123
+
115
124
beforeAll ( ( ) => {
116
125
jest . spyOn ( ingress , 'handleIngress' )
117
126
requestSpy = jest . spyOn ( https , 'request' )
@@ -127,10 +136,7 @@ describe('Result Endpoint', function () {
127
136
128
137
test ( 'HTTP GET without suffix' , async ( ) => {
129
138
const req = mockRequestGet ( 'https://fp.domain.com' , 'fpjs/resultId' )
130
- requestSpy . mockImplementationOnce ( ( url ) => {
131
- expect ( url . toString ( ) ) . toBe ( `${ origin } /${ search } ` )
132
- return Reflect . construct ( ClientRequest , url )
133
- } )
139
+ mockEndpoint ( `${ origin } /${ search } ` )
134
140
await proxy ( mockContext ( req ) , req )
135
141
expect ( ingress . handleIngress ) . toHaveBeenCalledTimes ( 1 )
136
142
expect ( https . request ) . toHaveBeenCalledWith (
@@ -147,10 +153,7 @@ describe('Result Endpoint', function () {
147
153
148
154
test ( 'HTTP GET with suffix' , async ( ) => {
149
155
const req = mockRequestGet ( 'https://fp.domain.com' , 'fpjs/resultId/with/suffix' )
150
- requestSpy . mockImplementationOnce ( ( url ) => {
151
- expect ( url . toString ( ) ) . toBe ( `${ origin } /with/suffix${ search } ` )
152
- return Reflect . construct ( ClientRequest , url )
153
- } )
156
+ mockEndpoint ( `${ origin } /with/suffix${ search } ` )
154
157
await proxy ( mockContext ( req ) , req )
155
158
expect ( ingress . handleIngress ) . toHaveBeenCalledTimes ( 1 )
156
159
expect ( https . request ) . toHaveBeenCalledWith (
@@ -174,10 +177,7 @@ describe('Result Endpoint', function () {
174
177
175
178
test ( 'HTTP POST without suffix' , async ( ) => {
176
179
const req = mockRequestPost ( 'https://fp.domain.com' , 'fpjs/resultId' )
177
- requestSpy . mockImplementationOnce ( ( url ) => {
178
- expect ( url . toString ( ) ) . toBe ( `${ origin } /${ search } ` )
179
- return Reflect . construct ( ClientRequest , url )
180
- } )
180
+ mockEndpoint ( `${ origin } /${ search } ` )
181
181
await proxy ( mockContext ( req ) , req )
182
182
expect ( ingress . handleIngress ) . toHaveBeenCalledTimes ( 1 )
183
183
expect ( https . request ) . toHaveBeenCalledWith (
@@ -194,10 +194,7 @@ describe('Result Endpoint', function () {
194
194
195
195
test ( 'HTTP POST with suffix' , async ( ) => {
196
196
const req = mockRequestPost ( 'https://fp.domain.com' , 'fpjs/resultId/with/suffix' )
197
- requestSpy . mockImplementationOnce ( ( url ) => {
198
- expect ( url . toString ( ) ) . toBe ( `${ origin } /with/suffix${ search } ` )
199
- return Reflect . construct ( ClientRequest , url )
200
- } )
197
+ mockEndpoint ( `${ origin } /with/suffix${ search } ` )
201
198
await proxy ( mockContext ( req ) , req )
202
199
expect ( ingress . handleIngress ) . toHaveBeenCalledTimes ( 1 )
203
200
expect ( https . request ) . toHaveBeenCalledWith (
0 commit comments