"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/* eslint-disable @typescript-eslint/camelcase */
var guard_1 = require("src/guard");
var url = '/api/v1/persons';
var url1 = '/api/v1/interviewer/persons';
var url2 = '/api/v1/interviewer/{user-name}';
function getSwagger() {
    var _a;
    return {
        basePath: '/',
        paths: (_a = {},
            _a[url1] = {
                get: {
                    operationId: 'personsUsingGET',
                    parameters: [],
                    responses: {
                        '200': {
                            description: 'OK'
                        }
                    },
                    deprecated: false
                }
            },
            _a[url] = {
                get: {
                    operationId: 'personsUsingGET_1',
                    parameters: [],
                    responses: {
                        '200': {
                            description: 'OK'
                        }
                    },
                    deprecated: false
                }
            },
            _a[url2] = {
                get: {
                    operationId: 'personsUsingGET_2',
                    parameters: [],
                    responses: {
                        '200': {
                            description: 'OK'
                        }
                    },
                    deprecated: false
                }
            },
            _a)
    };
}
var optionIdMethodUrlIncrementMap = {
    methodUrl2OperationIdMap: {
        'get /api/v1/persons': 'personsUsingGET',
        'get /api/v1/interviewer/persons': 'personsUsingGET_1'
    }
};
var optionIdMethodUrlSafeModeDuplicateMap = {
    mode: 'safe',
    methodUrl2OperationIdMap: {
        'get /api/v1/persons': 'personsUsingGET',
        'get /api/v1/interviewer/persons': 'personsUsingGET',
        'get /api/v1/interviewer/{user-name}': 'v1InterviewerUserNameUsingGet'
    }
};
var optionIdMethodUrlMap = {
    methodUrl2OperationIdMap: {
        'get /api/v1/persons': 'personsUsingGET',
        'get /api/v1/interviewer/persons': 'personsUsingGET_1',
        'get /api/v1/interviewer/{user-name}': 'personsUsingGET_2'
    }
};
var optionIdMethodUrlMap2 = {
    methodUrl2OperationIdMap: {
        'get /api/v1/interviewer/persons': 'personsUsingGET',
        'get /api/v1/persons': 'personsUsingGET_1',
        'get /api/v1/interviewer/{user-name}': 'personsUsingGET_2'
    }
};
describe('guard', function () {
    it('operationIdGuard should work ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var swagger, res;
        var _a, _b;
        return tslib_1.__generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    swagger = getSwagger();
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, {})];
                case 1:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('1 error');
                    expect(swagger).toMatchSnapshot('1 error');
                    swagger = getSwagger();
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, optionIdMethodUrlMap)];
                case 2:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('2 autofix');
                    expect(swagger).toMatchSnapshot('2 autofix');
                    swagger = getSwagger();
                    swagger.paths = {};
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, optionIdMethodUrlMap)];
                case 3:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('3 remove error');
                    expect(swagger).toMatchSnapshot('3 remove error');
                    swagger = getSwagger();
                    swagger.paths = (_a = {},
                        _a[url1] = swagger.paths[url1],
                        _a);
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, optionIdMethodUrlMap)];
                case 4:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('4 partial remove error');
                    expect(swagger).toMatchSnapshot('4 partial remove error');
                    swagger = getSwagger();
                    swagger.paths = (_b = {},
                        _b[url1] = swagger.paths[url1],
                        _b);
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, optionIdMethodUrlMap2)];
                case 5:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('5 partial remove ok');
                    expect(swagger).toMatchSnapshot('5 partial remove ok');
                    return [2 /*return*/];
            }
        });
    }); });
    it('operationIdGuard increment should work ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var swagger, res;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    swagger = getSwagger();
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, optionIdMethodUrlIncrementMap)];
                case 1:
                    res = _a.sent();
                    expect(res).toMatchSnapshot();
                    expect(swagger).toMatchSnapshot();
                    return [2 /*return*/];
            }
        });
    }); });
    it('operationIdGuard duplicate map should throw errors', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var swagger, res;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    swagger = getSwagger();
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, optionIdMethodUrlSafeModeDuplicateMap)];
                case 1:
                    res = _a.sent();
                    expect(res).toMatchSnapshot();
                    expect(swagger).toMatchSnapshot();
                    return [2 /*return*/];
            }
        });
    }); });
    it('operationIdGuard safe mode should work ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var swagger, res;
        var _a, _b;
        return tslib_1.__generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    swagger = getSwagger();
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, { mode: 'safe' })];
                case 1:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('1 error');
                    expect(swagger).toMatchSnapshot('1 error');
                    swagger = getSwagger();
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'safe' }))];
                case 2:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('2 autofix');
                    expect(swagger).toMatchSnapshot('2 autofix');
                    swagger = getSwagger();
                    swagger.paths = {};
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'safe' }))];
                case 3:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('3 remove error');
                    expect(swagger).toMatchSnapshot('3 remove error');
                    swagger = getSwagger();
                    swagger.paths = (_a = {},
                        _a[url1] = swagger.paths[url1],
                        _a);
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'safe' }))];
                case 4:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('4 partial remove error');
                    expect(swagger).toMatchSnapshot('4 partial remove error');
                    swagger = getSwagger();
                    swagger.paths = (_b = {},
                        _b[url1] = swagger.paths[url1],
                        _b);
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'safe' }))];
                case 5:
                    res = _c.sent();
                    expect(res).toMatchSnapshot('5 partial remove ok');
                    expect(swagger).toMatchSnapshot('5 partial remove ok');
                    return [2 /*return*/];
            }
        });
    }); });
    it('operationIdGuard strict mode should work ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var swagger, res;
        var _a, _b, _c;
        return tslib_1.__generator(this, function (_d) {
            switch (_d.label) {
                case 0:
                    swagger = getSwagger();
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, { mode: 'safe' })];
                case 1:
                    res = _d.sent();
                    expect(res).toMatchSnapshot('1 error');
                    expect(swagger).toMatchSnapshot('1 error');
                    swagger = getSwagger();
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'strict' }))];
                case 2:
                    res = _d.sent();
                    expect(res).toMatchSnapshot('2 autofix');
                    expect(swagger).toMatchSnapshot('2 autofix');
                    swagger = getSwagger();
                    swagger.paths = {};
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'strict' }))];
                case 3:
                    res = _d.sent();
                    expect(res).toMatchSnapshot('3 remove error');
                    expect(swagger).toMatchSnapshot('3 remove error');
                    swagger = getSwagger();
                    swagger.paths = (_a = {},
                        _a[url1] = swagger.paths[url1],
                        _a);
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'strict' }))];
                case 4:
                    res = _d.sent();
                    expect(res).toMatchSnapshot('4 partial remove error');
                    expect(swagger).toMatchSnapshot('4 partial remove error');
                    swagger = getSwagger();
                    swagger.paths = (_b = {},
                        _b[url1] = swagger.paths[url1],
                        _b);
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'strict' }))];
                case 5:
                    res = _d.sent();
                    expect(res).toMatchSnapshot('5 partial remove ok');
                    expect(swagger).toMatchSnapshot('5 partial remove ok');
                    swagger = getSwagger();
                    swagger.paths = (_c = {},
                        _c[url1] = {
                            get: {
                                operationId: 'personsUsingGET',
                                parameters: [
                                    {
                                        name: 'bad arg',
                                        in: 'query',
                                        description: 'bad arg',
                                        required: false
                                    },
                                    {
                                        name: 'bad-arg',
                                        in: 'form',
                                        description: 'bad-arg',
                                        required: false
                                    },
                                    {
                                        name: 'bad坏arg',
                                        in: 'path',
                                        description: 'bad坏arg',
                                        required: false
                                    },
                                    {
                                        name: 'goodArg',
                                        in: 'path',
                                        description: 'good arg',
                                        required: false
                                    }
                                ],
                                responses: {
                                    '200': {
                                        description: 'Test'
                                    }
                                },
                                deprecated: false
                            }
                        },
                        _c);
                    return [4 /*yield*/, guard_1.operationIdGuard(swagger, tslib_1.__assign(tslib_1.__assign({}, optionIdMethodUrlMap), { mode: 'strict' }))];
                case 6:
                    res = _d.sent();
                    expect(res).toMatchSnapshot('6 params check error');
                    expect(swagger).toMatchSnapshot('6 params check error');
                    return [2 /*return*/];
            }
        });
    }); });
    it('strictModeGuard should work ok', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var swagger, info;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    swagger = getSwagger();
                    swagger.tags = [
                        {
                            name: '错误',
                            description: '这个tags不合格'
                        },
                        {
                            name: 'xxx-controller',
                            description: '这个tags不合格'
                        },
                        {
                            name: 'ok',
                            description: '这个tags合格'
                        }
                    ];
                    return [4 /*yield*/, guard_1.strictModeGuard(swagger, { mode: 'strict' })];
                case 1:
                    info = _a.sent();
                    expect(info).toMatchSnapshot('strictModeGuard');
                    return [2 /*return*/];
            }
        });
    }); });
});
//# sourceMappingURL=guard.test.js.map