import { IResponse, IHttpDeleteQueryCall, IHttpGetQueryCall, IHttpPatchQueryCall, IHttpPostQueryCall, IHttpPutQueryCall, IHttpQueryOptions, IHttpCancelRequestToken } from './http.models'; import { IHttpService } from './ihttp.service'; export class TestHttpService implements IHttpService { public response?: IResponse = undefined; public error?: any = undefined; constructor(config: { response?: IResponse; error?: any }) { Object.assign(this, config); } getAsync(call: IHttpGetQueryCall, options?: IHttpQueryOptions): Promise> { return this.resolveTestCall(); } postAsync( call: IHttpPostQueryCall, options?: IHttpQueryOptions ): Promise> { return this.resolveTestCall(); } putAsync(call: IHttpPutQueryCall, options?: IHttpQueryOptions): Promise> { return this.resolveTestCall(); } patchAsync( call: IHttpPatchQueryCall, options?: IHttpQueryOptions ): Promise> { return this.resolveTestCall(); } deleteAsync( call: IHttpDeleteQueryCall, options?: IHttpQueryOptions ): Promise> { return this.resolveTestCall(); } createCancelToken(): IHttpCancelRequestToken { return { cancel: () => {}, token: undefined }; } private resolveTestCall(): Promise> { const promise = new Promise>((resolve, reject) => { if (this.response) { resolve(this.response); } if (this.error) { reject(this.error); } throw Error(`Missing test data`); }); return promise; } }