"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const shared_1 = require("../../shared");
const core_utils_1 = require("../../../../shared/core-utils");
const server_commands_1 = require("../../../../shared/server-commands");
function importVideo(server) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const attributes = {
            name: 'import 2',
            privacy: 1,
            channelId: server.store.channel.id,
            targetUrl: shared_1.FIXTURE_URLS.goodVideo720
        };
        const { video: { uuid } } = yield server.imports.importVideo({ attributes });
        return uuid;
    });
}
describe('Object storage for video import', function () {
    if ((0, core_utils_1.areMockObjectStorageTestsDisabled)())
        return;
    let server;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            yield server_commands_1.ObjectStorageCommand.prepareDefaultMockBuckets();
            server = yield (0, server_commands_1.createSingleServer)(1, server_commands_1.ObjectStorageCommand.getDefaultMockConfig());
            yield (0, server_commands_1.setAccessTokensToServers)([server]);
            yield (0, server_commands_1.setDefaultVideoChannel)([server]);
            yield server.config.enableImports();
        });
    });
    describe('Without transcoding', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            before(function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    yield server.config.disableTranscoding();
                });
            });
            it('Should import a video and have sent it to object storage', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    this.timeout(120000);
                    const uuid = yield importVideo(server);
                    yield (0, server_commands_1.waitJobs)(server);
                    const video = yield server.videos.get({ id: uuid });
                    (0, chai_1.expect)(video.files).to.have.lengthOf(1);
                    (0, chai_1.expect)(video.streamingPlaylists).to.have.lengthOf(0);
                    const fileUrl = video.files[0].fileUrl;
                    (0, shared_1.expectStartWith)(fileUrl, server_commands_1.ObjectStorageCommand.getMockWebTorrentBaseUrl());
                    yield (0, server_commands_1.makeRawRequest)({ url: fileUrl, expectedStatus: 200 });
                });
            });
        });
    });
    describe('With transcoding', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            before(function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    yield server.config.enableTranscoding();
                });
            });
            it('Should import a video and have sent it to object storage', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    this.timeout(120000);
                    const uuid = yield importVideo(server);
                    yield (0, server_commands_1.waitJobs)(server);
                    const video = yield server.videos.get({ id: uuid });
                    (0, chai_1.expect)(video.files).to.have.lengthOf(5);
                    (0, chai_1.expect)(video.streamingPlaylists).to.have.lengthOf(1);
                    (0, chai_1.expect)(video.streamingPlaylists[0].files).to.have.lengthOf(5);
                    for (const file of video.files) {
                        (0, shared_1.expectStartWith)(file.fileUrl, server_commands_1.ObjectStorageCommand.getMockWebTorrentBaseUrl());
                        yield (0, server_commands_1.makeRawRequest)({ url: file.fileUrl, expectedStatus: 200 });
                    }
                    for (const file of video.streamingPlaylists[0].files) {
                        (0, shared_1.expectStartWith)(file.fileUrl, server_commands_1.ObjectStorageCommand.getMockPlaylistBaseUrl());
                        yield (0, server_commands_1.makeRawRequest)({ url: file.fileUrl, expectedStatus: 200 });
                    }
                });
            });
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.killallServers)([server]);
        });
    });
});
//# sourceMappingURL=video-imports.js.map