test that user.del removed mailbox and aliases

This commit is contained in:
Girish Ramakrishnan
2016-09-26 00:14:03 -07:00
parent d92e99a092
commit a8d57bb036
2 changed files with 22 additions and 4 deletions

View File

@@ -887,6 +887,18 @@ describe('User', function () {
}); });
}); });
it('can set aliases', function (done) {
user.setAliases(userObject.id, [ 'everything', 'is', 'awesome' ], function (error) {
expect(error).to.be(null);
mailboxdb.getAliasesByName(USERNAME.toLowerCase(), function (error, results) {
expect(error).to.be(null);
expect(results.length).to.be(3);
done();
});
});
});
it('can remove valid user', function (done) { it('can remove valid user', function (done) {
user.remove(userObject.id, { }, function (error) { user.remove(userObject.id, { }, function (error) {
expect(error).to.be(null); expect(error).to.be(null);
@@ -894,12 +906,16 @@ describe('User', function () {
}); });
}); });
it('did delete mailbox', function (done) { it('did delete mailbox and aliases', function (done) {
mailboxdb.getMailbox(userObject.username.toLowerCase(), function (error, mailbox) { mailboxdb.getMailbox(userObject.username.toLowerCase(), function (error, mailbox) {
expect(error.reason).to.be(DatabaseError.NOT_FOUND); expect(error.reason).to.be(DatabaseError.NOT_FOUND);
mailboxdb.getAliasesByName(USERNAME.toLowerCase(), function (error, results) {
expect(error).to.be(null);
expect(results.length).to.be(0);
done(); done();
}); });
}); });
});
}); });
}); });

View File

@@ -285,7 +285,7 @@ function removeUser(userId, auditSource, callback) {
eventlog.add(eventlog.ACTION_USER_REMOVE, auditSource, { userId: userId }); eventlog.add(eventlog.ACTION_USER_REMOVE, auditSource, { userId: userId });
if (user.username) mailboxdb.delByOwnerId(user.id, callback); else callback(); asyncIf(!!user.username, mailboxdb.delByOwnerId.bind(null, user.id), callback);
mailer.userRemoved(user); mailer.userRemoved(user);
}); });
@@ -588,6 +588,8 @@ function setAliases(userId, aliases, callback) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND)); if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND));
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error)); if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
if (!user.username) return new UserError(UserError.BAD_FIELD, 'Username must be set before settings aliases');
mailboxdb.setAliasesByName(user.username, aliases, function (error) { mailboxdb.setAliasesByName(user.username, aliases, function (error) {
if (error && error.reason === DatabaseError.ALREADY_EXISTS) return callback(new UserError(UserError.ALREADY_EXISTS, error.message)); if (error && error.reason === DatabaseError.ALREADY_EXISTS) return callback(new UserError(UserError.ALREADY_EXISTS, error.message));
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND)); if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND));