Skip to content

Commit

Permalink
♻️ api: remove dead code that used PIX_CERTIF_SCO_BLOCKED_ACCESS_WHIT…
Browse files Browse the repository at this point in the history
…ELIST

* This code was used by migration scripts during V3 generalization. Scripts that are now deleted.
  • Loading branch information
Steph0 committed Dec 3, 2024
1 parent 10243f4 commit 98e08fc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 119 deletions.
15 changes: 0 additions & 15 deletions api/src/certification/configuration/domain/models/Center.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import Joi from 'joi';

import { config } from '../../../../shared/config.js';
import { EntityValidationError } from '../../../../shared/domain/errors.js';
import { _ } from '../../../../shared/infrastructure/utils/lodash-utils.js';
import { CenterTypes } from './CenterTypes.js';

export class Center {
static #schema = Joi.object({
Expand All @@ -26,18 +23,6 @@ export class Center {
this.#validate();
}

isInWhitelist() {
if (this.type !== CenterTypes.SCO) {
return true;
}

if (this.type == CenterTypes.SCO && _.isBlank(this.externalId)) {
return false;
}

return config.features.pixCertifScoBlockedAccessWhitelist.includes(this.externalId.toUpperCase());
}

#validate() {
const { error } = Center.#schema.validate(this, { allowUnknown: false });
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,108 +32,4 @@ describe('Unit | Certification | Configuration | Domain | Models | Center', func
expect(error).to.be.an.instanceOf(EntityValidationError);
});
});

context('#isInWhitelist', function () {
let originalEnvValueWhitelist;

beforeEach(function () {
originalEnvValueWhitelist = config.features.pixCertifScoBlockedAccessWhitelist;
config.features.pixCertifScoBlockedAccessWhitelist = [];
});

afterEach(function () {
config.features.pixCertifScoBlockedAccessWhitelist = originalEnvValueWhitelist;
});

it('should consider centers other than SCO as always whitelisted', function () {
// given
config.features.pixCertifScoBlockedAccessWhitelist = ['hello'];
const center = new Center({
id: 12,
type: CenterTypes.PRO,
externalId: 'hello',
});
// when
const isInWhitelist = center.isInWhitelist();

// then
expect(isInWhitelist).to.be.true;
});
context('when center is SCO', function () {
it('should consider blank externalId as not whitelisted', function () {
// given
const center = new Center({
id: 12,
type: CenterTypes.SCO,
externalId: ' ',
});
// when
const isInWhitelist = center.isInWhitelist();

// then
expect(isInWhitelist).to.be.false;
});

it('should consider center without externalId as not whitelisted', function () {
// given
const center = new Center({
id: 12,
type: CenterTypes.SCO,
externalId: undefined,
});
// when
const isInWhitelist = center.isInWhitelist();

// then
expect(isInWhitelist).to.be.false;
});

it('should consider center in whitelist as whitelisted', function () {
// given
const externalId = 'WHITELISTED';
config.features.pixCertifScoBlockedAccessWhitelist = [externalId];
const center = new Center({
id: 12,
type: CenterTypes.SCO,
externalId: externalId,
});
// when
const isInWhitelist = center.isInWhitelist();

// then
expect(isInWhitelist).to.be.true;
});

it('should consider center NOT in whitelist as NOT whitelisted', function () {
// given
config.features.pixCertifScoBlockedAccessWhitelist = ['WHITELISTED'];
const center = new Center({
id: 12,
type: CenterTypes.SCO,
externalId: 'not_whitelisted',
});
// when
const isInWhitelist = center.isInWhitelist();

// then
expect(isInWhitelist).to.be.false;
});

it('should not be case sensitive on externalId', function () {
// given
// config is already uppercased + trimmed
config.features.pixCertifScoBlockedAccessWhitelist = ['WHITELISTED12'];
const center = new Center({
id: 12,
type: CenterTypes.SCO,
externalId: 'whiteLISTed12',
});
// when
const isInWhitelist = center.isInWhitelist();

// then
expect(isInWhitelist).to.be.true;
});
});
});
});

0 comments on commit 98e08fc

Please sign in to comment.