"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
require("mocha");
const shared_1 = require("../../shared");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test jobs API validators', function () {
    const path = '/api/v1/jobs/failed';
    let server;
    let userAccessToken = '';
    before(function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            this.timeout(120000);
            server = yield (0, server_commands_1.createSingleServer)(1);
            yield (0, server_commands_1.setAccessTokensToServers)([server]);
            const user = {
                username: 'user1',
                password: 'my super password'
            };
            yield server.users.create({ username: user.username, password: user.password });
            userAccessToken = yield server.login.getAccessToken(user);
        });
    });
    describe('When listing jobs', function () {
        it('Should fail with a bad state', function () {
            return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeGetRequest)({
                    url: server.url,
                    token: server.accessToken,
                    path: path + 'ade'
                });
            });
        });
        it('Should fail with an incorrect job type', function () {
            return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeGetRequest)({
                    url: server.url,
                    token: server.accessToken,
                    path,
                    query: {
                        jobType: 'toto'
                    }
                });
            });
        });
        it('Should fail with a bad start pagination', function () {
            return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                yield (0, shared_1.checkBadStartPagination)(server.url, path, server.accessToken);
            });
        });
        it('Should fail with a bad count pagination', function () {
            return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                yield (0, shared_1.checkBadCountPagination)(server.url, path, server.accessToken);
            });
        });
        it('Should fail with an incorrect sort', function () {
            return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                yield (0, shared_1.checkBadSortPagination)(server.url, path, server.accessToken);
            });
        });
        it('Should fail with a non authenticated user', function () {
            return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeGetRequest)({
                    url: server.url,
                    path,
                    expectedStatus: 401
                });
            });
        });
        it('Should fail with a non admin user', function () {
            return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeGetRequest)({
                    url: server.url,
                    path,
                    token: userAccessToken,
                    expectedStatus: 403
                });
            });
        });
    });
    describe('When pausing/resuming the job queue', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            const commands = ['pause', 'resume'];
            it('Should fail with a non authenticated user', function () {
                return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                    for (const command of commands) {
                        yield (0, server_commands_1.makePostBodyRequest)({
                            url: server.url,
                            path: '/api/v1/jobs/' + command,
                            expectedStatus: 401
                        });
                    }
                });
            });
            it('Should fail with a non admin user', function () {
                return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                    for (const command of commands) {
                        yield (0, server_commands_1.makePostBodyRequest)({
                            url: server.url,
                            path: '/api/v1/jobs/' + command,
                            expectedStatus: 401
                        });
                    }
                });
            });
            it('Should succeed with the correct params', function () {
                return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
                    for (const command of commands) {
                        yield (0, server_commands_1.makePostBodyRequest)({
                            url: server.url,
                            path: '/api/v1/jobs/' + command,
                            token: server.accessToken,
                            expectedStatus: 204
                        });
                    }
                });
            });
        });
    });
    after(function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=jobs.js.map