"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const server_commands_1 = require("../../../shared/server-commands");
describe('Test plugin altering video constants', function () {
    let server;
    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 server.plugins.install({ path: server_commands_1.PluginsCommand.getPluginTestPath('-video-constants') });
        });
    });
    it('Should have updated languages', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const languages = yield server.videos.getLanguages();
            (0, chai_1.expect)(languages['en']).to.not.exist;
            (0, chai_1.expect)(languages['fr']).to.not.exist;
            (0, chai_1.expect)(languages['al_bhed']).to.equal('Al Bhed');
            (0, chai_1.expect)(languages['al_bhed2']).to.equal('Al Bhed 2');
            (0, chai_1.expect)(languages['al_bhed3']).to.not.exist;
        });
    });
    it('Should have updated categories', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const categories = yield server.videos.getCategories();
            (0, chai_1.expect)(categories[1]).to.not.exist;
            (0, chai_1.expect)(categories[2]).to.not.exist;
            (0, chai_1.expect)(categories[42]).to.equal('Best category');
            (0, chai_1.expect)(categories[43]).to.equal('High best category');
        });
    });
    it('Should have updated licences', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const licences = yield server.videos.getLicences();
            (0, chai_1.expect)(licences[1]).to.not.exist;
            (0, chai_1.expect)(licences[7]).to.not.exist;
            (0, chai_1.expect)(licences[42]).to.equal('Best licence');
            (0, chai_1.expect)(licences[43]).to.equal('High best licence');
        });
    });
    it('Should have updated video privacies', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const privacies = yield server.videos.getPrivacies();
            (0, chai_1.expect)(privacies[1]).to.exist;
            (0, chai_1.expect)(privacies[2]).to.not.exist;
            (0, chai_1.expect)(privacies[3]).to.exist;
            (0, chai_1.expect)(privacies[4]).to.exist;
        });
    });
    it('Should have updated playlist privacies', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const playlistPrivacies = yield server.playlists.getPrivacies();
            (0, chai_1.expect)(playlistPrivacies[1]).to.exist;
            (0, chai_1.expect)(playlistPrivacies[2]).to.exist;
            (0, chai_1.expect)(playlistPrivacies[3]).to.not.exist;
        });
    });
    it('Should not be able to create a video with this privacy', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const attributes = { name: 'video', privacy: 2 };
            yield server.videos.upload({ attributes, expectedStatus: 400 });
        });
    });
    it('Should not be able to create a video with this privacy', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const attributes = { displayName: 'video playlist', privacy: 3 };
            yield server.playlists.create({ attributes, expectedStatus: 400 });
        });
    });
    it('Should be able to upload a video with these values', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' };
            const { uuid } = yield server.videos.upload({ attributes });
            const video = yield server.videos.get({ id: uuid });
            (0, chai_1.expect)(video.language.label).to.equal('Al Bhed 2');
            (0, chai_1.expect)(video.licence.label).to.equal('Best licence');
            (0, chai_1.expect)(video.category.label).to.equal('Best category');
        });
    });
    it('Should uninstall the plugin and reset languages, categories, licences and privacies', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' });
            {
                const languages = yield server.videos.getLanguages();
                (0, chai_1.expect)(languages['en']).to.equal('English');
                (0, chai_1.expect)(languages['fr']).to.equal('French');
                (0, chai_1.expect)(languages['al_bhed']).to.not.exist;
                (0, chai_1.expect)(languages['al_bhed2']).to.not.exist;
                (0, chai_1.expect)(languages['al_bhed3']).to.not.exist;
            }
            {
                const categories = yield server.videos.getCategories();
                (0, chai_1.expect)(categories[1]).to.equal('Music');
                (0, chai_1.expect)(categories[2]).to.equal('Films');
                (0, chai_1.expect)(categories[42]).to.not.exist;
                (0, chai_1.expect)(categories[43]).to.not.exist;
            }
            {
                const licences = yield server.videos.getLicences();
                (0, chai_1.expect)(licences[1]).to.equal('Attribution');
                (0, chai_1.expect)(licences[7]).to.equal('Public Domain Dedication');
                (0, chai_1.expect)(licences[42]).to.not.exist;
                (0, chai_1.expect)(licences[43]).to.not.exist;
            }
            {
                const privacies = yield server.videos.getPrivacies();
                (0, chai_1.expect)(privacies[1]).to.exist;
                (0, chai_1.expect)(privacies[2]).to.exist;
                (0, chai_1.expect)(privacies[3]).to.exist;
                (0, chai_1.expect)(privacies[4]).to.exist;
            }
            {
                const playlistPrivacies = yield server.playlists.getPrivacies();
                (0, chai_1.expect)(playlistPrivacies[1]).to.exist;
                (0, chai_1.expect)(playlistPrivacies[2]).to.exist;
                (0, chai_1.expect)(playlistPrivacies[3]).to.exist;
            }
        });
    });
    it('Should be able to reset categories', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield server.plugins.install({ path: server_commands_1.PluginsCommand.getPluginTestPath('-video-constants') });
            {
                const categories = yield server.videos.getCategories();
                (0, chai_1.expect)(categories[1]).to.not.exist;
                (0, chai_1.expect)(categories[2]).to.not.exist;
                (0, chai_1.expect)(categories[42]).to.exist;
                (0, chai_1.expect)(categories[43]).to.exist;
            }
            yield (0, server_commands_1.makeGetRequest)({
                url: server.url,
                token: server.accessToken,
                path: '/plugins/test-video-constants/router/reset-categories',
                expectedStatus: 204
            });
            {
                const categories = yield server.videos.getCategories();
                (0, chai_1.expect)(categories[1]).to.exist;
                (0, chai_1.expect)(categories[2]).to.exist;
                (0, chai_1.expect)(categories[42]).to.not.exist;
                (0, chai_1.expect)(categories[43]).to.not.exist;
            }
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=video-constants.js.map