Skip to content

Commit

Permalink
🔥 api: (2nd script) delete updateCentersToV3 and findV2CenterIds meth…
Browse files Browse the repository at this point in the history
…ods from center repository

Only used in convertCentersToV3 usecase
  • Loading branch information
AndreiaPena committed Nov 15, 2024
1 parent caf334f commit adddcdc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,3 @@ export const resetWhitelist = async () => {
.update({ isScoBlockedAccessWhitelist: false, updatedAt: knexConn.fn.now() })
.where({ type: CenterTypes.SCO });
};

/**
* @param {Object} params
* @param {Array<number>} params.preservedCenterIds
* @returns {Promise<number>} updated centers count
*/
export const updateCentersToV3 = async ({ preservedCenterIds }) => {
const knexConn = DomainTransaction.getConnection();
const results = await knexConn('certification-centers')
.update({ isV3Pilot: true, updatedAt: knexConn.fn.now() }, ['id'])
.where({ isV3Pilot: false })
.whereNotIn('id', preservedCenterIds);

return results.length;
};

/**
* @param {Object} params
* @param {Array<number>} params.preservedCenterIds
* @returns {Promise<Array<number>>} v2 center ids excluding preservedCenterIds
*/
export const findV2CenterIds = async ({ preservedCenterIds }) => {
const knexConn = DomainTransaction.getConnection();
const centers = await knexConn('certification-centers')
.select('id')
.where({ isV3Pilot: false })
.whereNotIn('id', preservedCenterIds);

return centers.map(({ id }) => id);
};
Original file line number Diff line number Diff line change
Expand Up @@ -95,53 +95,4 @@ describe('Certification | Configuration | Integration | Repository | center-repo
expect(updatedCenter.isScoBlockedAccessWhitelist).to.be.true;
});
});

describe('#updateCentersToV3', function () {
it('should set isV3Pilot to true for v2 centers', async function () {
const v2Center = databaseBuilder.factory.buildCertificationCenter({
isV3Pilot: false,
});
await databaseBuilder.commit();

const count = await centerRepository.updateCentersToV3({ preservedCenterIds: [] });

const updatedCenter = await knex('certification-centers').where({ id: v2Center.id }).first();
expect(updatedCenter.isV3Pilot).to.be.true;
expect(count).to.equal(1);
});

it('should avoid setting isV3Pilot to true for v2 centers of preservedCenterIds', async function () {
const v2Center = databaseBuilder.factory.buildCertificationCenter({
isV3Pilot: false,
});
const v2CenterToPreserve = databaseBuilder.factory.buildCertificationCenter({
isV3Pilot: false,
});
await databaseBuilder.commit();

await centerRepository.updateCentersToV3({ preservedCenterIds: [v2CenterToPreserve.id] });

const updatedCenter = await knex('certification-centers').where({ id: v2Center.id }).first();
expect(updatedCenter.isV3Pilot).to.be.true;

const preservedCenter = await knex('certification-centers').where({ id: v2CenterToPreserve.id }).first();
expect(preservedCenter.isV3Pilot).to.be.false;
});
});

describe('#findV2Centers', function () {
it('should avoid setting isV3Pilot to true for v2 centers of preservedCenterIds', async function () {
const v2Center = databaseBuilder.factory.buildCertificationCenter({
isV3Pilot: false,
});
const v2CenterToPreserve = databaseBuilder.factory.buildCertificationCenter({
isV3Pilot: false,
});
await databaseBuilder.commit();

const centerIds = await centerRepository.findV2CenterIds({ preservedCenterIds: [v2CenterToPreserve.id] });

expect(centerIds).to.deep.equal([v2Center.id]);
});
});
});

0 comments on commit adddcdc

Please sign in to comment.