"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var middleware_1 = require("src/validate/middleware");
var consts_1 = require("src/consts");
var consts_2 = require("../consts");
describe('validate/middleware', function () {
    it('createValidateMiddle ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var hooks, next, middleware;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    hooks = jest.fn();
                    next = jest.fn();
                    middleware = middleware_1.createValidateMiddle(hooks);
                    return [4 /*yield*/, middleware(consts_2.Request, consts_2.Response, next)];
                case 1:
                    _a.sent();
                    expect(hooks).toBeCalledWith(consts_2.Request, consts_2.Response, {
                        basePath: consts_2.Request.headers[consts_1.X_SM_BASEPATH],
                        path: consts_2.Request.headers[consts_1.X_SM_PATH]
                    });
                    expect(next).toBeCalled();
                    return [2 /*return*/];
            }
        });
    }); });
    it('requestMiddleware/json ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var req;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    req = consts_2.mockRequest({ 'content-type': 'application/json' });
                    return [4 /*yield*/, middleware_1.requestMiddleware(req, consts_2.Response)];
                case 1:
                    _a.sent();
                    expect(req[consts_1.X_SM_PARAMS].data).toMatchObject(consts_2.testJSON);
                    expect(req[consts_1.X_SM_PARAMS].body).toMatchObject(consts_2.testJSON);
                    return [2 /*return*/];
            }
        });
    }); });
    it('requestMiddleware/form ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var req;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    req = consts_2.mockRequest({ 'content-type': 'application/x-www-form-urlencoded' });
                    return [4 /*yield*/, middleware_1.requestMiddleware(req, consts_2.Response)];
                case 1:
                    _a.sent();
                    expect(req[consts_1.X_SM_PARAMS].form).toMatchObject(consts_2.testJSON);
                    expect(req[consts_1.X_SM_PARAMS].body).toMatchObject(consts_2.testJSON);
                    return [2 /*return*/];
            }
        });
    }); });
    it('requestMiddleware/json ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var hooks, middleware, res, swagger, data;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    hooks = jest.fn();
                    middleware = middleware_1.responseHooksFactory(hooks);
                    res = consts_2.mockRequest({ 'content-type': 'application/json' });
                    swagger = {
                        basePath: '/test/api',
                        path: 'test'
                    };
                    return [4 /*yield*/, middleware(consts_2.Request, res, swagger)];
                case 1:
                    _a.sent();
                    data = {
                        code: 0,
                        message: '',
                        result: {
                            req: consts_2.Request,
                            res: res,
                            send: undefined,
                            receive: {
                                body: consts_2.testJSON,
                                status: 200
                            },
                            swagger: swagger
                        }
                    };
                    expect(hooks).toBeCalledWith(data);
                    return [2 /*return*/];
            }
        });
    }); });
});
//# sourceMappingURL=middleware.test.js.map