Commit 9c218989 authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

Finish "bank" to "vendorId" renaming;

parent be8e2c95
......@@ -84,16 +84,16 @@ Access.updateAttributes = function() {
assert(false, 'Access.updateAttributes is deprecated. Please use Access.update');
};
Access.byBank = async function byBank(userId, bank) {
assert(userId === 0, 'Access.byBank first arg must be the userId.');
Access.byVendorId = async function byVendorId(userId, bank) {
assert(userId === 0, 'Access.byVendorId first arg must be the userId.');
if (typeof bank !== 'object' || typeof bank.uuid !== 'string') {
log.warn('Access.byBank misuse: bank must be a Bank instance.');
log.warn('Access.byVendorId misuse: bank must be a Bank instance.');
}
let params = {
key: bank.uuid
};
return await request('allByBank', params);
return await request('allByVendorId', params);
};
// Sync function
......
......@@ -80,17 +80,17 @@ Account = promisifyModel(Account);
let request = promisify(Account.request.bind(Account));
Account.byBank = async function byBank(userId, bank) {
assert(userId === 0, 'Account.byBank first arg must be the userId.');
Account.byVendorId = async function byVendorId(userId, bank) {
assert(userId === 0, 'Account.byVendorId first arg must be the userId.');
if (typeof bank !== 'object' || typeof bank.uuid !== 'string') {
log.warn('Account.byBank misuse: bank must be a Bank instance');
log.warn('Account.byVendorId misuse: bank must be a Bank instance');
}
let params = {
key: bank.uuid
};
return await request('allByBank', params);
return await request('allByVendorId', params);
};
Account.findMany = async function findMany(userId, accountIds) {
......
......@@ -198,22 +198,22 @@ let migrations = [
};
for (let a of accesses) {
if (a.bank === 'bnporc') {
if (a.vendorId === 'bnporc') {
await updateCustomFields(userId, a, updateFieldsBnp);
continue;
}
if (a.bank === 'hellobank') {
if (a.vendorId === 'hellobank') {
// Update access
await updateCustomFields(userId, a, updateFieldsHelloBank);
// Update accounts
let accounts = await Accounts.byBank(userId, { uuid: 'hellobank' });
let accounts = await Accounts.byVendorId(userId, { uuid: 'hellobank' });
for (let acc of accounts) {
await Accounts.update(userId, acc.id, { bank: 'bnporc' });
await Accounts.update(userId, acc.id, { vendorId: 'bnporc' });
}
await Accesses.update(userId, a.id, { bank: 'bnporc' });
await Accesses.update(userId, a.id, { vendorId: 'bnporc' });
log.info("\tHelloBank access updated to use BNP's backend.");
continue;
}
......@@ -353,24 +353,24 @@ let migrations = [
async function m10(userId) {
log.info('Looking for an s2e module...');
try {
let accesses = await Accesses.byBank(userId, { uuid: 's2e' });
let accesses = await Accesses.byVendorId(userId, { uuid: 's2e' });
for (let access of accesses) {
let customFields = JSON.parse(access.customFields);
let { value: website } = customFields.find(f => f.name === 'website');
let bank = null;
let vendorId = null;
switch (website) {
case 'smartphone.s2e-net.com':
log.info('\tMigrating s2e module to bnpere...');
bank = 'bnppere';
vendorId = 'bnppere';
break;
case 'mobile.capeasi.com':
log.info('\tMigrating s2e module to capeasi...');
bank = 'capeasi';
vendorId = 'capeasi';
break;
case 'm.esalia.com':
log.info('\tMigrating s2e module to esalia...');
bank = 'esalia';
vendorId = 'esalia';
break;
case 'mobi.ere.hsbc.fr':
log.error('\tCannot migrate module s2e.');
......@@ -381,8 +381,8 @@ let migrations = [
continue;
}
if (bank !== null) {
await Accesses.update(userId, access.id, { customFields: '[]', bank });
if (vendorId !== null) {
await Accesses.update(userId, access.id, { customFields: '[]', vendorId });
}
}
return true;
......@@ -398,7 +398,7 @@ let migrations = [
let accounts = await Accounts.all(userId);
for (let account of accounts.filter(acc => acc.iban === 'None')) {
log.info(`\tDeleting iban for ${account.title} of bank ${account.bank}`);
log.info(`\tDeleting iban for ${account.title} of bank ${account.vendorId}`);
await Accounts.update(userId, account.id, { iban: null });
}
return true;
......@@ -639,7 +639,7 @@ let migrations = [
async function m19(userId) {
log.info('Migrating Crédit Mutuel de Bretagne default website.');
try {
let accesses = await Accesses.byBank(userId, { uuid: 'cmb' });
let accesses = await Accesses.byVendorId(userId, { uuid: 'cmb' });
accessLoop: for (let access of accesses) {
let customFields = JSON.parse(access.customFields);
......@@ -721,7 +721,7 @@ let migrations = [
async function m21(userId) {
log.info('Migrating banquepopulaire websites.');
try {
let accesses = await Accesses.byBank(userId, { uuid: 'banquepopulaire' });
let accesses = await Accesses.byVendorId(userId, { uuid: 'banquepopulaire' });
const updateBanqueBopulaire = customFields => {
let newFields = [];
for (let { name, value } of customFields) {
......@@ -779,7 +779,7 @@ let migrations = [
async function m22(userId) {
log.info("Migrating bnporc 'ppold' website to 'pp'");
try {
let accesses = await Accesses.byBank(userId, { uuid: 'bnporc' });
let accesses = await Accesses.byVendorId(userId, { uuid: 'bnporc' });
const changePpoldToPp = customFields => {
for (let customField of customFields) {
if (customField.name === 'website' && customField.value === 'ppold') {
......
......@@ -2,7 +2,7 @@ import * as cozydb from 'cozydb';
/* eslint-disable */
function allByName() { emit(doc.name, doc); }
function allByBank() { emit(doc.bank, doc); }
function allByVendorId() { emit(doc.vendorId, doc); }
function allByBankAccess() { emit(doc.bankAccess, doc); }
function allByBankAccount() { emit(doc.accountId, doc); }
function allByAccountIds() { emit(doc.id, doc); }
......@@ -20,14 +20,14 @@ function byCategoryAndYearAndMonth() { emit([doc.categoryId, doc.year, doc.mo
module.exports = {
accesses: {
all: cozydb.defaultRequests.all,
allByBank
allByVendorId
},
accounts: {
all: cozydb.defaultRequests.all,
allByAccountIds,
allByBankAccess,
allByBank
allByVendorId
},
alerts: {
......
......@@ -276,21 +276,21 @@ describe('Test migration 2', () => {
describe('Test migration 3', () => {
let hasWebsiteField = {
bank: 'HAS_WEBSITE',
vendorId: 'HAS_WEBSITE',
website: 'https://kresus.org'
};
let hasNoWebsiteField = {
bank: 'WEBSITE_UNDEFINED'
vendorId: 'WEBSITE_UNDEFINED'
};
let hasEmptyWebsiteField = {
bank: 'NO_WEBSITE',
vendorId: 'NO_WEBSITE',
website: ''
};
let hasWebsiteFieldAndCustomField = {
bank: 'HAS_CUSTOMFIELD_WEBSITE',
vendorId: 'HAS_CUSTOMFIELD_WEBSITE',
website: 'https://framagit.org/kresusapp/kresus',
customFields: JSON.stringify([
{
......@@ -329,7 +329,7 @@ describe('Test migration 3', () => {
it('should have transformed the website property into a custom field', async function() {
let allAccesses = await Accesses.all(0);
let access = allAccesses.find(t => t.bank === hasWebsiteField.bank);
let access = allAccesses.find(t => t.vendorId === hasWebsiteField.vendorId);
access.customFields.should.equal(
JSON.stringify([{ name: 'website', value: hasWebsiteField.website }])
);
......@@ -338,30 +338,30 @@ describe('Test migration 3', () => {
it('should not have transformed the website property into a custom field if it was empty', async function() {
let allAccesses = await Accesses.all(0);
let access = allAccesses.find(t => t.bank === hasNoWebsiteField.bank);
let access = allAccesses.find(t => t.vendorId === hasNoWebsiteField.vendorId);
access.customFields.should.equal('[]');
should.not.exist(access.website);
access = allAccesses.find(t => t.bank === hasEmptyWebsiteField.bank);
access = allAccesses.find(t => t.vendorId === hasEmptyWebsiteField.vendorId);
access.customFields.should.equal('[]');
});
it('should not modify an existing custom field named "website"', async function() {
let allAccesses = await Accesses.all(0);
let access = allAccesses.find(t => t.bank === hasWebsiteFieldAndCustomField.bank);
let access = allAccesses.find(t => t.vendorId === hasWebsiteFieldAndCustomField.vendorId);
access.customFields.should.equal(hasWebsiteFieldAndCustomField.customFields);
});
});
describe('Test migration 4', () => {
let bnpAccess = {
bank: 'bnporc',
vendorId: 'bnporc',
login: 'bnporc'
};
let bnpAccessWithWebsite = {
bank: bnpAccess.bank,
vendorId: bnpAccess.vendorId,
login: 'bnporcwithwebsite',
customFields: JSON.stringify([
{
......@@ -372,12 +372,12 @@ describe('Test migration 4', () => {
};
let helloBankAccess = {
bank: 'hellobank',
vendorId: 'hellobank',
login: 'hellobank'
};
let helloBankAccount = {
bank: helloBankAccess.bank
vendorId: helloBankAccess.vendorId
};
before(async function() {
......@@ -407,14 +407,14 @@ describe('Test migration 4', () => {
result.should.equal(true);
});
it('should have transformed the bank property into the new one', async function() {
it('should have transformed the vendorId property into the new one', async function() {
let allAccesses = await Accesses.all(0);
let access = allAccesses.find(t => t.login === helloBankAccess.login);
access.bank.should.equal('bnporc');
access.vendorId.should.equal('bnporc');
let allAccounts = await Accounts.all(0);
allAccounts[0].bank.should.equal('bnporc');
allAccounts[0].vendorId.should.equal('bnporc');
});
it('should have updated the websites custom fields if not already defined', async function() {
......@@ -437,16 +437,16 @@ describe('Test migration 4', () => {
describe('Test migration 5', () => {
let account = {
bank: 'fakeaccount'
vendorId: 'fakeaccount'
};
let accountWithDate = {
bank: 'withdate',
vendorId: 'withdate',
importDate: new Date()
};
let accountWithOps = {
bank: 'withops'
vendorId: 'withops'
};
let op1fields = {
......@@ -489,17 +489,17 @@ describe('Test migration 5', () => {
});
it('should have set an import date when missing', async function() {
let acc = await Accounts.byBank(0, { uuid: account.bank });
let acc = await Accounts.byVendorId(0, { uuid: account.vendorId });
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 });
let acc = await Accounts.byVendorId(0, { uuid: accountWithOps.vendorId });
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 });
let acc = await Accounts.byVendorId(0, { uuid: accountWithDate.vendorId });
acc[0].importDate.should.eql(accountWithDate.importDate);
});
});
......@@ -671,7 +671,7 @@ describe('Test migration 9', () => {
describe('Test migration 10', () => {
let bnpere = {
bank: 's2e',
vendorId: 's2e',
customFields: JSON.stringify([
{
name: 'website',
......@@ -681,7 +681,7 @@ describe('Test migration 10', () => {
};
let capeasi = {
bank: 's2e',
vendorId: 's2e',
customFields: JSON.stringify([
{
name: 'website',
......@@ -691,7 +691,7 @@ describe('Test migration 10', () => {
};
let esalia = {
bank: 's2e',
vendorId: 's2e',
customFields: JSON.stringify([
{
name: 'website',
......@@ -701,7 +701,7 @@ describe('Test migration 10', () => {
};
let hsbc = {
bank: 's2e',
vendorId: 's2e',
customFields: JSON.stringify([
{
name: 'website',
......@@ -711,7 +711,7 @@ describe('Test migration 10', () => {
};
let other = {
bank: 'fakebank',
vendorId: 'fakebank',
customFields: JSON.stringify([
{
name: 'website',
......@@ -743,26 +743,26 @@ describe('Test migration 10', () => {
});
it('only hsbc should remain a s2e bank access', async function() {
let s2eAccesses = await Accesses.byBank(0, { uuid: 's2e' });
let s2eAccesses = await Accesses.byVendorId(0, { uuid: 's2e' });
s2eAccesses.length.should.equal(1);
s2eAccesses.should.containDeep([hsbc]);
});
it('should have modified the bank & reset the custom fields for all s2e accesses but hsbc', async function() {
let allAccesses = await Accesses.all(0);
allAccesses = allAccesses.filter(a => !['s2e', 'fakebank'].includes(a.bank));
allAccesses = allAccesses.filter(a => !['s2e', 'fakebank'].includes(a.vendorId));
allAccesses.length.should.equal(3);
allAccesses.every(a => a.customFields === '[]').should.equal(true);
allAccesses.should.containDeep([
{ bank: 'bnppere' },
{ bank: 'capeasi' },
{ bank: 'esalia' }
{ vendorId: 'bnppere' },
{ vendorId: 'capeasi' },
{ vendorId: 'esalia' }
]);
});
it('should not have transformed any other bank access', async function() {
let otherAccesses = await Accesses.byBank(0, { uuid: other.bank });
let otherAccesses = await Accesses.byVendorId(0, { uuid: other.vendorId });
otherAccesses.length.should.equal(1);
otherAccesses.should.containDeep([other]);
});
......@@ -920,16 +920,16 @@ describe('Test migration 13', async function() {
describe('Test migration 14', () => {
let invalidCustomField = {
bank: 'HAS_INVALID_CUSTOMFIELD',
vendorId: 'HAS_INVALID_CUSTOMFIELD',
customFields: 'INVALID'
};
let noCustomField = {
bank: 'NO_CUSTOM_FIELD'
vendorId: 'NO_CUSTOM_FIELD'
};
let validCustomField = {
bank: 'HAS_VALID_CUSTOMFIELD',
vendorId: 'HAS_VALID_CUSTOMFIELD',
customFields: JSON.stringify([
{
name: 'website',
......@@ -960,14 +960,16 @@ describe('Test migration 14', () => {
it('should have replaced invalid or nonexistent custom fields by an empty array', async function() {
let allAccesses = await Accesses.all(0);
allAccesses = allAccesses.filter(a => a.bank !== validCustomField.bank);
allAccesses = allAccesses.filter(a => a.vendorId !== validCustomField.vendorId);
allAccesses.length.should.equal(2);
allAccesses.every(a => a.customFields === '[]').should.equal(true);
});
it('should not have modified valid customFields', async function() {
let allAccesses = await Accesses.all(0);
let validCustomFiedsAccess = allAccesses.find(a => a.bank === validCustomField.bank);
let validCustomFiedsAccess = allAccesses.find(
a => a.vendorId === validCustomField.vendorId
);
validCustomFiedsAccess.customFields.should.equal(validCustomField.customFields);
});
});
......@@ -1175,21 +1177,21 @@ describe('Test migration 19', async function() {
});
let cmbAccessToKeep = {
bank: 'cmb',
vendorId: 'cmb',
login: 'toto',
password: 'password',
customFields: JSON.stringify([{ name: 'website', value: 'pro' }])
};
let cmbAccessToChange = {
bank: 'cmb',
vendorId: 'cmb',
login: 'toto',
password: 'password',
customFields: JSON.stringify([])
};
let otherAccessToKeep = {
bank: 'other',
vendorId: 'other',
login: 'toto',
password: 'password',
customFields: JSON.stringify([])
......@@ -1318,7 +1320,7 @@ describe('Test migration 21', async function() {
async function runM21Once(oldSite, newSite) {
describe(`Test applying M21 for website ${oldSite}`, async function() {
let bpAccessToChange = {
bank: 'banquepopulaire',
vendorId: 'banquepopulaire',
login: 'toto',
password: 'password',
customFields: JSON.stringify([{ name: 'website', value: oldSite }])
......@@ -1356,7 +1358,7 @@ describe('Test migration 21', async function() {
describe('Other website should not be changed', async function() {
let bpAccessToKeep = {
bank: 'banquepopulaire',
vendorId: 'banquepopulaire',
login: 'toto',
password: 'password',
customFields: JSON.stringify([{ name: 'website', value: 'oldSite' }])
......@@ -1386,7 +1388,7 @@ describe('Test migration 21', async function() {
describe('Other customFields should not be changed', async function() {
let bpAccessToKeep = {
bank: 'banquepopulaire',
vendorId: 'banquepopulaire',
login: 'toto',
password: 'password',
customFields: JSON.stringify([{ name: 'other', value: 'value' }])
......@@ -1421,21 +1423,21 @@ describe('Test migration 22', async function() {
});
let bnporcAccessToKeep = {
bank: 'bnporc',
vendorId: 'bnporc',
login: 'toto',
password: 'password',
customFields: JSON.stringify([{ name: 'website', value: 'pro' }])
};
let bnporcAccessToChange = {
bank: 'bnporc',
vendorId: 'bnporc',
login: 'toto',
password: 'password',
customFields: JSON.stringify([{ name: 'website', value: 'ppold' }])
};
let otherAccessToKeep = {
bank: 'other',
vendorId: 'other',
login: 'toto',
password: 'password',
customFields: JSON.stringify([])
......@@ -1483,7 +1485,7 @@ describe('Test migration 23', async function() {
});
let account = {
bank: 'lolbank',
vendorId: 'lolbank',
initialAmount: 42
};
......@@ -1505,7 +1507,7 @@ describe('Test migration 23', async function() {
all.length.should.equal(1);
let result = all[0];
result.bank.should.equal(account.bank);
result.vendorId.should.equal(account.vendorId);
result.initialBalance.should.equal(account.initialAmount);
should.not.exist(result.initialAmount);
});
......
Supports Markdown
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