import { SPHttpClient , SPHttpClientConfiguration , ISPHttpClientOptions , SPHttpClientResponse } from '@microsoft/sp-http' ; export class RequestClientMock extends SPHttpClient { public Requests : { url : string ; method : string ; options ? : ISPHttpClientOptions ; resultString : string ; } [ ] = [ ] ; public OnRequest : ( url : string , method : string , options ? : ISPHttpClientOptions ) => void ; public fetch ( url , configuration , options ) { let mockedResponse = this . Requests . filter ( req => req . method === options . method && req . url == url ) [ 0 ] ; let response ; if ( mockedResponse ) { response = new Response ( mockedResponse . resultString , { status : 200 , statusText : "Ok" } ) ; } else { response = new Response ( null , { status : 404 , statusText : "Not fount" , } ) ; } return Promise . resolve ( new SPHttpClientResponse ( response ) ) ; } public fetchRaw ( url , configuration , options ? ) { return this . fetch ( url , configuration , options ) ; } public get ( url , configuration , options ? ) { options = options || { } ; options . method = "GET" ; return this . fetch ( url , configuration , options ) ; } public post ( url , configuration , options ? ) { options = options || { } ; options . method = "POST" ; return this . fetch ( url , configuration , options ) ; } public patch ( url , configuration , options ? ) { options = options || { } ; options . method = "PATCH" ; return this . fetch ( url , configuration , options ) ; } public delete ( url , configuration , options ? ) { options = options || { } ; options . method = "DELETE" ; return this . fetch ( url , configuration , options ) ; } }