UNPKG

@microsoft.azure/autorest.testserver

Version:
78 lines (77 loc) 3.07 kB
import { Router } from "express"; import { MockRequestHandler } from "./request-processor"; export type HttpMethod = "get" | "post" | "put" | "patch" | "delete" | "head" | "options"; export type Category = "vanilla" | "azure" | "dpg" | "optional"; export declare class MockApiRouter { router: Router; private currentCategory; private registeredRoutes; constructor(); /** * Set the category for the route definition inside of the provided function. * @param category Category. * @param callback Callback where are defined the mock routes. */ category(category: Category, callback: () => void): void; /** * Register a GET request for the provided uri. * @param uri URI to match. * @param name Name of the scenario(For coverage). * @param func Request handler. */ get(uri: string, name: string | undefined, func: MockRequestHandler): void; /** * Register a POST request for the provided uri. * @param uri URI to match. * @param name Name of the scenario(For coverage). * @param func Request handler. */ post(uri: string, name: string | undefined, func: MockRequestHandler): void; /** * Register a PUT request for the provided uri. * @param uri URI to match. * @param name Name of the scenario(For coverage). * @param func Request handler. */ put(uri: string, name: string | undefined, func: MockRequestHandler): void; /** * Register a PATCH request for the provided uri. * @param uri URI to match. * @param name Name of the scenario(For coverage). * @param func Request handler. */ patch(uri: string, name: string | undefined, func: MockRequestHandler): void; /** * Register a DELETE request for the provided uri. * @param uri URI to match. * @param name Name of the scenario(For coverage). * @param func Request handler. */ delete(uri: string, name: string | undefined, func: MockRequestHandler): void; /** * Register a Options request for the provided uri. * @param uri URI to match. * @param name Name of the scenario(For coverage). * @param func Request handler. */ options(uri: string, name: string | undefined, func: MockRequestHandler): void; /** * Register a HEAD request for the provided uri. * @param uri URI to match. * @param name Name of the scenario(For coverage). * @param func Request handler. */ head(uri: string, name: string | undefined, func: MockRequestHandler): void; /** * Register a request for the provided uri. * @param method Method to use. * @param uri URI to match. * @param name Name of the scenario(For coverage). * @param func Request handler. * * @note prefer to use the corresponding method method directly instead of `#request()`(i.e `#get(), #post()`) */ request(method: HttpMethod, uri: string, name: string | undefined, func: MockRequestHandler): void; private hasRegistration; private trackRegistration; }