diff --git a/src/services/customPopup.service.spec.ts b/src/services/customPopup.service.spec.ts index 11d1d9cc798e0e93b399a36b6a5e7d5a811d7a80..4bb35e136fe92686622e87c30d79006f11407259 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 f09472520760a6cca1f6cb286c051605016c0d05..89f0f787dd669b7229634936dec267916dc5e1e0 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 65c9b9d93101881fb1b78e2fc1bea274fca164f6..9cb45df355382f8200bfad24f25afb6b471b695a 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: '',