"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
require("mocha");
const chai = (0, tslib_1.__importStar)(require("chai"));
const index_1 = require("../../../../shared/server-commands/index");
const expect = chai.expect;
function getHomepageState(server) {
    return (0, 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 (0, 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]);
            command = server.customPage;
        });
    });
    it('Should not have a homepage', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            const state = yield getHomepageState(server);
            expect(state).to.be.false;
            yield command.getInstanceHomepage({ expectedStatus: 404 });
        });
    });
    it('Should set a homepage', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield command.updateInstanceHomepage({ content: '<picsou-magazine></picsou-magazine>' });
            const page = yield command.getInstanceHomepage();
            expect(page.content).to.equal('<picsou-magazine></picsou-magazine>');
            const state = yield getHomepageState(server);
            expect(state).to.be.true;
        });
    });
    it('Should have the same homepage after a restart', function () {
        return (0, 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();
            expect(page.content).to.equal('<picsou-magazine></picsou-magazine>');
            const state = yield getHomepageState(server);
            expect(state).to.be.true;
        });
    });
    it('Should empty the homepage', function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield command.updateInstanceHomepage({ content: '' });
            const page = yield command.getInstanceHomepage();
            expect(page.content).to.be.empty;
            const state = yield getHomepageState(server);
            expect(state).to.be.false;
        });
    });
    after(function () {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
            yield (0, index_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=homepage.js.map