mailboxdb: merge into mail.js
This commit is contained in:
@@ -6,8 +6,10 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('./common.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
expect = require('expect.js'),
|
||||
mail = require('../mail.js');
|
||||
mail = require('../mail.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
describe('Mail', function () {
|
||||
const { setup, cleanup, domain, auditSource } = common;
|
||||
@@ -15,7 +17,7 @@ describe('Mail', function () {
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
describe('values', function () {
|
||||
describe('settings', function () {
|
||||
it('can get default', async function () {
|
||||
const mailConfig = await mail.getDomain(domain.domain);
|
||||
expect(mailConfig.enabled).to.be(false);
|
||||
@@ -70,4 +72,109 @@ describe('Mail', function () {
|
||||
expect(mailConfig.enabled).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mailboxes', function () {
|
||||
it('add user mailbox succeeds', async function () {
|
||||
await mail.addMailbox('girish', domain.domain, { ownerId: 'uid-0', ownerType: mail.OWNERTYPE_USER, active: true }, auditSource);
|
||||
});
|
||||
|
||||
it('cannot add dup entry', async function () {
|
||||
const [error] = await safe(mail.addMailbox('girish', domain.domain, { ownerId: 'uid-1', ownerType: mail.OWNERTYPE_GROUP, active: true }, auditSource));
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
});
|
||||
|
||||
it('add app mailbox succeeds', async function () {
|
||||
await mail.addMailbox('support', domain.domain, { ownerId: 'osticket', ownerType: 'user', active: true}, auditSource);
|
||||
});
|
||||
|
||||
it('get succeeds', async function () {
|
||||
const mailbox = await mail.getMailbox('support', domain.domain);
|
||||
expect(mailbox.name).to.equal('support');
|
||||
expect(mailbox.ownerId).to.equal('osticket');
|
||||
expect(mailbox.domain).to.equal(domain.domain);
|
||||
expect(mailbox.creationTime).to.be.a(Date);
|
||||
});
|
||||
|
||||
it('get non-existent mailbox', async function () {
|
||||
const mailbox = await mail.getMailbox('random', domain.domain);
|
||||
expect(mailbox).to.be(null);
|
||||
});
|
||||
|
||||
it('list mailboxes succeeds', async function () {
|
||||
const mailboxes = await mail.listMailboxes(domain.domain, null /* search */, 1, 10);
|
||||
expect(mailboxes.length).to.be(2);
|
||||
expect(mailboxes[0].name).to.be('girish');
|
||||
expect(mailboxes[1].name).to.be('support');
|
||||
});
|
||||
|
||||
it('list all mailboxes succeeds', async function () {
|
||||
const mailboxes = await mail.listAllMailboxes(1, 10);
|
||||
expect(mailboxes.length).to.be(2);
|
||||
expect(mailboxes[0].name).to.be('girish');
|
||||
expect(mailboxes[0].domain).to.be(domain.domain);
|
||||
expect(mailboxes[1].name).to.be('support');
|
||||
expect(mailboxes[1].domain).to.be(domain.domain);
|
||||
});
|
||||
|
||||
it('mailbox count succeeds', async function () {
|
||||
const count = await mail.getMailboxCount(domain.domain);
|
||||
expect(count).to.be(2);
|
||||
});
|
||||
|
||||
it('can set alias', async function () {
|
||||
await mail.setAliases('support', domain.domain, [ { name: 'support2', domain: domain.domain }, { name: 'help', domain: domain.domain } ]);
|
||||
});
|
||||
|
||||
it('can get aliases of name', async function () {
|
||||
const results = await mail.getAliases('support', domain.domain);
|
||||
expect(results.length).to.be(2);
|
||||
expect(results[0].name).to.be('help');
|
||||
expect(results[0].domain).to.be(domain.domain);
|
||||
expect(results[1].name).to.be('support2');
|
||||
expect(results[1].domain).to.be(domain.domain);
|
||||
});
|
||||
|
||||
it('unset aliases', async function () {
|
||||
await mail.setAliases('support', domain.domain, []);
|
||||
|
||||
const results = await mail.getAliases('support', domain.domain);
|
||||
expect(results.length).to.be(0);
|
||||
});
|
||||
|
||||
it('add list succeeds', async function () {
|
||||
await mail.addList('people', domain.domain, { members: [ 'test@cloudron.io' ], membersOnly: false, active: true }, auditSource);
|
||||
});
|
||||
|
||||
it('cannot add dup list', async function () {
|
||||
const [error] = await safe(mail.addList('people', domain.domain, { members: [ 'admin@cloudron.io' ], membersOnly: false, active: true }, auditSource));
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
});
|
||||
|
||||
it('cannot get non-existing list', async function () {
|
||||
const result = await mail.getList('random', domain.domain);
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
it('del list succeeds', async function () {
|
||||
await mail.delList('people', domain.domain, auditSource);
|
||||
const result = await mail.getList('people', domain.domain);
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
it('del non-existent list fails', async function () {
|
||||
const [error] = await safe(mail.delList('people', domain.domain, auditSource));
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
it('del mailbox succeeds', async function () {
|
||||
await mail.delMailbox('girish', domain.domain, {/*options*/}, auditSource);
|
||||
const result = await mail.getMailbox('girish', domain.domain);
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
it('del non-existent mailbox fails', async function () {
|
||||
const [error] = await safe(mail.delMailbox('girish', domain.domain, {/*options*/}, auditSource));
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user