diff --git a/src/appdb.js b/src/appdb.js index 61709e672..444a483d5 100644 --- a/src/appdb.js +++ b/src/appdb.js @@ -270,7 +270,6 @@ function add(id, appStoreId, manifest, location, domain, ownerId, portBindings, assert.strictEqual(typeof ownerId, 'string'); assert.strictEqual(typeof portBindings, 'object'); assert(data && typeof data === 'object'); - assert(typeof data.mailboxName === 'string' && data.mailboxName); // non-empty string assert.strictEqual(typeof callback, 'function'); portBindings = portBindings || { }; @@ -289,13 +288,13 @@ function add(id, appStoreId, manifest, location, domain, ownerId, portBindings, const env = data.env || {}; const label = data.label || null; const tagsJson = data.tags ? JSON.stringify(data.tags) : null; - const mailboxName = data.mailboxName; + const mailboxName = data.mailboxName || null; var queries = []; queries.push({ query: 'INSERT INTO apps (id, appStoreId, manifestJson, installationState, accessRestrictionJson, memoryLimit, xFrameOptions,' - + 'restoreConfigJson, sso, debugModeJson, robotsTxt, ownerId, mailboxName, label, tagsJson) ' + + + 'restoreConfigJson, sso, debugModeJson, robotsTxt, ownerId, mailboxName, label, tagsJson) ' + ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', args: [ id, appStoreId, manifestJson, installationState, accessRestrictionJson, memoryLimit, xFrameOptions, restoreConfigJson, sso, debugModeJson, robotsTxt, ownerId, mailboxName, label, tagsJson ] diff --git a/src/eventlogdb.js b/src/eventlogdb.js index 27cfff500..3fa5ef3d5 100644 --- a/src/eventlogdb.js +++ b/src/eventlogdb.js @@ -145,7 +145,7 @@ function clear(callback) { database.query('DELETE FROM eventlog', function (error) { if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error)); - callback(error); + callback(null); }); } @@ -153,19 +153,19 @@ function delByCreationTime(creationTime, callback) { assert(util.isDate(creationTime)); assert.strictEqual(typeof callback, 'function'); - // since notifications reference eventlog items, we have to clean them up as well - database.query('SELECT * FROM eventlog WHERE creationTime < ?', [ creationTime ], function (error, result) { + // remove notifications that reference the events as well + database.query('SELECT * FROM eventlog WHERE creationTime <= ?', [ creationTime ], function (error, result) { if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error)); - async.eachSeries(result, function (item, callback) { - database.query('DELETE FROM notifications WHERE eventId=?', [ item.id ], function (error) { - if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error)); + async.eachSeries(result, function (item, iteratorCallback) { + async.series([ + database.query.bind(null, 'DELETE FROM notifications WHERE eventId=?', [ item.id ]), + database.query.bind(null, 'DELETE FROM eventlog WHERE id=?', [ item.id ]) + ], iteratorCallback); + }, function (error) { + if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error)); - database.query('DELETE FROM eventlog WHERE id=?', [ item.id ], function (error) { - if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error)); - callback(); - }); - }); - }, callback); + callback(null); + }); }); } diff --git a/src/test/database-test.js b/src/test/database-test.js index 21c9376ca..342b025ed 100644 --- a/src/test/database-test.js +++ b/src/test/database-test.js @@ -250,10 +250,10 @@ describe('database', function () { }); it('update succeeds', function (done) { - notificationdb.update(NOTIFICATION_1.id, { acknowledged: true }, function (error, result) { + notificationdb.update(NOTIFICATION_1.id, { acknowledged: true }, function (error) { expect(error).to.equal(null); - notificationdb.get(result, function (error, result) { + notificationdb.get(NOTIFICATION_1.id, function (error, result) { expect(error).to.equal(null); expect(result.id).to.equal(NOTIFICATION_1.id); expect(result.title).to.equal(NOTIFICATION_1.title); @@ -299,39 +299,6 @@ describe('database', function () { done(); }); }); - - it('can upsert acked notification without eventId', function (done) { - notificationdb.update(NOTIFICATION_3.id, { acknowledged: true }, function (error, result) { - expect(error).to.equal(null); - expect(result).to.be.a('string'); - - // check message also gets updated - NOTIFICATION_3.message = 'new message'; - - notificationdb.get(NOTIFICATION_3.id, function (error, result) { - expect(error).to.equal(null); - - var oldCreationTime = result.creationTime; - - // wait to verify the creationTime update - setTimeout(function () { - notificationdb.upsert(NOTIFICATION_3, function (error, result) { - expect(error).to.equal(null); - expect(result).to.equal(NOTIFICATION_3.id); - - notificationdb.get(NOTIFICATION_3.id, function (error, result) { - expect(error).to.equal(null); - expect(result.acknowledged).to.equal(false); - expect(result.message).to.equal(NOTIFICATION_3.message); - expect(result.creationTime).to.be.greaterThan(oldCreationTime); - - done(); - }); - }); - }, 1000); - }); - }); - }); }); describe('domains', function () { @@ -454,7 +421,9 @@ describe('database', function () { env: {}, mailboxName: 'talktome', enableAutomaticUpdate: true, - dataDir: '' + dataDir: '', + tags: [], + label: null }; it('cannot delete referenced domain', function (done) { @@ -1036,7 +1005,9 @@ describe('database', function () { }, mailboxName: 'talktome', enableAutomaticUpdate: true, - dataDir: '' + dataDir: '', + tags: [], + label: null }; var APP_1 = { @@ -1067,7 +1038,9 @@ describe('database', function () { env: {}, mailboxName: 'callme', enableAutomaticUpdate: true, - dataDir: '' + dataDir: '', + tags: [], + label: null }; before(function (done) { @@ -1864,7 +1837,7 @@ describe('database', function () { }, function (error) { expect(error).to.be(null); - eventlogdb.delByCreationTime(new Date(), function (error) { + eventlogdb.delByCreationTime(new Date(Date.now() + 1000), function (error) { expect(error).to.be(null); eventlogdb.getAllPaged([], null, 1, 100, function (error, results) {