Skip to content

Commit

Permalink
feat(mon-pix): do not emit start/stop certification events when FT is…
Browse files Browse the repository at this point in the history
… false

Co-authored-by: Andreia Pena Ferreira <[email protected]>
  • Loading branch information
nlepage and AndreiaPena authored Oct 10, 2024
1 parent 7c8199d commit 271295b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mon-pix/app/services/pix-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
40 changes: 40 additions & 0 deletions mon-pix/tests/unit/services/pix-companion-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand Down

0 comments on commit 271295b

Please sign in to comment.