Commit 10e5c6ea authored by Nicolas Frandeboeuf's avatar Nicolas Frandeboeuf Committed by Nicolas Frandeboeuf

[tests] Test migration 5

parent 51fdd8a6
......@@ -422,6 +422,76 @@ describe('Test migration 4', () => {
});
});
describe('Test migration 5', () => {
let account = {
bank: 'fakeaccount'
};
let accountWithDate = {
bank: 'withdate',
importDate: new Date()
};
let accountWithOps = {
bank: 'withops'
};
let op1fields = {
dateImport: new Date('2015-07-31T12:00:00Z')
};
let op2fields = {
dateImport: new Date('2015-10-21T12:00:00Z')
};
before(async function() {
await clear(Accounts);
await clear(Transactions);
});
it('should insert new accounts and operations in the DB', async function() {
await Accounts.create(0, account);
await Accounts.create(0, accountWithDate);
let accWithOps = await Accounts.create(0, accountWithOps);
op1fields.accountId = accWithOps.id;
op2fields.accountId = accWithOps.id;
let allAccounts = await Accounts.all(0);
allAccounts.length.should.equal(3);
allAccounts.should.containDeep([account, accountWithDate, accountWithOps]);
await Transactions.create(0, op1fields);
await Transactions.create(0, op2fields);
let allTransactions = await Transactions.all(0);
allTransactions.length.should.equal(2);
allTransactions.should.containDeep([op1fields, op2fields]);
});
it('should run migration m5 correctly', async function() {
let m5 = MIGRATIONS[5];
let cache = {};
let result = await m5(cache, 0);
result.should.equal(true);
});
it('should have set an import date when missing', async function() {
let acc = await Accounts.byBank(0, { uuid: account.bank });
acc[0].importDate.should.Date();
});
it('should have set an import date when missing based on the oldest transaction', async function() {
let acc = await Accounts.byBank(0, { uuid: accountWithOps.bank });
acc[0].importDate.should.eql(op1fields.dateImport);
});
it('should not have modified the importDate if present', async function() {
let acc = await Accounts.byBank(0, { uuid: accountWithDate.bank });
acc[0].importDate.should.eql(accountWithDate.importDate);
});
});
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