From 62a67ed6aa5abbd7e712fb547410ae76fec13423 Mon Sep 17 00:00:00 2001 From: rouxxi Date: Tue, 14 May 2024 15:59:54 +0200 Subject: [PATCH 1/2] feat(junior): handle-environment-base-url --- orga/app/services/current-domain.js | 4 ++++ orga/tests/unit/services/current-domain_test.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/orga/app/services/current-domain.js b/orga/app/services/current-domain.js index 05cc1a357e6..8a2605e79aa 100644 --- a/orga/app/services/current-domain.js +++ b/orga/app/services/current-domain.js @@ -11,4 +11,8 @@ export default class CurrentDomainService extends Service { getExtension() { return last(location.hostname.split('.')); } + + getEnvironmentBaseUrl(stringUrl = window.location) { + return stringUrl.hostname.replace('orga', ''); + } } diff --git a/orga/tests/unit/services/current-domain_test.js b/orga/tests/unit/services/current-domain_test.js index a9c93ad2736..74e66c80505 100644 --- a/orga/tests/unit/services/current-domain_test.js +++ b/orga/tests/unit/services/current-domain_test.js @@ -32,5 +32,13 @@ module('Unit | Service | currentDomain', function (hooks) { // then assert.false(isFranceDomain); }); + + test('Get PR environment base url from domain', function (assert) { + const service = this.owner.lookup('service:currentDomain'); + + const url = new URL('https://orga-pr8887.review.pix.fr'); + const result = service.getEnvironmentBaseUrl(url); + assert.deepEqual(result, '-pr8887.review.pix.fr'); + }); }); }); From 7234cfa60e04c1b1ec497c7b5022af42e4fb864e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannick=20Fran=C3=A7ois?= Date: Tue, 14 May 2024 16:45:18 +0200 Subject: [PATCH 2/2] :recycle: refactor(junior): get junior url directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit co-authored-by: GUL co-authored-by: Gwenvaƫl Laskar --- orga/app/services/current-domain.js | 4 ++-- orga/app/services/url.js | 4 ++-- orga/config/environment.js | 1 - orga/sample.env | 15 --------------- orga/tests/acceptance/missions-list_test.js | 2 +- orga/tests/unit/services/current-domain_test.js | 9 +++++---- orga/tests/unit/services/url_test.js | 7 +------ 7 files changed, 11 insertions(+), 31 deletions(-) delete mode 100644 orga/sample.env diff --git a/orga/app/services/current-domain.js b/orga/app/services/current-domain.js index 8a2605e79aa..077aeb7dc62 100644 --- a/orga/app/services/current-domain.js +++ b/orga/app/services/current-domain.js @@ -12,7 +12,7 @@ export default class CurrentDomainService extends Service { return last(location.hostname.split('.')); } - getEnvironmentBaseUrl(stringUrl = window.location) { - return stringUrl.hostname.replace('orga', ''); + getJuniorBaseUrl(stringUrl = window.location) { + return `${stringUrl.protocol}//${stringUrl.hostname.replace('orga', 'junior')}`; } } diff --git a/orga/app/services/url.js b/orga/app/services/url.js index 42f85e74a5c..f3e5418136d 100644 --- a/orga/app/services/url.js +++ b/orga/app/services/url.js @@ -33,7 +33,6 @@ export default class Url extends Service { definedCampaignsRootUrl = ENV.APP.CAMPAIGNS_ROOT_URL; pixAppUrlWithoutExtension = ENV.APP.PIX_APP_URL_WITHOUT_EXTENSION; - pixJuniorUrl = ENV.APP.PIX_JUNIOR_URL; definedHomeUrl = ENV.rootURL; @@ -88,7 +87,8 @@ export default class Url extends Service { if (!schoolCode) { return ''; } - return `${this.pixJuniorUrl}/schools/${schoolCode}`; + + return `${this.currentDomain.getJuniorBaseUrl()}/schools/${schoolCode}`; } _computeShowcaseWebsiteUrl({ en: englishPath, fr: frenchPath }) { diff --git a/orga/config/environment.js b/orga/config/environment.js index 8e5ed27bb04..212db599f4a 100644 --- a/orga/config/environment.js +++ b/orga/config/environment.js @@ -50,7 +50,6 @@ module.exports = function (environment) { minValue: 0, }), PIX_APP_URL_WITHOUT_EXTENSION: process.env.PIX_APP_URL_WITHOUT_EXTENSION || 'https://app.pix.', - PIX_JUNIOR_URL: process.env.PIX_JUNIOR_URL || 'https://junior.pix.fr', API_ERROR_MESSAGES: { BAD_REQUEST: { CODE: '400', diff --git a/orga/sample.env b/orga/sample.env deleted file mode 100644 index 2ee393aa4af..00000000000 --- a/orga/sample.env +++ /dev/null @@ -1,15 +0,0 @@ -# This file is the minimal configuration file used by Dotenv to define the -# environment variables on localhost. -# -# Instructions: -# 1. copy this file as `.env` -# 2. edit the `.env` file with working values - -# URL of the Pix Junior application. -# -# If not present, the link to pix-junior for current school on missions page will not be available. -# -# presence: optional -# type: Url -# default: http://localhost:4205 -PIX_JUNIOR_URL=http://localhost:4205 diff --git a/orga/tests/acceptance/missions-list_test.js b/orga/tests/acceptance/missions-list_test.js index de0bd59e0bd..8b3c0d5b773 100644 --- a/orga/tests/acceptance/missions-list_test.js +++ b/orga/tests/acceptance/missions-list_test.js @@ -52,7 +52,7 @@ module('Acceptance | Missions List', function (hooks) { .dom( screen.getByRole('link', { name: this.intl.t('pages.missions.list.banner.copypaste-container.import-text') }), ) - .hasAttribute('href', 'https://junior.pix.fr/schools/BLABLA123'); + .hasAttribute('href', 'http://localhost/schools/BLABLA123'); }); module('display divisions', function () { diff --git a/orga/tests/unit/services/current-domain_test.js b/orga/tests/unit/services/current-domain_test.js index 74e66c80505..ca9f9ec4136 100644 --- a/orga/tests/unit/services/current-domain_test.js +++ b/orga/tests/unit/services/current-domain_test.js @@ -32,13 +32,14 @@ module('Unit | Service | currentDomain', function (hooks) { // then assert.false(isFranceDomain); }); + }); - test('Get PR environment base url from domain', function (assert) { + module('#getJuniorBaseUrl', function () { + test('should return url with junior instead of orga for review app', function (assert) { const service = this.owner.lookup('service:currentDomain'); - const url = new URL('https://orga-pr8887.review.pix.fr'); - const result = service.getEnvironmentBaseUrl(url); - assert.deepEqual(result, '-pr8887.review.pix.fr'); + const result = service.getJuniorBaseUrl(url); + assert.deepEqual(result, 'https://junior-pr8887.review.pix.fr'); }); }); }); diff --git a/orga/tests/unit/services/url_test.js b/orga/tests/unit/services/url_test.js index 8add0032734..b3ce77e386e 100644 --- a/orga/tests/unit/services/url_test.js +++ b/orga/tests/unit/services/url_test.js @@ -258,27 +258,22 @@ module('Unit | Service | url', function (hooks) { }); module('#pixJuniorSchoolUrl', function () { test('returns pix junior url for current organization', function (assert) { - // given const service = this.owner.lookup('service:url'); service.pixJuniorUrl = 'https://junior.pix.fr'; service.currentUser = { organization: { schoolCode: 'MINIPIXOU' } }; + service.currentDomain = { getJuniorBaseUrl: () => 'https://junior.pix.fr' }; - // when const pixJuniorSchoolUrl = service.pixJuniorSchoolUrl; - // then assert.strictEqual(pixJuniorSchoolUrl, 'https://junior.pix.fr/schools/MINIPIXOU'); }); test('returns empty string if the current organization has not any school code', function (assert) { - // given const service = this.owner.lookup('service:url'); service.pixJuniorUrl = 'https://junior.pix.fr'; service.currentUser = { organization: {} }; - // when const pixJuniorSchoolUrl = service.pixJuniorSchoolUrl; - // then assert.strictEqual(pixJuniorSchoolUrl, ''); }); });