"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerHttpAssertSteps = registerHttpAssertSteps;
const attachments_1 = require("../../reporter/attachments");
function registerHttpAssertSteps(registry) {
    registry.register("assert.httpStatus", async (ctx, step) => {
        const input = (step.with ?? {});
        const response = input.from ?? ctx.last?.apiResponse;
        if (!response) {
            throw new Error('Missing ApiResponse for op "assert.httpStatus"');
        }
        if (input.is === undefined) {
            throw new Error('Missing "is" in step.with for op "assert.httpStatus"');
        }
        if (ctx.options?.printApiLogs && ctx.reporter.attach) {
            (0, attachments_1.attachJson)(ctx, "apiResponse", response);
        }
        if (response.status !== input.is) {
            const err = new Error(`Expected HTTP status ${input.is} but got ${response.status}`);
            err.httpResponseBody = response.bodyText;
            err.httpStatus = response.status;
            err.httpExpectedStatus = input.is;
            throw err;
        }
    });
}
//# sourceMappingURL=http.step.js.map