@@ -180,6 +180,21 @@ export function getRecordingLogger(messages: LoggedMessage[]): Logger {
180
180
export function mockFeatureFlagApiEndpoint (
181
181
responseStatusCode : number ,
182
182
response : { [ flagName : string ] : boolean } ,
183
+ ) {
184
+ stubFeatureFlagApiEndpoint ( ( ) => ( {
185
+ status : responseStatusCode ,
186
+ messageIfError : "some error message" ,
187
+ data : response ,
188
+ } ) ) ;
189
+ }
190
+
191
+ /** Stub the HTTP request to the feature flags enablement API endpoint. */
192
+ export function stubFeatureFlagApiEndpoint (
193
+ responseFunction : ( params : any ) => {
194
+ status : number ;
195
+ messageIfError ?: string ;
196
+ data : { [ flagName : string ] : boolean } ;
197
+ } ,
183
198
) {
184
199
// Passing an auth token is required, so we just use a dummy value
185
200
const client = github . getOctokit ( "123" ) ;
@@ -189,16 +204,23 @@ export function mockFeatureFlagApiEndpoint(
189
204
const optInSpy = requestSpy . withArgs (
190
205
"GET /repos/:owner/:repo/code-scanning/codeql-action/features" ,
191
206
) ;
192
- if ( responseStatusCode < 300 ) {
193
- optInSpy . resolves ( {
194
- status : responseStatusCode ,
195
- data : response ,
196
- headers : { } ,
197
- url : "GET /repos/:owner/:repo/code-scanning/codeql-action/features" ,
198
- } ) ;
199
- } else {
200
- optInSpy . throws ( new HTTPError ( "some error message" , responseStatusCode ) ) ;
201
- }
207
+
208
+ optInSpy . callsFake ( ( _route , params ) => {
209
+ const response = responseFunction ( params ) ;
210
+ if ( response . status < 300 ) {
211
+ return Promise . resolve ( {
212
+ status : response . status ,
213
+ data : response . data ,
214
+ headers : { } ,
215
+ url : "GET /repos/:owner/:repo/code-scanning/codeql-action/features" ,
216
+ } ) ;
217
+ } else {
218
+ throw new HTTPError (
219
+ response . messageIfError || "default stub error message" ,
220
+ response . status ,
221
+ ) ;
222
+ }
223
+ } ) ;
202
224
203
225
sinon . stub ( apiClient , "getApiClient" ) . value ( ( ) => client ) ;
204
226
}
0 commit comments