async'ify avatar and apppassword code

This commit is contained in:
Girish Ramakrishnan
2021-06-25 22:11:17 -07:00
parent 31d742fa67
commit 147c8df6e3
11 changed files with 385 additions and 354 deletions

View File

@@ -0,0 +1,62 @@
/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
const appPasswords = require('../apppasswords.js'),
BoxError = require('../boxerror.js'),
common = require('./common.js'),
expect = require('expect.js'),
safe = require('safetydance');
describe('App passwords', function () {
const { setup, cleanup, ADMIN } = common;
before(setup);
after(cleanup);
let id;
it('cannot add bad app password', async function () {
const [error] = await safe(appPasswords.add(ADMIN.id, 'appid', 'x'.repeat(201)));
expect(error.reason).to.be(BoxError.BAD_FIELD);
});
it('can add app password', async function () {
const result = await appPasswords.add(ADMIN.id, 'appid', 'spark');
expect(result.id).to.be.a('string');
expect(result.password).to.be.a('string');
id = result.id;
});
it('can get app password', async function () {
const result = await appPasswords.get(id);
expect(result.hashedPassword).to.be.a('string');
expect(result.name).to.be('spark');
expect(result.identifier).to.be('appid');
});
it('cannot get random app password', async function () {
const result = await appPasswords.get('random');
expect(result).to.be(null);
});
it('can get app passwords', async function () {
const results = await appPasswords.list(ADMIN.id);
expect(results.length).to.be(1);
expect(results[0].hashedPassword).to.be.a('string');
expect(results[0].name).to.be('spark');
expect(results[0].identifier).to.be('appid');
});
it('can del app password', async function () {
await appPasswords.del(id);
});
it('cannot del random app password', async function () {
const [error] = await safe(appPasswords.del('random'));
expect(error.reason).to.be(BoxError.NOT_FOUND);
});
});