1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-28 20:02:16 -05:00

Add update script for DB version 6

This commit is contained in:
Tankred Hase 2015-04-07 17:15:38 +02:00
parent 73febe287e
commit 07e0f39b55
4 changed files with 75 additions and 3 deletions

View File

@ -42,7 +42,7 @@ appCfg.config = {
iconPath: '/img/icon-128-chrome.png',
verificationUrl: '/verify/',
verificationUuidLength: 36,
dbVersion: 5,
dbVersion: 6,
appVersion: undefined,
outboxMailboxPath: 'OUTBOX',
outboxMailboxName: 'Outbox',

View File

@ -10,7 +10,8 @@ var axe = require('axe-logger'),
updateV2 = require('./update-v2'),
updateV3 = require('./update-v3'),
updateV4 = require('./update-v4'),
updateV5 = require('./update-v5');
updateV5 = require('./update-v5'),
updateV6 = require('./update-v6');
/**
* Handles database migration
@ -18,7 +19,7 @@ var axe = require('axe-logger'),
function UpdateHandler(appConfigStore, accountStore, auth, dialog) {
this._appConfigStorage = appConfigStore;
this._userStorage = accountStore;
this._updateScripts = [updateV1, updateV2, updateV3, updateV4, updateV5];
this._updateScripts = [updateV1, updateV2, updateV3, updateV4, updateV5, updateV6];
this._auth = auth;
this._dialog = dialog;
}

View File

@ -0,0 +1,18 @@
'use strict';
/**
* Update handler for transition database version 5 -> 6
*/
function update(options) {
var emailDbType = 'email_',
versionDbType = 'dbVersion',
postUpdateDbVersion = 6;
// remove the emails
return options.userStorage.removeList(emailDbType).then(function() {
// update the database version to postUpdateDbVersion
return options.appConfigStorage.storeList([postUpdateDbVersion], versionDbType);
});
}
module.exports = update;

View File

@ -468,5 +468,58 @@ describe('UpdateHandler', function() {
});
});
});
describe('v5 -> v6', function() {
var emailDbType = 'email_';
beforeEach(function() {
cfg.dbVersion = 6; // app requires database version 6
appConfigStorageStub.listItems.withArgs(versionDbType).returns(resolves([5])); // database version is 5
});
afterEach(function() {
// database version is only queried for version checking prior to the update script
// so no need to check this in case-specific tests
expect(appConfigStorageStub.listItems.calledOnce).to.be.true;
});
it('should work', function(done) {
userStorageStub.removeList.withArgs(emailDbType).returns(resolves());
appConfigStorageStub.storeList.withArgs([6], versionDbType).returns(resolves());
updateHandler.update().then(function() {
expect(userStorageStub.removeList.calledOnce).to.be.true;
expect(appConfigStorageStub.storeList.calledOnce).to.be.true;
done();
});
});
it('should fail when persisting database version fails', function(done) {
userStorageStub.removeList.returns(resolves());
appConfigStorageStub.storeList.returns(rejects(new Error()));
updateHandler.update().catch(function(error) {
expect(error).to.exist;
expect(userStorageStub.removeList.calledOnce).to.be.true;
expect(appConfigStorageStub.storeList.calledOnce).to.be.true;
done();
});
});
it('should fail when wiping emails from database fails', function(done) {
userStorageStub.removeList.returns(rejects(new Error()));
updateHandler.update().catch(function(error) {
expect(error).to.exist;
expect(userStorageStub.removeList.calledOnce).to.be.true;
expect(appConfigStorageStub.storeList.called).to.be.false;
done();
});
});
});
});
});