From 271295b8a56869a28fa0f206dd784139fee6a523 Mon Sep 17 00:00:00 2001 From: Nicolas Lepage <19571875+nlepage@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:39:56 +0200 Subject: [PATCH] feat(mon-pix): do not emit start/stop certification events when FT is false Co-authored-by: Andreia Pena Ferreira --- mon-pix/app/services/pix-companion.js | 2 + .../tests/unit/services/pix-companion-test.js | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/mon-pix/app/services/pix-companion.js b/mon-pix/app/services/pix-companion.js index 27c843cd70..ee9b18bc25 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 3799bf2429..8270a58441 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 () {