UNPKG

@microsoft.azure/autorest.testserver

Version:
92 lines 3.64 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestExpectation = void 0; const deep_equal_1 = __importDefault(require("deep-equal")); const api_1 = require("../api"); const request_validations_1 = require("./request-validations"); /** * Class containing all the expectations that can be run on the request. */ class RequestExpectation { constructor(originalRequest) { this.originalRequest = originalRequest; } /** * Expect the raw body of the request to match the given string. * @param rawBody Raw request body. * @throws {ValidationError} if there is an error. */ rawBodyEquals(expectedRawBody) { (0, request_validations_1.validateRawBodyEquals)(this.originalRequest, expectedRawBody); } /** * Expect the body of the request to match the given object. * @param rawBody Raw request body. * @throws {ValidationError} if there is an error. */ bodyEquals(expectedRawBody) { (0, request_validations_1.validateBodyEquals)(this.originalRequest, expectedRawBody); } /** * Expect the coerced body of the request to match the given object. * @param rawBody Raw request body. * @throws {ValidationError} if there is an error. */ coercedBodyEquals(expectedRawBody) { (0, request_validations_1.validateCoercedDateBodyEquals)(this.originalRequest, expectedRawBody); } /** * Expect the body of the request to be empty. * @throws {ValidationError} if there is an error. */ bodyEmpty() { (0, request_validations_1.validateBodyEmpty)(this.originalRequest); } /** * Expect the body of the request to be not empty. * @throws {ValidationError} if there is an error. */ bodyNotEmpty() { (0, request_validations_1.validateBodyNotEmpty)(this.originalRequest); } /** * Expect the body of the request matches the XML body you expect * @param expectedRawBody Raw request XML body expressed in a string. * @throws {ValidationError} if there is an error. */ async xmlBodyEquals(expectedRawBody) { await (0, request_validations_1.validateXMLBodyEquals)(this.originalRequest, expectedRawBody); } /** * Expect the header of the request contains the expected key/value pair * @param headerName Key expected in header * @param expectedValue Values expected in header * @throws {ValidationError} if there is an error. */ containsHeader(headerName, expectedValue) { (0, request_validations_1.validateHeader)(this.originalRequest, headerName, expectedValue); } /** * Expect the query string of the request contains the expected name/value pair. * @param paramName Name of the query parameter. * @param expectedValue Value expected of the query parameter. */ containsQueryParam(paramName, expectedValue) { (0, request_validations_1.validateQueryParam)(this.originalRequest, paramName, expectedValue); } /** * Check if two requests are equal * @param actual Actual value * @param expected Expected value */ deepEqual(actual, expected, message = "Values not deep equal") { if (!(0, deep_equal_1.default)(actual, expected, { strict: true })) { throw new api_1.ValidationError(message, actual, expected); } } } exports.RequestExpectation = RequestExpectation; //# sourceMappingURL=request-expectation.js.map