merge maildb.js into mail.js
This commit is contained in:
@@ -2,116 +2,72 @@
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
/* global beforeEach:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
database = require('../database.js'),
|
||||
domains = require('../domains.js'),
|
||||
const common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
mail = require('../mail.js'),
|
||||
maildb = require('../maildb.js'),
|
||||
nock = require('nock'),
|
||||
settings = require('../settings.js');
|
||||
|
||||
const DOMAIN_0 = {
|
||||
domain: 'example.com',
|
||||
zoneName: 'example.com',
|
||||
provider: 'manual',
|
||||
config: {},
|
||||
fallbackCertificate: null,
|
||||
tlsConfig: { provider: 'fallback' },
|
||||
wellKnown: null
|
||||
};
|
||||
|
||||
const AUDIT_SOURCE = {
|
||||
ip: '1.2.3.4'
|
||||
};
|
||||
|
||||
function setup(done) {
|
||||
async.series([
|
||||
database.initialize,
|
||||
database._clear,
|
||||
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0, AUDIT_SOURCE),
|
||||
settings.setDashboardLocation.bind(null, DOMAIN_0.domain, 'my.' + DOMAIN_0.domain),
|
||||
], done);
|
||||
}
|
||||
|
||||
function cleanup(done) {
|
||||
async.series([
|
||||
database._clear,
|
||||
database.uninitialize
|
||||
], done);
|
||||
}
|
||||
mail = require('../mail.js');
|
||||
|
||||
describe('Mail', function () {
|
||||
const { setup, cleanup, DOMAIN, AUDIT_SOURCE } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
beforeEach(nock.cleanAll);
|
||||
|
||||
describe('values', function () {
|
||||
it('can get default', function (done) {
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
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' });
|
||||
done();
|
||||
});
|
||||
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 set mail from validation', function (done) {
|
||||
mail.setMailFromValidation(DOMAIN_0.domain, false, function (error) {
|
||||
expect(error).to.be(null);
|
||||
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailConfig.mailFromValidation).to.be(false);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
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 catch all address', function (done) {
|
||||
mail.setCatchAllAddress(DOMAIN_0.domain, [ 'user1', 'user2' ], function (error) {
|
||||
expect(error).to.be(null);
|
||||
it('can set mail from validation', async function () {
|
||||
await mail.setMailFromValidation(DOMAIN.domain, false);
|
||||
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailConfig.catchAll).to.eql([ 'user1', 'user2' ]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
expect(mailConfig.mailFromValidation).to.be(false);
|
||||
});
|
||||
|
||||
it('can set mail relay', function (done) {
|
||||
var relay = { provider: 'external-smtp', host: 'mx.foo.com', port: 25 };
|
||||
it('can set catch all address', async function () {
|
||||
await mail.setCatchAllAddress(DOMAIN.domain, [ 'user1', 'user2' ]);
|
||||
|
||||
maildb.update(DOMAIN_0.domain, { relay: relay }, function (error) { // skip the mail server verify()
|
||||
expect(error).to.be(null);
|
||||
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailConfig.relay).to.eql(relay);
|
||||
done();
|
||||
});
|
||||
});
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
expect(mailConfig.catchAll).to.eql([ 'user1', 'user2' ]);
|
||||
});
|
||||
|
||||
it('can enable mail', function (done) {
|
||||
mail.setMailEnabled(DOMAIN_0.domain, true, AUDIT_SOURCE, function (error) {
|
||||
expect(error).to.be(null);
|
||||
it('can set mail relay', async function () {
|
||||
const relay = { provider: 'external-smtp', host: 'mx.foo.com', port: 25 };
|
||||
|
||||
mail.getDomain(DOMAIN_0.domain, function (error, mailConfig) {
|
||||
expect(error).to.be(null);
|
||||
expect(mailConfig.enabled).to.be(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
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, AUDIT_SOURCE);
|
||||
|
||||
const mailConfig = await mail.getDomain(DOMAIN.domain);
|
||||
expect(mailConfig.enabled).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user