Skip to content

Commit

Permalink
🚧 mon-pix: use pix companion feature toggle in pix app
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiaPena committed Oct 10, 2024
1 parent 93072f7 commit 4757b9b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
1 change: 1 addition & 0 deletions mon-pix/app/models/feature-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export default class FeatureToggle extends Model {
@attr('boolean') isNewAuthenticationDesignEnabled;
@attr('boolean') isTextToSpeechButtonEnabled;
@attr('boolean') showNewResultPage;
@attr('boolean') isPixCompanionEnabled;
}
10 changes: 5 additions & 5 deletions mon-pix/app/services/pix-companion.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Service from '@ember/service';
import Service, { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import ENV from 'mon-pix/config/environment';

export default class PixCompanion extends Service {
@service featureToggles;
@tracked _isExtensionEnabled = true;

#checkExtensionIsEnabledInterval;
Expand All @@ -18,13 +18,13 @@ export default class PixCompanion extends Service {
}

startCheckingExtensionIsEnabled(windowRef = window) {
if (!ENV.APP.FT_IS_PIX_COMPANION_MANDATORY) return;
if (!this.featureToggles.isPixCompanionEnabled) return;
this.checkExtensionIsEnabled(windowRef);
this.#checkExtensionIsEnabledInterval = windowRef.setInterval(() => this.checkExtensionIsEnabled(windowRef), 1000);
}

stopCheckingExtensionIsEnabled(windowRef = window) {
if (!ENV.APP.FT_IS_PIX_COMPANION_MANDATORY) return;
if (!this.featureToggles.isPixCompanionEnabled) return;
windowRef.clearInterval(this.#checkExtensionIsEnabledInterval);
}

Expand All @@ -50,7 +50,7 @@ export default class PixCompanion extends Service {
}

get isExtensionEnabled() {
if (!ENV.APP.FT_IS_PIX_COMPANION_MANDATORY) return true;
if (!this.featureToggles.isPixCompanionEnabled) return true;
return this._isExtensionEnabled;
}
}
Expand Down
2 changes: 0 additions & 2 deletions mon-pix/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = function (environment) {
// when it is created
API_HOST: process.env.API_HOST || '',
FT_FOCUS_CHALLENGE_ENABLED: _isFeatureEnabled(process.env.FT_FOCUS_CHALLENGE_ENABLED) || false,
FT_IS_PIX_COMPANION_MANDATORY: _isFeatureEnabled(process.env.FT_IS_PIX_COMPANION_MANDATORY) || false,
isTimerCountdownEnabled: true,
LOAD_EXTERNAL_SCRIPT: true,
NUMBER_OF_CHALLENGES_BETWEEN_TWO_CHECKPOINTS: 5,
Expand Down Expand Up @@ -172,7 +171,6 @@ module.exports = function (environment) {
ENV.APP.isTimerCountdownEnabled = false;
ENV.APP.LOAD_EXTERNAL_SCRIPT = false;
ENV.APP.FT_FOCUS_CHALLENGE_ENABLED = true;
ENV.APP.FT_IS_PIX_COMPANION_MANDATORY = false;
ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID = 999;
ENV.metrics.enabled = false;
}
Expand Down
15 changes: 14 additions & 1 deletion mon-pix/tests/unit/services/feature-toggles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module('Unit | Service | feature-toggles', function (hooks) {
const featureToggles = Object.create({
isTextToSpeechButtonEnabled: false,
isNewAuthenticationDesignEnabled: false,
isPixCompanionEnabled: false,
});

let storeStub;
Expand Down Expand Up @@ -45,7 +46,7 @@ module('Unit | Service | feature-toggles', function (hooks) {
assert.false(featureToggleService.featureToggles.isTextToSpeechButtonEnabled);
});

test('it initializes the feature toggle isNewAuthenticationDesignEnabled to true', async function (assert) {
test('it initializes the feature toggle isNewAuthenticationDesignEnabled to false', async function (assert) {
// given
const featureToggleService = this.owner.lookup('service:featureToggles');
featureToggleService.set('store', storeStub);
Expand All @@ -56,5 +57,17 @@ module('Unit | Service | feature-toggles', function (hooks) {
// then
assert.false(featureToggleService.featureToggles.isNewAuthenticationDesignEnabled);
});

test('it initializes the feature toggle isPixCompanionEnabled to false', async function (assert) {
// given
const featureToggleService = this.owner.lookup('service:featureToggles');
featureToggleService.set('store', storeStub);

// when
await featureToggleService.load();

// then
assert.false(featureToggleService.featureToggles.isPixCompanionEnabled);
});
});
});
32 changes: 10 additions & 22 deletions mon-pix/tests/unit/services/pix-companion-test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { setupTest } from 'ember-qunit';
import ENV from 'mon-pix/config/environment';
import { module, test } from 'qunit';
import sinon from 'sinon';

module('Unit | Service | pix-companion', function (hooks) {
setupTest(hooks);
let pixCompanion;

const ORIGINAL_FT_IS_PIX_COMPANION_MANDATORY = ENV.APP.FT_IS_PIX_COMPANION_MANDATORY;

hooks.beforeEach(() => {
ENV.APP.FT_IS_PIX_COMPANION_MANDATORY = true;
});

hooks.afterEach(() => {
ENV.APP.FT_IS_PIX_COMPANION_MANDATORY = ORIGINAL_FT_IS_PIX_COMPANION_MANDATORY;
hooks.beforeEach(function () {
pixCompanion = this.owner.lookup('service:pix-companion');
pixCompanion.featureToggles = { isPixCompanionEnabled: true };
});

module('#startCertification', function () {
Expand All @@ -24,7 +19,6 @@ module('Unit | Service | pix-companion', function (hooks) {
postMessage: sinon.stub(),
location: { origin: 'test' },
};
const pixCompanion = this.owner.lookup('service:pix-companion');

// When
pixCompanion.startCertification(windowStub);
Expand All @@ -44,7 +38,6 @@ module('Unit | Service | pix-companion', function (hooks) {
postMessage: sinon.stub(),
location: { origin: 'test' },
};
const pixCompanion = this.owner.lookup('service:pix-companion');

// When
pixCompanion.stopCertification(windowStub);
Expand All @@ -69,7 +62,6 @@ module('Unit | Service | pix-companion', function (hooks) {
assert.strictEqual(type, 'pix:companion:pong');
listener();
});
const pixCompanion = this.owner.lookup('service:pix-companion');
pixCompanion._isExtensionEnabled = false;

// When
Expand All @@ -93,7 +85,6 @@ module('Unit | Service | pix-companion', function (hooks) {
assert.strictEqual(timeout, 100);
callback();
});
const pixCompanion = this.owner.lookup('service:pix-companion');
pixCompanion._isExtensionEnabled = true;

// When
Expand All @@ -107,18 +98,17 @@ module('Unit | Service | pix-companion', function (hooks) {
});

module('#startCheckingExtensionIsEnabled', function () {
module('when FT_IS_PIX_COMPANION_MANDATORY is false', function () {
module('when the feature toggle isPixCompanionEnabled is false', function () {
test('do nothing', async function (assert) {
// Given
ENV.APP.FT_IS_PIX_COMPANION_MANDATORY = false;
const windowStub = {
addEventListener: sinon.stub(),
dispatchEvent: sinon.stub(),
removeEventListener: sinon.stub(),
setInterval: sinon.stub(),
setTimeout: sinon.stub(),
};
const pixCompanion = this.owner.lookup('service:pix-companion');
pixCompanion.featureToggles = { isPixCompanionEnabled: false };

// When
pixCompanion.startCheckingExtensionIsEnabled(windowStub);
Expand All @@ -136,14 +126,13 @@ module('Unit | Service | pix-companion', function (hooks) {
});

module('#stopCheckingExtensionIsEnabled', function () {
module('when FT_IS_PIX_COMPANION_MANDATORY is false', function () {
module('when the feature toggle isPixCompanionEnabled is false', function () {
test('do nothing', async function (assert) {
// Given
ENV.APP.FT_IS_PIX_COMPANION_MANDATORY = false;
const windowStub = {
clearInterval: sinon.stub(),
};
const pixCompanion = this.owner.lookup('service:pix-companion');
pixCompanion.featureToggles = { isPixCompanionEnabled: false };

// When
pixCompanion.stopCheckingExtensionIsEnabled(windowStub);
Expand All @@ -156,11 +145,10 @@ module('Unit | Service | pix-companion', function (hooks) {
});

module('#isExtensionEnabled', function () {
module('when FT_IS_PIX_COMPANION_MANDATORY is false', function () {
module('when the feature toggle isPixCompanionEnabled is false', function () {
test('always return true', async function (assert) {
// Given
ENV.APP.FT_IS_PIX_COMPANION_MANDATORY = false;
const pixCompanion = this.owner.lookup('service:pix-companion');
pixCompanion.featureToggles = { isPixCompanionEnabled: false };

// When
pixCompanion._isExtensionEnabled = false;
Expand Down

0 comments on commit 4757b9b

Please sign in to comment.