Files
cloudron-box/src/test/mail-test.js
2021-08-13 11:34:05 -07:00

74 lines
2.5 KiB
JavaScript

/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
const common = require('./common.js'),
expect = require('expect.js'),
mail = require('../mail.js');
describe('Mail', function () {
const { setup, cleanup, domain, auditSource } = common;
before(setup);
after(cleanup);
describe('values', function () {
it('can get default', async function () {
const mailConfig = await mail.getDomain(domain.domain);
expect(mailConfig.enabled).to.be(false);
expect(mailConfig.mailFromValidation).to.be(true);
expect(mailConfig.catchAll).to.eql([]);
expect(mailConfig.relay).to.eql({ provider: 'cloudron-smtp' });
});
it('can get all domains', async function () {
const result = await mail.listDomains();
expect(result).to.be.an(Array);
expect(result[0]).to.be.an('object');
expect(result[0].domain).to.eql(domain.domain);
});
it('can set mail from validation', async function () {
await mail.setMailFromValidation(domain.domain, false);
const mailConfig = await mail.getDomain(domain.domain);
expect(mailConfig.mailFromValidation).to.be(false);
});
it('can set catch all address', async function () {
await mail.setCatchAllAddress(domain.domain, [ 'user1', 'user2' ]);
const mailConfig = await mail.getDomain(domain.domain);
expect(mailConfig.catchAll).to.eql([ 'user1', 'user2' ]);
});
it('can set mail relay', async function () {
const relay = { provider: 'external-smtp', host: 'mx.foo.com', port: 25 };
await mail.setMailRelay(domain.domain, relay, { skipVerify: true });
const mailConfig = await mail.getDomain(domain.domain);
expect(mailConfig.relay).to.eql(relay);
});
it('can set banner', async function () {
const banner = { text: 'text', html: 'html' };
await mail.setBanner(domain.domain, banner);
const mailConfig = await mail.getDomain(domain.domain);
expect(mailConfig.banner).to.eql(banner);
});
it('can enable mail', async function () {
await mail.setMailEnabled(domain.domain, true, auditSource);
const mailConfig = await mail.getDomain(domain.domain);
expect(mailConfig.enabled).to.be(true);
});
});
});