diff --git a/orga/app/services/current-domain.js b/orga/app/services/current-domain.js index 05cc1a357e6..077aeb7dc62 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('.')); } + + 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 a9c93ad2736..ca9f9ec4136 100644 --- a/orga/tests/unit/services/current-domain_test.js +++ b/orga/tests/unit/services/current-domain_test.js @@ -33,4 +33,13 @@ module('Unit | Service | currentDomain', function (hooks) { assert.false(isFranceDomain); }); }); + + 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.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, ''); }); });