Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VAMS-20163 news release contact number #919

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/data/queries/pressRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'media--document',
]),
'field_press_release_contact',
'field_press_release_contact.field_telephone',
'field_listing',
'field_administration',
...getNestedIncludes('field_pdf_version', 'media--document'),
Expand All @@ -43,7 +44,7 @@
return entity
}

export const formatter: QueryFormatter<NodePressRelease, PressRelease> = (

Check failure on line 47 in src/data/queries/pressRelease.ts

View workflow job for this annotation

GitHub Actions / Setup and Test

Type '(entity: NodePressRelease) => { releaseDate: string; pdfVersion: any; introText: string; address: FieldAddress; fullText: string; contacts: { id: string; description: string; name: string; email: string; numbers: { ...; }[]; }[]; ... 12 more ...; lastUpdated: string; }' is not assignable to type 'QueryFormatter<NodePressRelease, PressRelease>'.
entity: NodePressRelease
) => {
const downloads = entity.field_press_release_downloads
Expand Down Expand Up @@ -75,14 +76,22 @@
}
})
: []
// Setting phone numbers to an array even though there is only one in case multiple are added in the future.
const formattedContacts = entity.field_press_release_contact
? entity.field_press_release_contact.map((contact) => {
return {
id: contact?.id || null,
description: contact?.field_description || null,
name: contact?.title || null,
email: contact?.field_email_address || null,
phone: contact?.field_phone_number || null,
numbers: [contact?.field_telephone].map((number) => {
return {
id: number?.id || null,
type: number?.field_phone_number_type || null,
number: number?.field_phone_number || null,
ext: number?.field_phone_extension || null,
Comment on lines +89 to +92
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 What happens if these are false-y? I can't think of a reason we'd ever want empty strings for any of these, but this will turn those empty strings into null. 🤔 Probably fine? 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also dubious about this, but was trying to follow style/pattern. Getting existential about the identity of a defect ticket, it was feeling weird to shift that style for this work. Mostly because I would then feel the need to change other un-related areas to match. I think next steps around this sort of thing for me at least would be to hook my local drupal up to local next to start playing around with different missing data states.

}
}),
}
})
: []
Expand Down
43 changes: 42 additions & 1 deletion src/data/queries/tests/__snapshots__/newsStory.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,50 @@ exports[`node--news_story formatData outputs formatted data 1`] = `
"field_meta_tags": null,
"field_name_first": "Keith",
"field_office": null,
"field_phone_number": null,
"field_photo_allow_hires_download": false,
"field_suffix": null,
"field_telephone": {
"behavior_settings": [],
"breadcrumbs": [],
"content_translation_changed": "2024-11-25T18:00:06+00:00",
"content_translation_outdated": false,
"content_translation_source": "und",
"created": "2024-11-25T18:00:06+00:00",
"default_langcode": true,
"drupal_internal__id": 163647,
"drupal_internal__revision_id": 1561519,
"field_phone_extension": null,
"field_phone_label": null,
"field_phone_number": "412-360-1479",
"field_phone_number_type": "phone",
"id": "a96f65e2-5a82-4b59-b249-25c634e93108",
"langcode": "en",
"links": {
"self": {
"href": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/paragraph/phone_number/a96f65e2-5a82-4b59-b249-25c634e93108?resourceVersion=id%3A1561519",
},
},
"paragraph_type": {
"id": "9c5d2698-f605-42f2-a516-15949b84d17f",
"resourceIdObjMeta": {
"drupal_internal__target_id": "phone_number",
},
"type": "paragraphs_type--paragraphs_type",
},
"parent_field_name": "field_telephone",
"parent_id": "94",
"parent_type": "node",
"relationshipNames": [
"paragraph_type",
],
"resourceIdObjMeta": {
"drupal_internal__target_id": 163647,
"target_revision_id": 1561519,
},
"revision_translation_affected": null,
"status": true,
"type": "paragraph--phone_number",
},
"id": "c76037be-ebb0-4338-9b31-973a76958929",
"langcode": "en",
"links": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,22 @@ exports[`node--press_release formatData output formatted data 1`] = `
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/wilmington-health-care/news-releases/wilmington-vamc-2019-annual-report",
},
],
"contacts": [],
"contacts": [
{
"description": "Public Affairs Specialist",
"email": "[email protected]",
"id": "7ecb5154-7e2c-4c16-a171-bb3710a4dab7",
"name": "Sheila Tunney",
"numbers": [
{
"ext": null,
"id": "a96f65e2-5a82-4b59-b249-25c634e93108",
"number": "412-360-1479",
"type": "phone",
},
],
},
],
"downloads": [],
"entityId": 18141,
"entityPath": "/wilmington-health-care/news-releases/wilmington-vamc-2019-annual-report",
Expand Down
36 changes: 35 additions & 1 deletion src/data/queries/tests/pressRelease.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,48 @@ describe(`${RESOURCE_TYPES.PRESS_RELEASE} formatData`, () => {
expect(formattedData.administration.name).toBeNull()
expect(formattedData.pdfVersion).toBeNull()
})
test('handles missing or null contact fields correctly', () => {
const modifiedMockContact: NodePressRelease = {
...nodePressReleaseMock,
field_press_release_contact: [
{
...nodePressReleaseMock.field_press_release_contact[0],
id: undefined,
field_description: undefined,
title: undefined,
field_email_address: undefined,
field_telephone: {
...nodePressReleaseMock.field_press_release_contact[0]
.field_telephone,
id: undefined,
field_phone_number_type: undefined,
field_phone_number: undefined,
field_phone_extension: undefined,
},
},
],
}
const formattedData = queries.formatData(
RESOURCE_TYPES.PRESS_RELEASE,
modifiedMockContact
)
expect(formattedData.contacts[0].id).toBeNull()
expect(formattedData.contacts[0].description).toBeNull()
expect(formattedData.contacts[0].name).toBeNull()
expect(formattedData.contacts[0].email).toBeNull()
expect(formattedData.contacts[0].numbers[0].id).toBeNull()
expect(formattedData.contacts[0].numbers[0].type).toBeNull()
expect(formattedData.contacts[0].numbers[0].number).toBeNull()
expect(formattedData.contacts[0].numbers[0].ext).toBeNull()
})
})

