Skip to content

Commit

Permalink
[TECH] ♻️ Construit l'URL pour pix junior depuis l'URL courante plutô…
Browse files Browse the repository at this point in the history
…t qu'une variable

 #8915
  • Loading branch information
pix-service-auto-merge committed May 15, 2024
2 parents 1b04547 + 7234cfa commit 780a660
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 25 deletions.
4 changes: 4 additions & 0 deletions orga/app/services/current-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`;
}
}
4 changes: 2 additions & 2 deletions orga/app/services/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 }) {
Expand Down
1 change: 0 additions & 1 deletion orga/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
15 changes: 0 additions & 15 deletions orga/sample.env

This file was deleted.

2 changes: 1 addition & 1 deletion orga/tests/acceptance/missions-list_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
9 changes: 9 additions & 0 deletions orga/tests/unit/services/current-domain_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
7 changes: 1 addition & 6 deletions orga/tests/unit/services/url_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
});
});
Expand Down

0 comments on commit 780a660

Please sign in to comment.