Commit a3a54686 authored by Nicolas Frandeboeuf's avatar Nicolas Frandeboeuf Committed by Benjamin Bouvier

Tests migrations

parent 21b2e5af
......@@ -311,7 +311,9 @@ let migrations = [
try {
cache.banks = cache.banks || (await Bank.all());
for (let bank of cache.banks) {
await bank.destroy();
if (typeof bank.id !== 'undefined') {
await Bank.destroy(bank.id);
}
}
delete cache.banks;
return true;
......@@ -321,23 +323,12 @@ let migrations = [
}
},
async function m9(cache, userId) {
log.info('Looking for a CMB access...');
try {
let accesses = await Accesses.byBank(userId, { uuid: 'cmb' });
for (let access of accesses) {
// There is currently no other customFields, no need to update if it is defined.
if (typeof access.customFields === 'undefined') {
log.info('Found CMB access, migrating to "par" website.');
const updateCMB = () => [{ name: 'website', value: 'par' }];
await updateCustomFields(userId, access, updateCMB);
}
}
return true;
} catch (e) {
log.error(`Error while migrating CMB accesses: ${e.toString()}`);
return false;
}
async function m9() {
// This migration used to set the website custom field to 'par' for the CMB accesses.
// However this is not expected anymore, and the value should now be set to 'pro', as done
// in m19. This migration is therefore now a no-op so that m19 can do its job (it could not
// if the website custom field was already set).
return true;
},
async function m10(cache, userId) {
......
......@@ -26,6 +26,7 @@ process.on('unhandledRejection', (reason, promise) => {
let Accesses = null;
let Accounts = null;
let Alerts = null;
let Banks = null;
let Categories = null;
let Settings = null;
let Transactions = null;
......@@ -55,6 +56,7 @@ before(async function() {
Accesses = require('../../server/models/accesses');
Accounts = require('../../server/models/accounts');
Alerts = require('../../server/models/alerts');
Banks = require('../../server/models/deprecated-bank');
Categories = require('../../server/models/categories');
Settings = require('../../server/models/settings');
Transactions = require('../../server/models/transactions');
......@@ -634,6 +636,48 @@ describe('Test migration 7', () => {
});
});
describe('Test migration 8', () => {
let bankFields = {
name: 'deprecated'
};
before(async function() {
await clearDeprecatedModels(Banks);
});
it('should insert new banks in the DB', async function() {
// The banks are deprecated and therefore have no knowledge of the user's id.
await Banks.create(bankFields);
let allBanks = await Banks.all();
allBanks.length.should.equal(1);
allBanks.should.containDeep([bankFields]);
});
it('should run migration m8 correctly', async function() {
let m8 = MIGRATIONS[8];
let cache = {};
let result = await m8(cache, 0);
result.should.equal(true);
should.not.exist(cache.banks);
});
it('should have removed all the banks from the DB', async function() {
let allBanks = await Banks.all();
allBanks.length.should.equal(0);
});
});
describe('Test migration 9', () => {
// The migration is now a no-op. We only check the result to ensure the next migrations run.
it('should run migration m9 correctly', async function() {
let m9 = MIGRATIONS[9];
let cache = {};
let result = await m9(cache, 0);
result.should.equal(true);
});
});
describe('Test migration 19', async function() {
before(async function() {
await clear(Accesses);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment