Skip to content

Commit

Permalink
✨ api: whem updating the whitelist, we also have to indicate the upda…
Browse files Browse the repository at this point in the history
…tedAt column
  • Loading branch information
Steph0 committed Sep 24, 2024
1 parent a86b505 commit 7267b03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const findSCOV2Centers = async function ({ pageNumber = DEFAULT_PAGINATIO
export const addToWhitelistByExternalIds = async ({ externalIds }) => {
const knexConn = DomainTransaction.getConnection();
return knexConn('certification-centers')
.update({ isScoBlockedAccessWhitelist: true })
.update({ isScoBlockedAccessWhitelist: true, updatedAt: knexConn.fn.now() })
.whereIn('externalId', externalIds);
};

Expand All @@ -37,5 +37,5 @@ export const addToWhitelistByExternalIds = async ({ externalIds }) => {
*/
export const resetWhitelist = async () => {
const knexConn = DomainTransaction.getConnection();
return knexConn('certification-centers').update({ isScoBlockedAccessWhitelist: false });
return knexConn('certification-centers').update({ isScoBlockedAccessWhitelist: false, updatedAt: knexConn.fn.now() });
};
Original file line number Diff line number Diff line change
Expand Up @@ -111,37 +111,41 @@ describe('Certification | Configuration | Integration | Repository | center-repo
it('should set the centers as whitelisted', async function () {
// given
const whitelistedExternalId = '1234ABC';
const centerId = databaseBuilder.factory.buildCertificationCenter({
const centerBeforeUpdate = databaseBuilder.factory.buildCertificationCenter({
type: CenterTypes.SCO,
externalId: whitelistedExternalId,
isScoBlockedAccessWhitelist: false,
}).id;
updatedAt: new Date('2024-09-24'),
});
await databaseBuilder.commit();

// when
await centerRepository.addToWhitelistByExternalIds({ externalIds: [whitelistedExternalId] });

// then
const updatedCenter = await knex('certification-centers').where({ id: centerId }).first();
const updatedCenter = await knex('certification-centers').where({ id: centerBeforeUpdate.id }).first();
expect(updatedCenter.isScoBlockedAccessWhitelist).to.be.true;
expect(updatedCenter.updatedAt).to.be.above(centerBeforeUpdate.updatedAt);
});
});

describe('#resetWhitelist', function () {
it('should reset all isScoBlockedAccessWhitelist to false', async function () {
// given
const centerId = databaseBuilder.factory.buildCertificationCenter({
const centerBeforeUpdate = databaseBuilder.factory.buildCertificationCenter({
type: CenterTypes.SCO,
isScoBlockedAccessWhitelist: true,
}).id;
updatedAt: new Date('2024-09-24'),
});
await databaseBuilder.commit();

// when
await centerRepository.resetWhitelist();

// then
const updatedCenter = await knex('certification-centers').where({ id: centerId }).first();
const updatedCenter = await knex('certification-centers').where({ id: centerBeforeUpdate.id }).first();
expect(updatedCenter.isScoBlockedAccessWhitelist).to.be.false;
expect(updatedCenter.updatedAt).to.be.above(centerBeforeUpdate.updatedAt);
});
});
});

0 comments on commit 7267b03

Please sign in to comment.