diff --git a/packages/ripple-tide-landing-page/mapping/components.ts b/packages/ripple-tide-landing-page/mapping/components.ts index feb7dd00dd..d59c56d7b9 100644 --- a/packages/ripple-tide-landing-page/mapping/components.ts +++ b/packages/ripple-tide-landing-page/mapping/components.ts @@ -52,7 +52,7 @@ const mappings: { // Add reusable include on whitelisted paragraph types reusableParagraphTypes.forEach((k) => { - if (mappings[k].includes.length > 0) { + if (mappings[k]?.includes.length > 0) { mappings[k].includes = [ ...mappings[k].includes, ...mappings[k].includes.map((j) => diff --git a/packages/ripple-tide-landing-page/mapping/components/from-library/from-library-mapping.test.ts b/packages/ripple-tide-landing-page/mapping/components/from-library/from-library-mapping.test.ts new file mode 100644 index 0000000000..90be6decc4 --- /dev/null +++ b/packages/ripple-tide-landing-page/mapping/components/from-library/from-library-mapping.test.ts @@ -0,0 +1,219 @@ +import { expect, describe, it, jest } from '@jest/globals' +import mapping from './from-library-mapping' +import { useAppConfig } from '#imports' + +const RAW = { + links: { + self: { + href: 'https://nginx-php.pr-1691.content-vic.sdp4.sdp.vic.gov.au/api/v1/paragraph/from_library/ebc72f3d-17d7-4251-8136-6883bb707472?resourceVersion=id%3A5890392' + } + }, + meta: { + target_revision_id: 5890392, + drupal_internal__target_id: 3341760 + }, + drupal_internal__id: 3341760, + drupal_internal__revision_id: 5890392, + langcode: 'en', + status: true, + created: '2024-09-03T03:48:15+00:00', + parent_id: '41071', + parent_type: 'node', + parent_field_name: 'field_landing_page_component', + behavior_settings: [], + default_langcode: true, + revision_translation_affected: null, + field_reusable_paragraph: { + links: { + self: { + href: 'https://nginx-php.pr-1691.content-vic.sdp4.sdp.vic.gov.au/api/v1/paragraphs_library_item/paragraphs_library_item/9600093a-cb86-497b-be21-a1f05878c7ab?resourceVersion=id%3A2' + } + }, + meta: { + drupal_internal__target_id: 2 + }, + drupal_internal__id: 2, + drupal_internal__revision_id: 2, + langcode: 'en', + revision_created: '2024-08-21T05:27:59+00:00', + revision_log: null, + status: true, + label: 'BDM: Proof of ID - Acceptable documents (pp & dl)', + created: '2024-08-21T05:26:09+00:00', + changed: '2024-08-21T05:27:59+00:00', + default_langcode: true, + revision_translation_affected: true, + metatag: [ + { + tag: 'link', + attributes: { + rel: 'canonical', + href: 'https://nginx-php.pr-1691.content-vic.sdp4.sdp.vic.gov.au/api/v1/node/landing_page/f4d4c76e-4fb9-4dea-a157-593f3ee9e1f3' + } + }, + { + tag: 'meta', + attributes: { + property: 'og:locale', + content: 'en-AU' + } + } + ], + paragraphs: { + links: { + self: { + href: 'https://nginx-php.pr-1691.content-vic.sdp4.sdp.vic.gov.au/api/v1/paragraph/basic_text/28ad7c12-709d-41a7-8b41-26e729687412?resourceVersion=id%3A5890329' + } + }, + meta: { + target_revision_id: 5890329, + drupal_internal__target_id: 3341733 + }, + drupal_internal__id: 3341733, + drupal_internal__revision_id: 5890329, + langcode: 'en', + status: true, + created: '2024-08-21T05:26:09+00:00', + parent_id: '2', + parent_type: 'paragraphs_library_item', + parent_field_name: 'paragraphs', + behavior_settings: [], + default_langcode: true, + revision_translation_affected: true, + field_paragraph_body: { + value: + '

One of the easiest ways to prove your identity is by presenting your driver licence (if it confirms your residential address) and your Passport.

Example driver licence
An Australian passport

 

 

 

 

See the other ways to prove your identity.

', + format: 'rich_text', + processed: + '

One of the easiest ways to prove your identity is by presenting your driver licence (if it confirms your residential address) and your Passport.

Example driver licence
An Australian passport

 

 

 

 

See the other ways to prove your identity.

' + }, + id: '28ad7c12-709d-41a7-8b41-26e729687412', + type: 'paragraph--basic_text' + }, + id: '9600093a-cb86-497b-be21-a1f05878c7ab', + type: 'paragraphs_library_item--paragraphs_library_item' + }, + id: 'ebc72f3d-17d7-4251-8136-6883bb707472', + type: 'paragraph--from_library' +} + +const UNSUPPORTED = { + links: { + self: { + href: 'https://nginx-php.pr-1691.content-vic.sdp4.sdp.vic.gov.au/api/v1/paragraph/from_library/ebc72f3d-17d7-4251-8136-6883bb707472?resourceVersion=id%3A5890392' + } + }, + meta: { + target_revision_id: 5890392, + drupal_internal__target_id: 3341760 + }, + drupal_internal__id: 3341760, + drupal_internal__revision_id: 5890392, + langcode: 'en', + status: true, + created: '2024-09-03T03:48:15+00:00', + parent_id: '41071', + parent_type: 'node', + parent_field_name: 'field_landing_page_component', + behavior_settings: [], + default_langcode: true, + revision_translation_affected: null, + field_reusable_paragraph: { + links: { + self: { + href: 'https://nginx-php.pr-1691.content-vic.sdp4.sdp.vic.gov.au/api/v1/paragraphs_library_item/paragraphs_library_item/9600093a-cb86-497b-be21-a1f05878c7ab?resourceVersion=id%3A2' + } + }, + meta: { + drupal_internal__target_id: 2 + }, + drupal_internal__id: 2, + drupal_internal__revision_id: 2, + langcode: 'en', + revision_created: '2024-08-21T05:27:59+00:00', + revision_log: null, + status: true, + label: 'BDM: Proof of ID - Acceptable documents (pp & dl)', + created: '2024-08-21T05:26:09+00:00', + changed: '2024-08-21T05:27:59+00:00', + default_langcode: true, + revision_translation_affected: true, + metatag: [ + { + tag: 'link', + attributes: { + rel: 'canonical', + href: 'https://nginx-php.pr-1691.content-vic.sdp4.sdp.vic.gov.au/api/v1/node/landing_page/f4d4c76e-4fb9-4dea-a157-593f3ee9e1f3' + } + }, + { + tag: 'meta', + attributes: { + property: 'og:locale', + content: 'en-AU' + } + } + ], + paragraphs: { + links: { + self: { + href: 'https://nginx-php.pr-1691.content-vic.sdp4.sdp.vic.gov.au/api/v1/paragraph/basic_text/28ad7c12-709d-41a7-8b41-26e729687412?resourceVersion=id%3A5890329' + } + }, + meta: { + target_revision_id: 5890329, + drupal_internal__target_id: 3341733 + }, + drupal_internal__id: 3341733, + drupal_internal__revision_id: 5890329, + langcode: 'en', + status: true, + created: '2024-08-21T05:26:09+00:00', + parent_id: '2', + parent_type: 'xxparagraphs_library_item', + parent_field_name: 'paragraphs', + behavior_settings: [], + default_langcode: true, + revision_translation_affected: true, + field_paragraph_body: { + value: + '

One of the easiest ways to prove your identity is by presenting your driver licence (if it confirms your residential address) and your Passport.

Example driver licence
An Australian passport

 

 

 

 

See the other ways to prove your identity.

', + format: 'rich_text', + processed: + '

One of the easiest ways to prove your identity is by presenting your driver licence (if it confirms your residential address) and your Passport.

Example driver licence
An Australian passport

 

 

 

 

See the other ways to prove your identity.

' + }, + id: '28ad7c12-709d-41a7-8b41-26e729687412', + type: 'xxparagraph--basic_text' + }, + id: '9600093a-cb86-497b-be21-a1f05878c7ab', + type: 'xxparagraphs_library_item--paragraphs_library_item' + }, + id: 'ebc72f3d-17d7-4251-8136-6883bb707472', + type: 'xxparagraph--from_library' +} + +const MAPPED = { + component: 'TideLandingPageContent', + id: '3341733', + internalAnchors: [], + props: { + html: '

One of the easiest ways to prove your identity is by presenting your driver licence (if it confirms your residential address) and your Passport.

Example driver licence
An Australian passport

 

 

 

 

See the other ways to prove your identity.

' + } +} + +jest.mock('#imports', () => ({ + useAppConfig: jest.fn() +})) +;(useAppConfig as jest.Mock).mockReturnValue({ ripple: { site: '123' } }) + +describe('From library component mapping', () => { + it('transforms a raw json api from_library paragraph to mapped component', async () => { + expect(mapping.mapping(RAW, {}, {})).toEqual(MAPPED) + }) + + it('logs a console error when a paragraph type is not supported', async () => { + const spy = jest.spyOn(console, 'error') + mapping.mapping(UNSUPPORTED, {}, {}) + expect(spy).toHaveBeenCalled() + }) +}) diff --git a/packages/ripple-tide-landing-page/mapping/components/from-library/from-library-mapping.ts b/packages/ripple-tide-landing-page/mapping/components/from-library/from-library-mapping.ts index 49edea6ce8..84a8edd9c3 100644 --- a/packages/ripple-tide-landing-page/mapping/components/from-library/from-library-mapping.ts +++ b/packages/ripple-tide-landing-page/mapping/components/from-library/from-library-mapping.ts @@ -8,7 +8,10 @@ interface TideFromLibrary { } export const fromLibraryMapping = ( - field: { field_reusable_paragraph: { paragraphs: TideFromLibrary } }, + field: { + field_reusable_paragraph: { paragraphs: TideFromLibrary } + id: string | null + }, page: any, tidePageApi: any ): TideDynamicPageComponent => { diff --git a/packages/ripple-tide-webform/mapping/webforms-mapping.ts b/packages/ripple-tide-webform/mapping/webforms-mapping.ts index edc7d5206b..6f747f4bb4 100644 --- a/packages/ripple-tide-webform/mapping/webforms-mapping.ts +++ b/packages/ripple-tide-webform/mapping/webforms-mapping.ts @@ -6,6 +6,7 @@ import { } from './../server/webform-utils' import { getAdvancedAddressMapping } from './webforms-address' import type { TideWebformElement, ApiWebForm, ApiPage } from './../types' +import { useAppConfig } from '#imports' interface CustomInputsConfig { [key: string]: { @@ -14,8 +15,8 @@ interface CustomInputsConfig { } } -const appConfig = useAppConfig().ripple as CustomInputsConfig -const customInputs: CustomInputsConfig = appConfig.customInputs || {} +const appConfig = useAppConfig()?.ripple as CustomInputsConfig +const customInputs: CustomInputsConfig = appConfig?.customInputs || {} export const getFormSchemaFromMapping = async ( webform: ApiWebForm, diff --git a/packages/ripple-tide-webform/server/webform-utils.ts b/packages/ripple-tide-webform/server/webform-utils.ts index f2d5ea3ff3..d8e62c31e2 100644 --- a/packages/ripple-tide-webform/server/webform-utils.ts +++ b/packages/ripple-tide-webform/server/webform-utils.ts @@ -1,4 +1,3 @@ -// @ts-expect-error ts7016 monorepo ref import { logger } from '@dpc-sdp/ripple-tide-api' import { getConditionals } from './../mapping/webform-conditional-logic' import { getValidation } from './../mapping/webform-validation'