"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test transcoding API validators', function () {
    let servers;
    let userToken;
    let moderatorToken;
    let remoteId;
    let validId;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            servers = yield (0, server_commands_1.createMultipleServers)(2);
            yield (0, server_commands_1.setAccessTokensToServers)(servers);
            yield (0, server_commands_1.doubleFollow)(servers[0], servers[1]);
            userToken = yield servers[0].users.generateUserAndToken('user', 2);
            moderatorToken = yield servers[0].users.generateUserAndToken('moderator', 1);
            {
                const { uuid } = yield servers[1].videos.quickUpload({ name: 'remote video' });
                remoteId = uuid;
            }
            {
                const { uuid } = yield servers[0].videos.quickUpload({ name: 'both 1' });
                validId = uuid;
            }
            yield (0, server_commands_1.waitJobs)(servers);
            yield servers[0].config.enableTranscoding();
        });
    });
    it('Should not run transcoding of a unknown video', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield servers[0].videos.runTranscoding({ videoId: 404, transcodingType: 'hls', expectedStatus: 404 });
            yield servers[0].videos.runTranscoding({ videoId: 404, transcodingType: 'webtorrent', expectedStatus: 404 });
        });
    });
    it('Should not run transcoding of a remote video', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const expectedStatus = 400;
            yield servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'hls', expectedStatus });
            yield servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'webtorrent', expectedStatus });
        });
    });
    it('Should not run transcoding by a non admin user', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const expectedStatus = 403;
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', token: userToken, expectedStatus });
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', token: moderatorToken, expectedStatus });
        });
    });
    it('Should not run transcoding without transcoding type', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: undefined, expectedStatus: 400 });
        });
    });
    it('Should not run transcoding with an incorrect transcoding type', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const expectedStatus = 400;
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'toto', expectedStatus });
        });
    });
    it('Should not run transcoding if the instance disabled it', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const expectedStatus = 400;
            yield servers[0].config.disableTranscoding();
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', expectedStatus });
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus });
        });
    });
    it('Should run transcoding', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            yield servers[0].config.enableTranscoding();
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' });
            yield (0, server_commands_1.waitJobs)(servers);
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' });
            yield (0, server_commands_1.waitJobs)(servers);
        });
    });
    it('Should not run transcoding on a video that is already being transcoded', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' });
            const expectedStatus = 409;
            yield servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus });
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)(servers);
        });
    });
});
//# sourceMappingURL=transcoding.js.map