UNPKG

wiremock-captain

Version:

A better way to use the WireMock simulator to test your HTTP APIs

42 lines (41 loc) 1.85 kB
"use strict"; // Copyright (c) WarnerMedia Direct, LLC. All rights reserved. Licensed under the MIT license. // See the LICENSE file for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.WireMockAPI = void 0; const WireMock_1 = require("./WireMock"); class WireMockAPI extends WireMock_1.WireMock { constructor(baseUrl, endpoint, method, features) { super(baseUrl); this.endpoint = endpoint; this.method = method; this.features = features ?? {}; } /** * Creates a new stub with desired request and response match * @param request Request object for the stub mapping * @param response Response object for the stub mapping * @param features Additional options to be used for creation of stub mapping * @returns Created wiremock stub mapping. Contains `id` which is needed to delete a mapping */ async register(request, response, features) { return await super.register({ endpoint: this.endpoint, method: this.method, ...request }, response, { ...this.features, ...features }); } /** * Creates a new default stub with desired response * @param response Response object for the stub mapping * @param features Additional options to be used for creation of stub mapping * @returns Created wiremock stub mapping. Contains `id` which is needed to delete a mapping */ async registerDefaultResponse(response, features) { return await this.register({}, response, features); } /** * Returns list of request(s) made to the WireMock API * @returns List of wiremock requests made to the endpoint with given method */ async getRequestsForAPI() { return await super.getRequestsForAPI(this.method, this.endpoint); } } exports.WireMockAPI = WireMockAPI;