Files
cloudron-box/src/test/mail-test.js

74 lines
2.5 KiB
JavaScript
Raw Normal View History

/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
2021-06-29 14:26:34 -07:00
const common = require('./common.js'),
expect = require('expect.js'),
2021-06-29 14:26:34 -07:00
mail = require('../mail.js');
2018-01-21 00:06:08 -08:00
describe('Mail', function () {
2021-08-13 10:41:10 -07:00
const { setup, cleanup, domain, auditSource } = common;
2021-06-29 14:26:34 -07:00
2018-01-21 00:06:08 -08:00
before(setup);
after(cleanup);
2018-01-21 00:06:08 -08:00
describe('values', function () {
2021-06-29 14:26:34 -07:00
it('can get default', async function () {
2021-08-13 10:41:10 -07:00
const mailConfig = await mail.getDomain(domain.domain);
2021-06-29 14:26:34 -07:00
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' });
});
2021-06-29 14:26:34 -07:00
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');
2021-08-13 10:41:10 -07:00
expect(result[0].domain).to.eql(domain.domain);
2021-06-29 14:26:34 -07:00
});
2021-06-29 14:26:34 -07:00
it('can set mail from validation', async function () {
2021-08-13 10:41:10 -07:00
await mail.setMailFromValidation(domain.domain, false);
2018-01-21 00:06:08 -08:00
2021-08-13 10:41:10 -07:00
const mailConfig = await mail.getDomain(domain.domain);
2021-06-29 14:26:34 -07:00
expect(mailConfig.mailFromValidation).to.be(false);
});
2021-06-29 14:26:34 -07:00
it('can set catch all address', async function () {
2021-08-13 10:41:10 -07:00
await mail.setCatchAllAddress(domain.domain, [ 'user1', 'user2' ]);
2021-06-29 14:26:34 -07:00
2021-08-13 10:41:10 -07:00
const mailConfig = await mail.getDomain(domain.domain);
2021-06-29 14:26:34 -07:00
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 };
2021-08-13 10:41:10 -07:00
await mail.setMailRelay(domain.domain, relay, { skipVerify: true });
2021-08-13 10:41:10 -07:00
const mailConfig = await mail.getDomain(domain.domain);
2021-06-29 14:26:34 -07:00
expect(mailConfig.relay).to.eql(relay);
});
2021-06-29 14:26:34 -07:00
it('can set banner', async function () {
const banner = { text: 'text', html: 'html' };
2018-01-21 00:06:08 -08:00
2021-08-13 10:41:10 -07:00
await mail.setBanner(domain.domain, banner);
2021-08-13 10:41:10 -07:00
const mailConfig = await mail.getDomain(domain.domain);
2021-06-29 14:26:34 -07:00
expect(mailConfig.banner).to.eql(banner);
});
2021-06-29 14:26:34 -07:00
it('can enable mail', async function () {
2021-08-13 10:41:10 -07:00
await mail.setMailEnabled(domain.domain, true, auditSource);
2021-08-13 10:41:10 -07:00
const mailConfig = await mail.getDomain(domain.domain);
2021-06-29 14:26:34 -07:00
expect(mailConfig.enabled).to.be(true);
});
});
});