"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const shared_1 = require("../../shared");
const core_utils_1 = require("../../../../shared/core-utils");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test contact form', function () {
    let server;
    const emails = [];
    let command;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(30000);
            const port = yield shared_1.MockSmtpServer.Instance.collectEmails(emails);
            const overrideConfig = {
                smtp: {
                    hostname: '127.0.0.1',
                    port
                }
            };
            server = yield (0, server_commands_1.createSingleServer)(1, overrideConfig);
            yield (0, server_commands_1.setAccessTokensToServers)([server]);
            command = server.contactForm;
        });
    });
    it('Should send a contact form', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(10000);
            yield command.send({
                fromEmail: 'toto@example.com',
                body: 'my super message',
                subject: 'my subject',
                fromName: 'Super toto'
            });
            yield (0, server_commands_1.waitJobs)(server);
            (0, chai_1.expect)(emails).to.have.lengthOf(1);
            const email = emails[0];
            (0, chai_1.expect)(email['from'][0]['address']).equal('test-admin@127.0.0.1');
            (0, chai_1.expect)(email['replyTo'][0]['address']).equal('toto@example.com');
            (0, chai_1.expect)(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com');
            (0, chai_1.expect)(email['subject']).contains('my subject');
            (0, chai_1.expect)(email['text']).contains('my super message');
        });
    });
    it('Should not have duplicated email address in text message', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const text = emails[0]['text'];
            const matches = text.match(/toto@example.com/g);
            (0, chai_1.expect)(matches).to.have.lengthOf(1);
        });
    });
    it('Should not be able to send another contact form because of the anti spam checker', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(10000);
            yield (0, core_utils_1.wait)(1000);
            yield command.send({
                fromEmail: 'toto@example.com',
                body: 'my super message',
                subject: 'my subject',
                fromName: 'Super toto'
            });
            yield command.send({
                fromEmail: 'toto@example.com',
                body: 'my super message',
                fromName: 'Super toto',
                subject: 'my subject',
                expectedStatus: 403
            });
        });
    });
    it('Should be able to send another contact form after a while', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, core_utils_1.wait)(1000);
            yield command.send({
                fromEmail: 'toto@example.com',
                fromName: 'Super toto',
                subject: 'my subject',
                body: 'my super message'
            });
        });
    });
    it('Should not have the manage preferences link in the email', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const email = emails[0];
            (0, chai_1.expect)(email['text']).to.not.contain('Manage your notification preferences');
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            shared_1.MockSmtpServer.Instance.kill();
            yield (0, server_commands_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=contact-form.js.map