Skip to content

Commit

Permalink
Add contact consent to sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
chopkinsmade committed Nov 5, 2024
1 parent 8fd31b3 commit 3cce0a0
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 118 deletions.
71 changes: 32 additions & 39 deletions src/client/modules/Contacts/ContactDetails/ConsentDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,44 @@ import React from 'react'
import Table from '@govuk-react/table'

import { SummaryTable } from '../../../components'
import { transformContactConsents } from './transformers'

const getConsentRows = (consentData) => {
const domainGroupedConsent = Object.groupBy(
consentData,
({ consentDomain }) => consentDomain
)
const domainRows = Object.entries(domainGroupedConsent).map((domain) => {
{
const domainTitle = domain[0]
const domainTopics = domain[1]
return domainTopics.map((topic, index) => (
<Table.Row key={`domain_${index}`} data-test={`domain_${domainTitle}`}>
{index == 0 && <td rowSpan={domainTopics.length}>{domainTitle}</td>}
<Table.Cell>{topic.topic}</Table.Cell>
<Table.Cell>
{topic.emailContactConsent || topic.telephoneContactConsent
? 'Yes'
: 'No'}
</Table.Cell>
const ConsentTableRows = ({ consents }) => (
<>
<Table.Row>
<Table.CellHeader>Domain</Table.CellHeader>
<Table.CellHeader>Topic</Table.CellHeader>
<Table.CellHeader>Consent Given</Table.CellHeader>
</Table.Row>

{consents.map((consent) =>
consent.topics.map((topic) => (
<Table.Row>
<Table.Cell>{consent.domain}</Table.Cell>
<Table.Cell>{topic.name}</Table.Cell>
<Table.Cell>{topic.consent ? 'Yes' : 'No'}</Table.Cell>
</Table.Row>
))
}
})
)}
</>
)

const ConsentDetails = ({ contact }) => {
const consents = transformContactConsents(contact)
return (
<>
<Table.Row>
<Table.CellHeader>Domain</Table.CellHeader>
<Table.CellHeader>Topic</Table.CellHeader>
<Table.CellHeader>Consent Given</Table.CellHeader>
</Table.Row>
{domainRows}
</>
<SummaryTable
data-test="contact-consent-table"
caption={'Contact consents'}
>
{consents ? (
<ConsentTableRows consents={consents} />
) : (
<Table.Row data-test="no-contact-consents">
<Table.Cell>No consent data is available for this contact</Table.Cell>
</Table.Row>
)}
</SummaryTable>
)
}

const ConsentDetails = ({ contact }) => (
<SummaryTable data-test="contact-consent-table" caption={'Contact consents'}>
{contact.consentData ? (
getConsentRows(contact.consentData)
) : (
<Table.Row data-test="no-contact-consents">
<Table.Cell>No consent data is available for this contact</Table.Cell>
</Table.Row>
)}
</SummaryTable>
)
export default ConsentDetails
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'core-js/proposals/array-grouping-v2'
import { transformContactConsents } from '../transformers'

describe('transformContactConsents', () => {
context('When a falsey contact is passed', () => {
it('Should return undefined', () => {
expect(transformContactConsents(undefined)).to.be.undefined
})
})
context('When a contact has no consent data', () => {
it('Should return undefined', () => {
expect(transformContactConsents({})).to.be.undefined
})
})
context('When a contact with a single unique value for domain', () => {
it('Should return a single domain with a single topic', () => {
expect(
transformContactConsents({
consentData: [
{
topic: 'Topic 1',
sourceSystem: 'System A',
consentDomain: 'International',
emailContactConsent: false,
telephoneContactConsent: false,
},
],
})
).to.deep.equal([
{
domain: 'International',
topics: [{ consent: false, name: 'Topic 1' }],
},
])
})
})
context('When a contact has multiple values for domain', () => {
it('Should return a single domain with multiple topics', () => {
expect(
transformContactConsents({
consentData: [
{
topic: 'Topic 1',
sourceSystem: 'System A',
consentDomain: 'International',
emailContactConsent: false,
telephoneContactConsent: false,
},
{
topic: 'Topic 2',
sourceSystem: 'System A',
consentDomain: 'International',
emailContactConsent: false,
telephoneContactConsent: true,
},
],
})
).to.deep.equal([
{
domain: 'International',
topics: [
{ consent: false, name: 'Topic 1' },
{
consent: true,
name: 'Topic 2',
},
],
},
])
})
})
})
18 changes: 18 additions & 0 deletions src/client/modules/Contacts/ContactDetails/transformers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const transformContactConsents = (contact) => {
if (!contact || !contact.consentData) {
return undefined
}

const domainGroupedConsent = Object.groupBy(
contact.consentData,
({ consentDomain }) => consentDomain
)

return Object.entries(domainGroupedConsent).map((domain) => ({
domain: domain[0],
topics: domain[1].map((topic) => ({
consent: topic.emailContactConsent || topic.telephoneContactConsent,
name: topic.topic,
})),
}))
}
2 changes: 1 addition & 1 deletion test/end-to-end/cypress/specs/DIT/companies-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Contacts', () => {

cy.contains('You have successfully added a new contact Company Contact')

assertKeyValueTable('bodyMainContent', {
assertKeyValueTable('contact-details-table', {
'Job title': 'Coffee machine operator',
'Phone number': '44 0778877778800',
Address: '100 Path, A town, 12345, United States',
Expand Down
8 changes: 8 additions & 0 deletions test/functional/cypress/specs/contacts/details-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ describe('View contact details', () => {
.should('have.attr', 'href', contacts.edit(completeUKContact.id))
})

it('should render consent table with consent data', () => {
cy.get('[data-test=no-contact-consents]').should('not.exist')
})

it('should render the archive container', () => {
cy.get('[data-test=archive-contact-container]').should('exist')
cy.get('[data-test=archive-header]')
Expand Down Expand Up @@ -204,6 +208,10 @@ describe('View contact details', () => {
})
})

it('should render consent table without consent data', () => {
cy.get('[data-test=no-contact-consents]').should('exist')
})

it('should not render the Edit Contact button', () => {
cy.get('[data-test=edit-contact-button]').should('not.exist')
})
Expand Down
77 changes: 42 additions & 35 deletions test/sandbox/fixtures/v3/contact/contact-by-id-uk.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
{
"id":"f3d19ea7-d4cf-43e0-8e97-755c57cae313",
"title":null,
"first_name":"Joseph",
"last_name":"Woof",
"name":"Joseph Woof",
"job_title":"Dog master",
"company":{
"name":"Zboncak Group|271eb29e-425b-4cd8-b386-3208c3a5f978",
"id":"4cd4128b-1bad-4f1e-9146-5d4678c6a018"
"id": "f3d19ea7-d4cf-43e0-8e97-755c57cae313",
"title": null,
"first_name": "Joseph",
"last_name": "Woof",
"name": "Joseph Woof",
"job_title": "Dog master",
"company": {
"name": "Zboncak Group|271eb29e-425b-4cd8-b386-3208c3a5f978",
"id": "4cd4128b-1bad-4f1e-9146-5d4678c6a018"
},
"adviser":{
"name":"DBT Staff",
"first_name":"DBT",
"last_name":"Staff",
"id":"7d19d407-9aec-4d06-b190-d3f404627f21"
"adviser": {
"name": "DBT Staff",
"first_name": "DBT",
"last_name": "Staff",
"id": "7d19d407-9aec-4d06-b190-d3f404627f21"
},
"primary":true,
"telephone_countrycode":"",
"telephone_number":"",
"full_telephone_number":"222 3453454",
"email":"[email protected]",
"address_same_as_company":false,
"primary": true,
"telephone_countrycode": "",
"telephone_number": "",
"full_telephone_number": "222 3453454",
"email": "[email protected]",
"address_same_as_company": false,
"address_1": null,
"address_2":null,
"address_town":null,
"address_county":null,
"address_2": null,
"address_town": null,
"address_county": null,
"address_country": {
"id": "80756b9a-5d95-e211-a939-e4115bead28a"
},
"address_postcode":"E14 8RJ",
"telephone_alternative":null,
"email_alternative":null,
"notes":null,
"accepts_dit_email_marketing":false,
"archived":false,
"archived_documents_url_path":"/document/123",
"archived_on":null,
"archived_reason":null,
"archived_by":null,
"created_on":"2019-02-04T15:59:14.267412Z",
"modified_on":"2019-02-05T13:17:23.112153Z"
"address_postcode": "E14 8RJ",
"telephone_alternative": null,
"email_alternative": null,
"notes": null,
"accepts_dit_email_marketing": false,
"archived": false,
"archived_documents_url_path": "/document/123",
"archived_on": null,
"archived_reason": null,
"archived_by": null,
"created_on": "2019-02-04T15:59:14.267412Z",
"modified_on": "2019-02-05T13:17:23.112153Z",
"consent_data": [
{
"source_system": "System A",
"consent_domain": "Domestic",
"consent": false
}
]
}
93 changes: 50 additions & 43 deletions test/sandbox/fixtures/v3/contact/contact-complete-details-uk.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
{
"id":"2676ea91-9dd7-4cf3-a4a3-67b06f841b54",
"title":null,
"first_name":"Joseph",
"last_name":"Woof",
"name":"Joseph Woof",
"job_title":"Dog master",
"company":{
"name":"Zboncak Group|271eb29e-425b-4cd8-b386-3208c3a5f978",
"id":"4cd4128b-1bad-4f1e-9146-5d4678c6a018"
},
"adviser":{
"name":"DBT Staff",
"first_name":"DBT",
"last_name":"Staff",
"id":"7d19d407-9aec-4d06-b190-d3f404627f21"
},
"primary":true,
"telephone_countrycode":"",
"telephone_number":"",
"full_telephone_number":"222 3453454",
"email":"[email protected]",
"address_same_as_company":false,
"address_1":"123 Test Street",
"address_2":"Address Line 2",
"address_town":"Sandbox Town",
"address_county":"Test County",
"address_country": {
"id": "80756b9a-5d95-e211-a939-e4115bead28a",
"name": "United Kingdom"
},
"address_postcode":"AB1 2CD",
"telephone_alternative":null,
"email_alternative":null,
"notes":"An example of a contact for testing purposes",
"accepts_dit_email_marketing":true,
"archived":false,
"archived_documents_url_path":"/document/123",
"archived_on":null,
"archived_reason":null,
"archived_by":null,
"created_on":"2019-02-04T15:59:14.267412Z",
"modified_on":"2019-02-05T13:17:23.112153Z"
}
"id": "2676ea91-9dd7-4cf3-a4a3-67b06f841b54",
"title": null,
"first_name": "Joseph",
"last_name": "Woof",
"name": "Joseph Woof",
"job_title": "Dog master",
"company": {
"name": "Zboncak Group|271eb29e-425b-4cd8-b386-3208c3a5f978",
"id": "4cd4128b-1bad-4f1e-9146-5d4678c6a018"
},
"adviser": {
"name": "DBT Staff",
"first_name": "DBT",
"last_name": "Staff",
"id": "7d19d407-9aec-4d06-b190-d3f404627f21"
},
"primary": true,
"telephone_countrycode": "",
"telephone_number": "",
"full_telephone_number": "222 3453454",
"email": "[email protected]",
"address_same_as_company": false,
"address_1": "123 Test Street",
"address_2": "Address Line 2",
"address_town": "Sandbox Town",
"address_county": "Test County",
"address_country": {
"id": "80756b9a-5d95-e211-a939-e4115bead28a",
"name": "United Kingdom"
},
"address_postcode": "AB1 2CD",
"telephone_alternative": null,
"email_alternative": null,
"notes": "An example of a contact for testing purposes",
"accepts_dit_email_marketing": true,
"archived": false,
"archived_documents_url_path": "/document/123",
"archived_on": null,
"archived_reason": null,
"archived_by": null,
"created_on": "2019-02-04T15:59:14.267412Z",
"modified_on": "2019-02-05T13:17:23.112153Z",
"consent_data": [
{
"source_system": "System B",
"consent_domain": "International",
"consent": true
}
]
}

0 comments on commit 3cce0a0

Please sign in to comment.