"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
require("mocha");
const chai = (0, tslib_1.__importStar)(require("chai"));
const shared_1 = require("../../shared");
const core_utils_1 = require("../../../../shared/core-utils");
const server_commands_1 = require("../../../../shared/server-commands");
const expect = chai.expect;
function importVideo(server) {
    return (0, 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.areObjectStorageTestsDisabled)())
        return;
    let server;
    before(function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            this.timeout(120000);
            yield server_commands_1.ObjectStorageCommand.prepareDefaultBuckets();
            server = yield (0, server_commands_1.createSingleServer)(1, server_commands_1.ObjectStorageCommand.getDefaultConfig());
            yield (0, server_commands_1.setAccessTokensToServers)([server]);
            yield (0, server_commands_1.setDefaultVideoChannel)([server]);
            yield server.config.enableImports();
        });
    });
    describe('Without transcoding', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            before(function () {
                return (0, 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 (0, 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 });
                    expect(video.files).to.have.lengthOf(1);
                    expect(video.streamingPlaylists).to.have.lengthOf(0);
                    const fileUrl = video.files[0].fileUrl;
                    (0, shared_1.expectStartWith)(fileUrl, server_commands_1.ObjectStorageCommand.getWebTorrentBaseUrl());
                    yield (0, server_commands_1.makeRawRequest)(fileUrl, 200);
                });
            });
        });
    });
    describe('With transcoding', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            before(function () {
                return (0, 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 (0, 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 });
                    expect(video.files).to.have.lengthOf(5);
                    expect(video.streamingPlaylists).to.have.lengthOf(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.getWebTorrentBaseUrl());
                        yield (0, server_commands_1.makeRawRequest)(file.fileUrl, 200);
                    }
                    for (const file of video.streamingPlaylists[0].files) {
                        (0, shared_1.expectStartWith)(file.fileUrl, server_commands_1.ObjectStorageCommand.getPlaylistBaseUrl());
                        yield (0, server_commands_1.makeRawRequest)(file.fileUrl, 200);
                    }
                });
            });
        });
    });
    after(function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield (0, server_commands_1.killallServers)([server]);
        });
    });
});
//# sourceMappingURL=video-imports.js.map