1- import { RequestClient , FetchOptions } from "@pnp/common/src/netutil" ;
1+ import { SPHttpClient , SPHttpClientConfiguration , ISPHttpClientOptions , SPHttpClientResponse } from '@microsoft/sp-http' ;
22
3- export class RequestClientMock implements RequestClient {
4- public Requests : { url : string , method : string , options ?: FetchOptions , resultString : string } [ ] = [ ] ;
5- public OnRequest : ( url : string , method : string , options ?: FetchOptions ) => void ;
6- public fetch ( url : string , options ?: FetchOptions ) : Promise < Response > {
3+ export class RequestClientMock extends SPHttpClient {
4+ public Requests : { url : string , method : string , options ?: ISPHttpClientOptions , resultString : string } [ ] = [ ] ;
5+ public OnRequest : ( url : string , method : string , options ?: ISPHttpClientOptions ) => void ;
6+ public fetch ( url : string , configuration : SPHttpClientConfiguration , options : ISPHttpClientOptions ) : Promise < SPHttpClientResponse > {
77 let mockedResponse = this . Requests . filter ( req => req . method === options . method && req . url == url ) [ 0 ] ;
88 let response : Response ;
99 if ( mockedResponse ) {
@@ -18,29 +18,29 @@ export class RequestClientMock implements RequestClient {
1818 statusText : "Not fount" ,
1919 } ) ;
2020 }
21- return Promise . resolve ( response ) ;
21+ return Promise . resolve ( new SPHttpClientResponse ( response ) ) ;
2222 }
23- public fetchRaw ( url : string , options ?: FetchOptions ) : Promise < Response > {
24- return this . fetch ( url , options ) ;
23+ public fetchRaw ( url : string , configuration : SPHttpClientConfiguration , options ?: ISPHttpClientOptions ) : Promise < SPHttpClientResponse > {
24+ return this . fetch ( url , configuration , options ) ;
2525 }
26- public get ( url : string , options ?: FetchOptions ) : Promise < Response > {
26+ public get ( url : string , configuration : SPHttpClientConfiguration , options ?: ISPHttpClientOptions ) : Promise < SPHttpClientResponse > {
2727 options = options || { } ;
2828 options . method = "GET" ;
29- return this . fetch ( url , options ) ;
29+ return this . fetch ( url , configuration , options ) ;
3030 }
31- public post ( url : string , options ?: FetchOptions ) : Promise < Response > {
31+ public post ( url : string , configuration : SPHttpClientConfiguration , options ?: ISPHttpClientOptions ) : Promise < SPHttpClientResponse > {
3232 options = options || { } ;
3333 options . method = "POST" ;
34- return this . fetch ( url , options ) ;
34+ return this . fetch ( url , configuration , options ) ;
3535 }
36- public patch ( url : string , options ?: FetchOptions ) : Promise < Response > {
36+ public patch ( url : string , configuration : SPHttpClientConfiguration , options ?: ISPHttpClientOptions ) : Promise < SPHttpClientResponse > {
3737 options = options || { } ;
3838 options . method = "PATCH" ;
39- return this . fetch ( url , options ) ;
39+ return this . fetch ( url , configuration , options ) ;
4040 }
41- public delete ( url : string , options ?: FetchOptions ) : Promise < Response > {
41+ public delete ( url : string , configuration : SPHttpClientConfiguration , options ?: ISPHttpClientOptions ) : Promise < SPHttpClientResponse > {
4242 options = options || { } ;
4343 options . method = "DELETE" ;
44- return this . fetch ( url , options ) ;
44+ return this . fetch ( url , configuration , options ) ;
4545 }
46- }
46+ }
0 commit comments