describe('DrupalJsonApiParams configuration for pressRelease', () => {
test('params function sets the correct include fields', () => {
const paramsInstance = params()
const queryString = decodeURIComponent(paramsInstance.getQueryString())
expect(queryString).toMatch(
/include=field_press_release_downloads,field_press_release_downloads.image,field_press_release_downloads.field_document,field_press_release_contact,field_listing,field_administration,field_pdf_version,field_pdf_version.field_document/
/include=field_press_release_downloads,field_press_release_downloads.image,field_press_release_downloads.field_document,field_press_release_contact,field_press_release_contact.field_telephone,field_listing,field_administration,field_pdf_version,field_pdf_version.field_document/
)
})
})
41 changes: 40 additions & 1 deletion src/mocks/newsStory.mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,46 @@
"field_last_saved_by_editor": "2019-11-12T20:21:16+00:00",
"field_meta_tags": null,
"field_name_first": "Keith",
"field_phone_number": null,
"field_telephone": {
"type": "paragraph--phone_number",
"id": "a96f65e2-5a82-4b59-b249-25c634e93108",
"drupal_internal__id": 163647,
"drupal_internal__revision_id": 1561519,
"langcode": "en",
"status": true,
"created": "2024-11-25T18:00:06+00:00",
"parent_id": "94",
"parent_type": "node",
"parent_field_name": "field_telephone",
"behavior_settings": [],
"default_langcode": true,
"revision_translation_affected": null,
"breadcrumbs": [],
"content_translation_source": "und",
"content_translation_outdated": false,
"content_translation_changed": "2024-11-25T18:00:06+00:00",
"field_phone_extension": null,
"field_phone_label": null,
"field_phone_number": "412-360-1479",
"field_phone_number_type": "phone",
"links": {
"self": {
"href": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/paragraph/phone_number/a96f65e2-5a82-4b59-b249-25c634e93108?resourceVersion=id%3A1561519"
}
},
"resourceIdObjMeta": {
"target_revision_id": 1561519,
"drupal_internal__target_id": 163647
},
"paragraph_type": {
"type": "paragraphs_type--paragraphs_type",
"id": "9c5d2698-f605-42f2-a516-15949b84d17f",
"resourceIdObjMeta": {
"drupal_internal__target_id": "phone_number"
}
},
"relationshipNames": ["paragraph_type"]
},
"field_photo_allow_hires_download": false,
"field_suffix": null,
"links": {
Expand Down
165 changes: 164 additions & 1 deletion src/mocks/pressRelease.mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,170 @@
}
}
},
"field_press_release_contact": [],
"field_press_release_contact": [
{
"type": "node--person_profile",
"id": "7ecb5154-7e2c-4c16-a171-bb3710a4dab7",
"drupal_internal__nid": 94,
"drupal_internal__vid": 988884,
"sticky": false,
"default_langcode": true,
"langcode": "en",
"status": true,
"title": "Sheila Tunney",
"created": "2019-02-26T05:47:15+00:00",
"changed": "2024-11-25T18:00:07+00:00",
"breadcrumbs": [
{
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/",
"title": "Home",
"options": []
},
{
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/pittsburgh-health-care",
"title": "VA Pittsburgh Health Care",
"options": []
},
{
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/pittsburgh-health-care/staff-profiles/sheila-tunney",
"title": "Sheila Tunney",
"options": []
}
],
"moderation_state": "published",
"expiration_date": null,
"warning_date": null,
"metatag": [
{
"tag": "meta",
"attributes": {
"name": "title",
"content": "Sheila Tunney | VA Pittsburgh health care | Veterans Affairs"
}
},
{
"tag": "link",
"attributes": {
"rel": "image_src",
"href": "https://www.va.gov/img/design/logo/va-og-image.png"
}
},
{
"tag": "meta",
"attributes": {
"property": "og:site_name",
"content": "Veterans Affairs"
}
},
{
"tag": "meta",
"attributes": {
"property": "og:title",
"content": "Sheila Tunney | VA Pittsburgh health care | Veterans Affairs"
}
},
{
"tag": "meta",
"attributes": {
"name": "twitter:card",
"content": "summary_large_image"
}
},
{
"tag": "meta",
"attributes": {
"name": "twitter:site",
"content": "@DeptVetAffairs"
}
},
{
"tag": "meta",
"attributes": {
"name": "twitter:title",
"content": "Sheila Tunney | VA Pittsburgh health care | Veterans Affairs"
}
}
],
"path": {
"alias": "/pittsburgh-health-care/staff-profiles/sheila-tunney",
"pid": 214,
"langcode": "en"
},
"field_body": null,
"field_complete_biography_create": false,
"field_description": "Public Affairs Specialist",
"field_email_address": "[email protected]",
"field_intro_text": null,
"field_last_name": "Tunney",
"field_last_saved_by_an_editor": "2024-05-02T13:03:19+00:00",
"field_meta_tags": null,
"field_name_first": "Sheila",
"field_photo_allow_hires_download": false,
"field_suffix": null,
"links": {
"self": {
"href": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/node/person_profile/7ecb5154-7e2c-4c16-a171-bb3710a4dab7?resourceVersion=id%3A934975"
}
},
"node_type": {
"type": "node_type--node_type",
"id": "89b07673-7fd5-4292-8fba-58cc10c4e3ec",
"resourceIdObjMeta": {
"drupal_internal__target_id": "person_profile"
}
},
"field_administration": {
"type": "taxonomy_term--administration",
"id": "87832236-1e54-4ce3-8141-8dec27c8a9a7",
"resourceIdObjMeta": {
"drupal_internal__target_id": 12
}
},
"field_complete_biography": null,
"field_media": null,
"field_office": null,
"field_telephone": {
"type": "paragraph--phone_number",
"id": "a96f65e2-5a82-4b59-b249-25c634e93108",
"drupal_internal__id": 163647,
"drupal_internal__revision_id": 1561519,
"langcode": "en",
"status": true,
"created": "2024-11-25T18:00:06+00:00",
"parent_id": "94",
"parent_type": "node",
"parent_field_name": "field_telephone",
"behavior_settings": [],
"default_langcode": true,
"revision_translation_affected": null,
"breadcrumbs": [],
"content_translation_source": "und",
"content_translation_outdated": false,
"content_translation_changed": "2024-11-25T18:00:06+00:00",
"field_phone_extension": null,
"field_phone_label": null,
"field_phone_number": "412-360-1479",
"field_phone_number_type": "phone",
"links": {
"self": {
"href": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/paragraph/phone_number/a96f65e2-5a82-4b59-b249-25c634e93108?resourceVersion=id%3A1561519"
}
},
"resourceIdObjMeta": {
"target_revision_id": 1561519,
"drupal_internal__target_id": 163647
},
"paragraph_type": {
"type": "paragraphs_type--paragraphs_type",
"id": "9c5d2698-f605-42f2-a516-15949b84d17f",
"resourceIdObjMeta": {
"drupal_internal__target_id": "phone_number"
}
},
"relationshipNames": ["paragraph_type"]
}
}
],
"field_press_release_downloads": [],
"field_administration": {
"drupal_internal__tid": 188,
Expand Down
Loading
Loading