"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const index_1 = require("../../../../shared/server-commands/index");
function getHomepageState(server) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const config = yield server.config.getConfig();
        return config.homepage.enabled;
    });
}
describe('Test instance homepage actions', function () {
    let server;
    let command;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(30000);
            server = yield (0, index_1.createSingleServer)(1);
            yield (0, index_1.setAccessTokensToServers)([server]);
            yield (0, index_1.setDefaultChannelAvatar)(server);
            yield (0, index_1.setDefaultAccountAvatar)(server);
            command = server.customPage;
        });
    });
    it('Should not have a homepage', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const state = yield getHomepageState(server);
            (0, chai_1.expect)(state).to.be.false;
            yield command.getInstanceHomepage({ expectedStatus: 404 });
        });
    });
    it('Should set a homepage', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield command.updateInstanceHomepage({ content: '<picsou-magazine></picsou-magazine>' });
            const page = yield command.getInstanceHomepage();
            (0, chai_1.expect)(page.content).to.equal('<picsou-magazine></picsou-magazine>');
            const state = yield getHomepageState(server);
            (0, chai_1.expect)(state).to.be.true;
        });
    });
    it('Should have the same homepage after a restart', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(30000);
            yield (0, index_1.killallServers)([server]);
            yield server.run();
            const page = yield command.getInstanceHomepage();
            (0, chai_1.expect)(page.content).to.equal('<picsou-magazine></picsou-magazine>');
            const state = yield getHomepageState(server);
            (0, chai_1.expect)(state).to.be.true;
        });
    });
    it('Should empty the homepage', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield command.updateInstanceHomepage({ content: '' });
            const page = yield command.getInstanceHomepage();
            (0, chai_1.expect)(page.content).to.be.empty;
            const state = yield getHomepageState(server);
            (0, chai_1.expect)(state).to.be.false;
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, index_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=homepage.js.map