Start moving db code to use BoxError as well

This commit is contained in:
Girish Ramakrishnan
2019-10-24 11:13:48 -07:00
parent ec216d9828
commit a017af41c5
30 changed files with 396 additions and 447 deletions

View File

@@ -10,6 +10,7 @@ var appdb = require('../appdb.js'),
async = require('async'),
authcodedb = require('../authcodedb.js'),
backupdb = require('../backupdb.js'),
BoxError = require('../boxerror.js'),
clientdb = require('../clientdb.js'),
database = require('../database'),
DatabaseError = require('../databaseerror.js'),
@@ -216,8 +217,8 @@ describe('database', function () {
it('cannot get by non-existing id', function (done) {
notificationdb.get('nopenothere', function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -238,8 +239,8 @@ describe('database', function () {
it('cannot update non-existing notification', function (done) {
notificationdb.update('isnotthere', { acknowledged: true }, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
done();
});
});
@@ -265,8 +266,8 @@ describe('database', function () {
expect(error).to.equal(null);
notificationdb.get(NOTIFICATION_0.id, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
@@ -276,8 +277,8 @@ describe('database', function () {
it('deletion for non-existing notification fails', function (done) {
notificationdb.del('doesnotexts', function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
done();
});
@@ -316,7 +317,7 @@ describe('database', function () {
it('cannot add same domain twice', function (done) {
domaindb.add(DOMAIN_0.domain, { zoneName: DOMAIN_0.zoneName, provider: DOMAIN_0.provider, config: DOMAIN_0.config, tlsConfig: DOMAIN_0.tlsConfig }, function (error) {
expect(error).to.be.ok();
expect(error.reason).to.be(DatabaseError.ALREADY_EXISTS);
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
done();
});
});
@@ -382,8 +383,8 @@ describe('database', function () {
it('cannot delete non-existing domain', function (done) {
domaindb.del('not.exists', function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
done();
});
@@ -423,8 +424,8 @@ describe('database', function () {
expect(error).to.be(null);
domaindb.del(DOMAIN_0.domain, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.IN_USE);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.CONFLICT);
appdb.del(APP_0.id, done);
});
@@ -436,8 +437,8 @@ describe('database', function () {
expect(error).to.be(null);
domaindb.get(DOMAIN_0.domain, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
done();
});
@@ -711,8 +712,8 @@ describe('database', function () {
it('add of same authcode fails', function (done) {
authcodedb.add(AUTHCODE_0.authCode, AUTHCODE_0.clientId, AUTHCODE_0.userId, AUTHCODE_0.expiresAt, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.ALREADY_EXISTS);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
done();
});
});
@@ -728,8 +729,8 @@ describe('database', function () {
it('get of nonexisting code fails', function (done) {
authcodedb.get(AUTHCODE_1.authCode, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -740,8 +741,8 @@ describe('database', function () {
expect(error).to.be(null);
authcodedb.get(AUTHCODE_2.authCode, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -754,8 +755,8 @@ describe('database', function () {
expect(result).to.eql(1);
authcodedb.get(AUTHCODE_2.authCode, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -771,8 +772,8 @@ describe('database', function () {
it('cannot delete previously delete record', function (done) {
authcodedb.del(AUTHCODE_0.authCode, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
@@ -816,8 +817,8 @@ describe('database', function () {
it('add of same token fails', function (done) {
tokendb.add(TOKEN_0, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.ALREADY_EXISTS);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
done();
});
});
@@ -842,8 +843,8 @@ describe('database', function () {
it('get of nonexisting token fails', function (done) {
tokendb.getByAccessToken(TOKEN_1.accessToken, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -862,8 +863,8 @@ describe('database', function () {
it('delete fails', function (done) {
tokendb.del(TOKEN_0.id + 'x', function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
@@ -897,8 +898,8 @@ describe('database', function () {
it('cannot delete previously delete record', function (done) {
tokendb.del(TOKEN_0.id, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
@@ -926,8 +927,8 @@ describe('database', function () {
expect(result).to.eql(1);
tokendb.getByAccessToken(TOKEN_2.accessToken, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -940,8 +941,8 @@ describe('database', function () {
expect(error).to.be(null);
tokendb.getByAccessToken(TOKEN_0.accessToken, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -956,8 +957,8 @@ describe('database', function () {
expect(error).to.not.be.ok();
tokendb.getByAccessToken(TOKEN_0.accessToken, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1024,8 +1025,7 @@ describe('database', function () {
dataDir: null,
tags: [],
label: null,
taskId: null,
reverseProxyConfig: {}
taskId: null
};
before(function (done) {
@@ -1078,8 +1078,8 @@ describe('database', function () {
it('add of same app fails', function (done) {
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, [], APP_0, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.ALREADY_EXISTS);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
done();
});
});
@@ -1095,8 +1095,8 @@ describe('database', function () {
it('get of nonexisting code fails', function (done) {
appdb.get(APP_1.id, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1143,8 +1143,8 @@ describe('database', function () {
it('update of nonexisting app fails', function (done) {
appdb.update(APP_1.id, { installationState: APP_1.installationState, location: APP_1.location }, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
@@ -1196,8 +1196,8 @@ describe('database', function () {
it('cannot delete previously delete record', function (done) {
appdb.del(APP_0.id, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
@@ -1264,7 +1264,7 @@ describe('database', function () {
it('getAddonConfigByName of unknown value succeeds', function (done) {
appdb.getAddonConfigByName(APP_1.id, 'addonid1', 'NOPE', function (error) {
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
@@ -1369,7 +1369,7 @@ describe('database', function () {
taskdb.del(taskId, function (error) {
expect(error).to.be(null);
taskdb.get(taskId, function (error) {
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
@@ -1408,8 +1408,8 @@ describe('database', function () {
it('add same client id fails', function (done) {
clientdb.add(CLIENT_0.id, CLIENT_0.appId, CLIENT_0.type, CLIENT_0.clientSecret, CLIENT_0.redirectURI, CLIENT_0.scope, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.ALREADY_EXISTS);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.ALREADY_EXISTS);
done();
});
});
@@ -1440,8 +1440,8 @@ describe('database', function () {
it('getByAppId fails for unknown client id', function (done) {
clientdb.getByAppId(CLIENT_0.appId + CLIENT_0.appId, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1463,8 +1463,8 @@ describe('database', function () {
expect(error).to.be(null);
clientdb.getByAppIdAndType(CLIENT_1.appId, CLIENT_1.type, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1476,8 +1476,8 @@ describe('database', function () {
expect(error).to.be(null);
clientdb.getByAppId(CLIENT_0.appId, function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1557,8 +1557,8 @@ describe('database', function () {
it('get of unknown id fails', function (done) {
backupdb.get('somerandom', function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1585,8 +1585,8 @@ describe('database', function () {
expect(result).to.not.be.ok();
backupdb.get('backup-box', function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1642,8 +1642,8 @@ describe('database', function () {
expect(result).to.not.be.ok();
backupdb.get('app_appid_123', function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1678,8 +1678,8 @@ describe('database', function () {
it('get of unknown id fails', function (done) {
eventlogdb.get('notfoundid', function (error, result) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error).to.be.a(BoxError);
expect(error.reason).to.be(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
@@ -1868,7 +1868,7 @@ describe('database', function () {
it('cannot add invalid user to group', function (done) {
groupdb.addMember(GROUP_ID_1, 'random', function (error) {
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});
@@ -1890,7 +1890,7 @@ describe('database', function () {
it('cannot delete non-existent member', function (done) {
groupdb.removeMember(GROUP_ID_1, 'random', function (error) {
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
expect(error.reason).to.be(BoxError.NOT_FOUND);
done();
});
});