diff --git a/mon-pix/app/services/pix-companion.js b/mon-pix/app/services/pix-companion.js index 27c843cd70a..ee9b18bc25d 100644 --- a/mon-pix/app/services/pix-companion.js +++ b/mon-pix/app/services/pix-companion.js @@ -8,11 +8,13 @@ export default class PixCompanion extends Service { #checkExtensionIsEnabledInterval; startCertification(windowRef = window) { + if (!this.featureToggles.featureToggles.isPixCompanionEnabled) return; windowRef.dispatchEvent(new CustomEvent('pix:certification:start')); windowRef.postMessage({ event: 'pix:certification:start' }, windowRef.location.origin); } stopCertification(windowRef = window) { + if (!this.featureToggles.featureToggles.isPixCompanionEnabled) return; windowRef.dispatchEvent(new CustomEvent('pix:certification:stop')); windowRef.postMessage({ event: 'pix:certification:stop' }, windowRef.location.origin); } diff --git a/mon-pix/tests/unit/services/pix-companion-test.js b/mon-pix/tests/unit/services/pix-companion-test.js index 3799bf2429c..8270a584410 100644 --- a/mon-pix/tests/unit/services/pix-companion-test.js +++ b/mon-pix/tests/unit/services/pix-companion-test.js @@ -28,6 +28,26 @@ module('Unit | Service | pix-companion', function (hooks) { sinon.assert.calledWith(windowStub.postMessage, { event: 'pix:certification:start' }, 'test'); assert.ok(true); }); + + module('when the feature toggle isPixCompanionEnabled is false', function () { + test('do nothing', async function (assert) { + // Given + pixCompanion.featureToggles.featureToggles.isPixCompanionEnabled = false; + const windowStub = { + dispatchEvent: sinon.stub(), + postMessage: sinon.stub(), + location: { origin: 'test' }, + }; + + // When + pixCompanion.startCertification(windowStub); + + // Then + sinon.assert.notCalled(windowStub.dispatchEvent); + sinon.assert.notCalled(windowStub.postMessage); + assert.ok(true); + }); + }); }); module('#stopCertification', function () { @@ -47,6 +67,26 @@ module('Unit | Service | pix-companion', function (hooks) { sinon.assert.calledWith(windowStub.postMessage, { event: 'pix:certification:stop' }, 'test'); assert.ok(true); }); + + module('when the feature toggle isPixCompanionEnabled is false', function () { + test('do nothing', async function (assert) { + // Given + pixCompanion.featureToggles.featureToggles.isPixCompanionEnabled = false; + const windowStub = { + dispatchEvent: sinon.stub(), + postMessage: sinon.stub(), + location: { origin: 'test' }, + }; + + // When + pixCompanion.stopCertification(windowStub); + + // Then + sinon.assert.notCalled(windowStub.dispatchEvent); + sinon.assert.notCalled(windowStub.postMessage); + assert.ok(true); + }); + }); }); module('#checkExtensionIsEnabled', function () {