Commit f975484c authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

Also migrate btpbanque + bred + add tests

parent 2e7f329e
Pipeline #421484 passed with stage
in 11 minutes and 58 seconds
......@@ -18,17 +18,20 @@ export async function updateBanks(userId: number | null, manager: EntityManager)
userCondition.userId = userId;
}
const accesses: Access[] = await manager.find(Access, {
// Remove the `auth_type` access field in both creditcooperatif and
// btpbanque, which is now optional and whose set of possible value have
// been updated.
log.info('> Removing auth_type on creditcooperatif/btpbanque...');
let accesses: Access[] = await manager.find(Access, {
select: ['id'],
where: {
vendorId: 'creditcooperatif',
vendorId: In(['creditcooperatif', 'btpbanque']),
...userCondition,
},
});
if (accesses.length > 0) {
// Remove the "auth_type" access field, which is now optional and for
// which possible values have been updated.
await manager.delete(AccessField, {
accessId: In(accesses.map(acc => acc.id)),
name: 'auth_type',
......@@ -36,5 +39,24 @@ export async function updateBanks(userId: number | null, manager: EntityManager)
});
}
// Remove the "website" field from the bred module; it's now unused.
log.info('> Removing website on bred...');
accesses = await manager.find(Access, {
select: ['id'],
where: {
vendorId: 'bred',
...userCondition,
},
});
if (accesses.length > 0) {
await manager.delete(AccessField, {
accessId: In(accesses.map(acc => acc.id)),
name: 'website',
...userCondition,
});
}
log.info('Finished running data migration on banks (2021-05-26)');
}
......@@ -735,4 +735,73 @@ describe('Data migrations', () => {
(await Access.byVendorId(USER_ID, { uuid: 'ganassurances' })).length.should.equal(1);
(await Access.byVendorId(USER_ID, { uuid: 'manual' })).length.should.equal(1);
});
it('should remove creditcooperatif/btpbanque auth_type', async () => {
await cleanAll(USER_ID);
const data = {
accesses: [
{
id: 0,
vendorId: 'creditcooperatif',
login: 'whatever-manual-acc--does-not-care',
fields: [
{
name: 'auth_type',
value: 'particular',
},
],
},
{
id: 1,
vendorId: 'btpbanque',
login: 'whatever-manual-acc--does-not-care',
fields: [
{
name: 'auth_type',
value: 'strong',
},
],
},
{
id: 2,
vendorId: 'bred',
login: 'whatever-manual-acc--does-not-care',
fields: [
{
name: 'website',
value: 'bred',
},
],
},
{
id: 3,
vendorId: 'manual',
login: 'whatever-manual-acc--does-not-care',
fields: [
{
name: 'test',
value: 'whatever',
},
],
},
],
};
await importData(USER_ID, data);
const actualAccesses = await Access.all(USER_ID);
actualAccesses.length.should.equal(data.accesses.length);
// Remove All The Fields!
actualAccesses[0].fields.length.should.equal(0);
actualAccesses[1].fields.length.should.equal(0);
actualAccesses[2].fields.length.should.equal(0);
// But not the fields of unrelated accesses.
actualAccesses[3].fields.length.should.equal(1);
});
});
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