Add and fixup invite link related tests
This commit is contained in:
@@ -208,5 +208,9 @@ function clearMailQueue() {
|
||||
async function checkMails(number) {
|
||||
await delay(1000);
|
||||
expect(mailer._mailQueue.length).to.equal(number);
|
||||
const emails = mailer._mailQueue;
|
||||
clearMailQueue();
|
||||
|
||||
// return for further investigation
|
||||
return emails;
|
||||
}
|
||||
|
||||
@@ -493,11 +493,37 @@ describe('User', function () {
|
||||
describe('invite', function () {
|
||||
before(createOwner);
|
||||
|
||||
it('send invite', async function () {
|
||||
let user;
|
||||
|
||||
it('get link fails as alreayd been used', async function () {
|
||||
const [error] = await safe(users.getInviteLink(admin, auditSource));
|
||||
expect(error.reason).to.be(BoxError.BAD_STATE);
|
||||
});
|
||||
|
||||
it('can get link', async function () {
|
||||
const userId = await users.add('some@mail.com', { username: 'someoneinvited', displayName: 'some one', password: 'unsafe1234' }, auditSource);
|
||||
user = await users.get(userId);
|
||||
|
||||
const inviteLink = await users.getInviteLink(user, auditSource);
|
||||
expect(inviteLink).to.be.a('string');
|
||||
expect(inviteLink).to.contain(user.inviteToken);
|
||||
});
|
||||
|
||||
it('cannot send mail for already active user', async function () {
|
||||
const [error] = await safe(users.sendInviteEmail(admin, 'admin@mail.com', auditSource));
|
||||
expect(error.reason).to.be(BoxError.BAD_STATE);
|
||||
});
|
||||
|
||||
it('cannot send mail with empty receipient', async function () {
|
||||
const [error] = await safe(users.sendInviteEmail(user, '', auditSource));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('can send mail', async function () {
|
||||
await clearMailQueue();
|
||||
const inviteLink = await users.sendInvite(admin, {}, auditSource);
|
||||
expect(inviteLink).to.be.ok();
|
||||
await checkMails(1);
|
||||
await users.sendInviteEmail(user, 'custom@mail.com', auditSource);
|
||||
const emails = await checkMails(1);
|
||||
expect(emails[0].to).to.equal('custom@mail.com');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user