"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
require("mocha");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test videos files', function () {
    let servers;
    let webtorrentId;
    let hlsId;
    let remoteId;
    let userToken;
    let moderatorToken;
    let validId1;
    let validId2;
    before(function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            this.timeout(300000);
            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;
            }
            {
                yield servers[0].config.enableTranscoding(true, true);
                {
                    const { uuid } = yield servers[0].videos.quickUpload({ name: 'both 1' });
                    validId1 = uuid;
                }
                {
                    const { uuid } = yield servers[0].videos.quickUpload({ name: 'both 2' });
                    validId2 = uuid;
                }
            }
            yield (0, server_commands_1.waitJobs)(servers);
            {
                yield servers[0].config.enableTranscoding(false, true);
                const { uuid } = yield servers[0].videos.quickUpload({ name: 'hls' });
                hlsId = uuid;
            }
            yield (0, server_commands_1.waitJobs)(servers);
            {
                yield servers[0].config.enableTranscoding(false, true);
                const { uuid } = yield servers[0].videos.quickUpload({ name: 'webtorrent' });
                webtorrentId = uuid;
            }
            yield (0, server_commands_1.waitJobs)(servers);
        });
    });
    it('Should not delete files of a unknown video', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield servers[0].videos.removeHLSFiles({ videoId: 404, expectedStatus: 404 });
            yield servers[0].videos.removeWebTorrentFiles({ videoId: 404, expectedStatus: 404 });
        });
    });
    it('Should not delete files of a remote video', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: 400 });
            yield servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: 400 });
        });
    });
    it('Should not delete files by a non admin user', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            const expectedStatus = 403;
            yield servers[0].videos.removeHLSFiles({ videoId: validId1, token: userToken, expectedStatus });
            yield servers[0].videos.removeHLSFiles({ videoId: validId1, token: moderatorToken, expectedStatus });
            yield servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: userToken, expectedStatus });
            yield servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: moderatorToken, expectedStatus });
        });
    });
    it('Should not delete files if the files are not available', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: 400 });
            yield servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: 400 });
        });
    });
    it('Should not delete files if no both versions are available', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: 400 });
            yield servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: 400 });
        });
    });
    it('Should not delete files if no both versions are available', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: 400 });
            yield servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: 400 });
        });
    });
    it('Should delete files if both versions are available', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield servers[0].videos.removeHLSFiles({ videoId: validId1 });
            yield servers[0].videos.removeWebTorrentFiles({ videoId: validId2 });
        });
    });
    after(function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)(servers);
        });
    });
});
//# sourceMappingURL=video-files.js.map