From 9180e37ab324100e4325c57a8dbef1dcbec90f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20PAILHAREY?= <rpailharey@grandlyon.com> Date: Mon, 30 Oct 2023 16:21:12 +0000 Subject: [PATCH] feat: added ecolyo links in custom popups --- src/services/customPopup.service.spec.ts | 17 ++++++++++++++++- src/services/customPopup.service.ts | 6 ++++-- tests/__mocks__/customPopup.mock.ts | 8 ++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/services/customPopup.service.spec.ts b/src/services/customPopup.service.spec.ts index 11d1d9cc7..4bb35e136 100644 --- a/src/services/customPopup.service.spec.ts +++ b/src/services/customPopup.service.spec.ts @@ -1,5 +1,8 @@ import mockClient from 'tests/__mocks__/client.mock' -import { mockCustomPopup } from 'tests/__mocks__/customPopup.mock' +import { + mockCustomPopup, + mockCustomPopupWithLink, +} from 'tests/__mocks__/customPopup.mock' import CustomPopupService from './customPopup.service' jest.mock('services/environment.service', () => { @@ -17,6 +20,18 @@ describe('PartnersInfo service', () => { expect(result).toBe(mockCustomPopup) }) + it('should return customPopup data with replaced link', async () => { + mockClient + .getStackClient() + .fetchJSON.mockResolvedValueOnce(mockCustomPopupWithLink) + const result = await customPopupService.getCustomPopup() + expect(result).toStrictEqual({ + ...mockCustomPopupWithLink, + description: + '<p>Allez voir la page <a href="./#/ecogestures" target="_self">astuces</a> !!</p>', + }) + }) + it('should return an error', async () => { mockClient.getStackClient().fetchJSON.mockRejectedValue(new Error()) let res diff --git a/src/services/customPopup.service.ts b/src/services/customPopup.service.ts index f09472520..89f0f787d 100644 --- a/src/services/customPopup.service.ts +++ b/src/services/customPopup.service.ts @@ -29,10 +29,12 @@ export default class CustomPopupService { : REMOTE_ORG_ECOLYO_AGENT_CUSTOM_POPUP_REC try { logApp.info('[Initialization] Getting CustomPopup') - const result = await this._client + const result: CustomPopup = await this._client .getStackClient() .fetchJSON('GET', remoteUrl) - return result as CustomPopup + + result.description = result.description.replace(/{cozyUrl}/g, './#/') + return result } catch (error) { const errorMessage = `getCustomPopup: Failed to get custom popup:${JSON.stringify( error diff --git a/tests/__mocks__/customPopup.mock.ts b/tests/__mocks__/customPopup.mock.ts index 65c9b9d93..9cb45df35 100644 --- a/tests/__mocks__/customPopup.mock.ts +++ b/tests/__mocks__/customPopup.mock.ts @@ -7,6 +7,14 @@ export const mockCustomPopup: CustomPopup = { endDate: '2099-10-04T15:10:53.219+02:00', } +export const mockCustomPopupWithLink: CustomPopup = { + popupEnabled: true, + title: 'Bold title', + description: + '<p>Allez voir la page <a href="{cozyUrl}ecogestures" target="_self">astuces</a> !!</p>', + endDate: '2099-10-04T15:10:53.219+02:00', +} + export const mockCustomPopupOff: CustomPopup = { popupEnabled: false, title: '', -- GitLab