"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const shared_1 = require("../../shared");
const core_utils_1 = require("../../../../shared/core-utils");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test update video privacy while transcoding', function () {
    let servers = [];
    const videoUUIDs = [];
    function runTestSuite(hlsOnly, objectStorageBaseUrl) {
        it('Should not have an error while quickly updating a private video to public after upload #1', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                this.timeout(360000);
                const attributes = {
                    name: 'quick update',
                    privacy: 3
                };
                const { uuid } = yield servers[0].videos.upload({ attributes, waitTorrentGeneration: false });
                yield servers[0].videos.update({ id: uuid, attributes: { privacy: 1 } });
                videoUUIDs.push(uuid);
                yield (0, server_commands_1.waitJobs)(servers);
                yield (0, shared_1.completeCheckHlsPlaylist)({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl });
            });
        });
        it('Should not have an error while quickly updating a private video to public after upload #2', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                {
                    const attributes = {
                        name: 'quick update 2',
                        privacy: 3
                    };
                    const { uuid } = yield servers[0].videos.upload({ attributes, waitTorrentGeneration: true });
                    yield servers[0].videos.update({ id: uuid, attributes: { privacy: 1 } });
                    videoUUIDs.push(uuid);
                    yield (0, server_commands_1.waitJobs)(servers);
                    yield (0, shared_1.completeCheckHlsPlaylist)({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl });
                }
            });
        });
        it('Should not have an error while quickly updating a private video to public after upload #3', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const attributes = {
                    name: 'quick update 3',
                    privacy: 3
                };
                const { uuid } = yield servers[0].videos.upload({ attributes, waitTorrentGeneration: true });
                yield (0, core_utils_1.wait)(1000);
                yield servers[0].videos.update({ id: uuid, attributes: { privacy: 1 } });
                videoUUIDs.push(uuid);
                yield (0, server_commands_1.waitJobs)(servers);
                yield (0, shared_1.completeCheckHlsPlaylist)({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl });
            });
        });
    }
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            const configOverride = {
                transcoding: {
                    enabled: true,
                    allow_audio_files: true,
                    hls: {
                        enabled: true
                    }
                }
            };
            servers = yield (0, server_commands_1.createMultipleServers)(2, configOverride);
            yield (0, server_commands_1.setAccessTokensToServers)(servers);
            yield (0, server_commands_1.doubleFollow)(servers[0], servers[1]);
        });
    });
    describe('With WebTorrent & HLS enabled', function () {
        runTestSuite(false);
    });
    describe('With only HLS enabled', function () {
        before(function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].config.updateCustomSubConfig({
                    newConfig: {
                        transcoding: {
                            enabled: true,
                            allowAudioFiles: true,
                            resolutions: {
                                '144p': false,
                                '240p': true,
                                '360p': true,
                                '480p': true,
                                '720p': true,
                                '1080p': true,
                                '1440p': true,
                                '2160p': true
                            },
                            hls: {
                                enabled: true
                            },
                            webtorrent: {
                                enabled: false
                            }
                        }
                    }
                });
            });
        });
        runTestSuite(true);
    });
    describe('With object storage enabled', function () {
        if ((0, core_utils_1.areMockObjectStorageTestsDisabled)())
            return;
        before(function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                this.timeout(120000);
                const configOverride = server_commands_1.ObjectStorageCommand.getDefaultMockConfig();
                yield server_commands_1.ObjectStorageCommand.prepareDefaultMockBuckets();
                yield servers[0].kill();
                yield servers[0].run(configOverride);
            });
        });
        runTestSuite(true, server_commands_1.ObjectStorageCommand.getMockPlaylistBaseUrl());
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)(servers);
        });
    });
});
//# sourceMappingURL=update-while-transcoding.js.map