/*! * Copyright (c) 2020 Ville de Montreal. All rights reserved. * Licensed under the MIT license. * See LICENSE file in the project root for full license information. */ import { IHttpClient } from './IHttpClient'; import { IHttpRequest } from './IHttpRequest'; import { IHttpResponse } from './IHttpResponse'; export interface IHttpMock { accepts: (req: Readonly) => boolean; returns: (req: IHttpRequest) => IHttpResponse; } export interface IHttpCall { req: Readonly; res?: IHttpResponse; err?: any; } /** * Fake implementation of a IHttpClient used to record and mock requests during unit tests. */ export declare class FakeHttpClient implements IHttpClient { calls: IHttpCall[]; private readonly mocks; /** * get the last issued request */ lastCall(): IHttpCall; /** * Registers a mock that can intercept specific request and return a hardcoded response * @param mock the request interceptor */ register(mock: IHttpMock): void; /** * Sends a HTTP request to a remote server * @param req the HTTP request to send to a remote server * @returns a HTTP response from the server * @throws HttpClientError when response status code is not within 200 to 299 range, * or for any other exception. */ send(req: Readonly): Promise; }