"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const shared_1 = require("../../shared");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test config defaults', function () {
    let server;
    let channelId;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(30000);
            server = yield (0, server_commands_1.createSingleServer)(1);
            yield (0, server_commands_1.setAccessTokensToServers)([server]);
            yield (0, server_commands_1.setDefaultVideoChannel)([server]);
            channelId = server.store.channel.id;
        });
    });
    describe('Default publish values', function () {
        before(function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const overrideConfig = {
                    defaults: {
                        publish: {
                            comments_enabled: false,
                            download_enabled: false,
                            privacy: 4,
                            licence: 4
                        }
                    }
                };
                yield server.kill();
                yield server.run(overrideConfig);
            });
        });
        const attributes = {
            name: 'video',
            downloadEnabled: undefined,
            commentsEnabled: undefined,
            licence: undefined,
            privacy: 1
        };
        function checkVideo(video) {
            (0, chai_1.expect)(video.downloadEnabled).to.be.false;
            (0, chai_1.expect)(video.commentsEnabled).to.be.false;
            (0, chai_1.expect)(video.licence.id).to.equal(4);
        }
        before(function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield server.config.disableTranscoding();
                yield server.config.enableImports();
                yield server.config.enableLive({ allowReplay: false, transcoding: false });
            });
        });
        it('Should have the correct server configuration', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const config = yield server.config.getConfig();
                (0, chai_1.expect)(config.defaults.publish.commentsEnabled).to.be.false;
                (0, chai_1.expect)(config.defaults.publish.downloadEnabled).to.be.false;
                (0, chai_1.expect)(config.defaults.publish.licence).to.equal(4);
                (0, chai_1.expect)(config.defaults.publish.privacy).to.equal(4);
            });
        });
        it('Should respect default values when uploading a video', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                for (const mode of ['legacy', 'resumable']) {
                    const { id } = yield server.videos.upload({ attributes, mode });
                    const video = yield server.videos.get({ id });
                    checkVideo(video);
                }
            });
        });
        it('Should respect default values when importing a video using URL', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const { video: { id } } = yield server.imports.importVideo({
                    attributes: Object.assign(Object.assign({}, attributes), { channelId, targetUrl: shared_1.FIXTURE_URLS.goodVideo })
                });
                const video = yield server.videos.get({ id });
                checkVideo(video);
            });
        });
        it('Should respect default values when importing a video using magnet URI', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const { video: { id } } = yield server.imports.importVideo({
                    attributes: Object.assign(Object.assign({}, attributes), { channelId, magnetUri: shared_1.FIXTURE_URLS.magnet })
                });
                const video = yield server.videos.get({ id });
                checkVideo(video);
            });
        });
        it('Should respect default values when creating a live', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const { id } = yield server.live.create({
                    fields: Object.assign(Object.assign({}, attributes), { channelId })
                });
                const video = yield server.videos.get({ id });
                checkVideo(video);
            });
        });
    });
    describe('Default P2P values', function () {
        describe('Webapp default value', function () {
            before(function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    const overrideConfig = {
                        defaults: {
                            p2p: {
                                webapp: {
                                    enabled: false
                                }
                            }
                        }
                    };
                    yield server.kill();
                    yield server.run(overrideConfig);
                });
            });
            it('Should have appropriate P2P config', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    const config = yield server.config.getConfig();
                    (0, chai_1.expect)(config.defaults.p2p.webapp.enabled).to.be.false;
                    (0, chai_1.expect)(config.defaults.p2p.embed.enabled).to.be.true;
                });
            });
            it('Should create a user with this default setting', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    yield server.users.create({ username: 'user_p2p_1' });
                    const userToken = yield server.login.getAccessToken('user_p2p_1');
                    const { p2pEnabled } = yield server.users.getMyInfo({ token: userToken });
                    (0, chai_1.expect)(p2pEnabled).to.be.false;
                });
            });
            it('Should register a user with this default setting', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    yield server.users.register({ username: 'user_p2p_2' });
                    const userToken = yield server.login.getAccessToken('user_p2p_2');
                    const { p2pEnabled } = yield server.users.getMyInfo({ token: userToken });
                    (0, chai_1.expect)(p2pEnabled).to.be.false;
                });
            });
        });
        describe('Embed default value', function () {
            before(function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    const overrideConfig = {
                        defaults: {
                            p2p: {
                                embed: {
                                    enabled: false
                                }
                            }
                        },
                        signup: {
                            limit: 15
                        }
                    };
                    yield server.kill();
                    yield server.run(overrideConfig);
                });
            });
            it('Should have appropriate P2P config', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    const config = yield server.config.getConfig();
                    (0, chai_1.expect)(config.defaults.p2p.webapp.enabled).to.be.true;
                    (0, chai_1.expect)(config.defaults.p2p.embed.enabled).to.be.false;
                });
            });
            it('Should create a user with this default setting', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    yield server.users.create({ username: 'user_p2p_3' });
                    const userToken = yield server.login.getAccessToken('user_p2p_3');
                    const { p2pEnabled } = yield server.users.getMyInfo({ token: userToken });
                    (0, chai_1.expect)(p2pEnabled).to.be.true;
                });
            });
            it('Should register a user with this default setting', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    yield server.users.register({ username: 'user_p2p_4' });
                    const userToken = yield server.login.getAccessToken('user_p2p_4');
                    const { p2pEnabled } = yield server.users.getMyInfo({ token: userToken });
                    (0, chai_1.expect)(p2pEnabled).to.be.true;
                });
            });
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=config-defaults.js.map