From adddcdc0af4d518e406d6454a5672b28b1c9cf22 Mon Sep 17 00:00:00 2001 From: AndreiaPena Date: Fri, 15 Nov 2024 11:45:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20api:=20(2nd=20script)=20delete?= =?UTF-8?q?=20updateCentersToV3=20and=20findV2CenterIds=20methods=20from?= =?UTF-8?q?=20center=20repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only used in convertCentersToV3 usecase --- .../repositories/center-repository.js | 30 ------------ .../repositories/center-repository_test.js | 49 ------------------- 2 files changed, 79 deletions(-) diff --git a/api/src/certification/configuration/infrastructure/repositories/center-repository.js b/api/src/certification/configuration/infrastructure/repositories/center-repository.js index 61a2515bfac..a3e8ff2c744 100644 --- a/api/src/certification/configuration/infrastructure/repositories/center-repository.js +++ b/api/src/certification/configuration/infrastructure/repositories/center-repository.js @@ -23,33 +23,3 @@ export const resetWhitelist = async () => { .update({ isScoBlockedAccessWhitelist: false, updatedAt: knexConn.fn.now() }) .where({ type: CenterTypes.SCO }); }; - -/** - * @param {Object} params - * @param {Array} params.preservedCenterIds - * @returns {Promise} 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} params.preservedCenterIds - * @returns {Promise>} 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); -}; diff --git a/api/tests/certification/configuration/integration/infrastructure/repositories/center-repository_test.js b/api/tests/certification/configuration/integration/infrastructure/repositories/center-repository_test.js index 989e3225e27..0c86f3d53c0 100644 --- a/api/tests/certification/configuration/integration/infrastructure/repositories/center-repository_test.js +++ b/api/tests/certification/configuration/integration/infrastructure/repositories/center-repository_test.js @@ -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]); - }); - }); });