/* jslint node:true */ import mailPasswords from '../mailpasswords.js'; import BoxError from '../boxerror.js'; import common from './common.js'; import expect from 'expect.js'; import safe from 'safetydance'; /* global it:false */ /* global describe:false */ /* global before:false */ /* global after:false */ describe('Mail passwords', function () { const { setup, cleanup, admin, app } = common; before(setup); after(cleanup); it('cannot add with empty appId', async function () { const [error] = await safe(mailPasswords.add('', admin.id, 'token123')); expect(error.reason).to.be(BoxError.BAD_FIELD); }); it('cannot add with empty userId', async function () { const [error] = await safe(mailPasswords.add(app.id, '', 'token123')); expect(error.reason).to.be(BoxError.BAD_FIELD); }); it('cannot add with empty password', async function () { const [error] = await safe(mailPasswords.add(app.id, admin.id, '')); expect(error.reason).to.be(BoxError.BAD_FIELD); }); it('can add mail password', async function () { const result = await mailPasswords.add(app.id, admin.id, 'secret-token'); expect(result.appId).to.be(app.id); expect(result.userId).to.be(admin.id); }); it('can get mail password', async function () { const result = await mailPasswords.get(app.id, admin.id); expect(result).to.be.ok(); expect(result.appId).to.be(app.id); expect(result.userId).to.be(admin.id); expect(result.password).to.be('secret-token'); }); it('cannot get random mail password', async function () { const result = await mailPasswords.get('random', 'random'); expect(result).to.be(null); }); it('can list mail passwords for user', async function () { const results = await mailPasswords.list(admin.id); expect(results.length).to.be(1); expect(results[0].appId).to.be(app.id); expect(results[0].userId).to.be(admin.id); }); it('cannot add duplicate appId and userId', async function () { const [error] = await safe(mailPasswords.add(app.id, admin.id, 'another-token')); expect(error.reason).to.be(BoxError.ALREADY_EXISTS); }); it('can del mail password', async function () { await mailPasswords.del(app.id, admin.id); }); it('cannot del random mail password', async function () { const [error] = await safe(mailPasswords.del('random', 'random')); expect(error.reason).to.be(BoxError.NOT_FOUND); }); it('cannot add with non-existent appId', async function () { const [error] = await safe(mailPasswords.add('nonexistent-app-id', admin.id, 'token')); expect(error.reason).to.be(BoxError.NOT_FOUND); }); it('cannot add with non-existent userId', async function () { const [error] = await safe(mailPasswords.add(app.id, 'nonexistent-user-id', 'token')); expect(error.reason).to.be(BoxError.NOT_FOUND); }); });