diff --git a/src/apps/contacts/constants.js b/src/apps/contacts/constants.js index af30e748536..4d56fe8476e 100644 --- a/src/apps/contacts/constants.js +++ b/src/apps/contacts/constants.js @@ -35,6 +35,9 @@ const QUERY_FIELDS = [ 'company_uk_region', ] +const EMAIL_CONSENT_YES = 'Can be marketed to' +const EMAIL_CONSENT_NO = 'Cannot be marketed to' + const LEFT_COMPANY_OPTION = 'Left the company' const NO_CONTACT_OPTION = 'Does not want to be contacted' const ROLE_CHANGE_OPTION = 'Changed role/responsibility' @@ -44,6 +47,8 @@ module.exports = { LOCAL_NAV, APP_PERMISSIONS, QUERY_FIELDS, + EMAIL_CONSENT_YES, + EMAIL_CONSENT_NO, LEFT_COMPANY_OPTION, NO_CONTACT_OPTION, ROLE_CHANGE_OPTION, diff --git a/src/apps/contacts/services/__test__/form.test.js b/src/apps/contacts/services/__test__/form.test.js index c7a0a455c64..4b6fca3b033 100644 --- a/src/apps/contacts/services/__test__/form.test.js +++ b/src/apps/contacts/services/__test__/form.test.js @@ -32,6 +32,7 @@ describe('contact form service', () => { primary: true, full_telephone_number: '+1 652423467167', email: 'zboasdaan@opasdasdov.com', + accepts_dit_email_marketing: true, address_same_as_company: false, notes: 'Some notes', archived_by: null, @@ -59,6 +60,7 @@ describe('contact form service', () => { primary: 'yes', full_telephone_number: '+1 652423467167', email: 'zboasdaan@opasdasdov.com', + accepts_dit_email_marketing: true, address_same_as_company: 'no', address_1: '99 N Shore Road', address_2: 'Suite 20', @@ -105,6 +107,7 @@ describe('contact form service', () => { address_postcode: null, address_country: null, notes: 'Some notes', + accepts_dit_email_marketing: true, } const actual = contactFormService.getContactAsFormData(contact) @@ -115,5 +118,15 @@ describe('contact form service', () => { it('should handle a null contact', () => { expect(contactFormService.getContactAsFormData(null)).to.be.null }) + + context('when the contact accepts DBT email marketing', () => { + it('should set the marketing preferences to accepts_dit_email_marketing', () => { + const contact = assign({}, contactData, { + accepts_dit_email_marketing: true, + }) + const actual = contactFormService.getContactAsFormData(contact) + expect(actual.accepts_dit_email_marketing).to.be.true + }) + }) }) }) diff --git a/src/apps/contacts/services/form.js b/src/apps/contacts/services/form.js index e4dbe790ba1..dec6765f39f 100644 --- a/src/apps/contacts/services/form.js +++ b/src/apps/contacts/services/form.js @@ -14,6 +14,11 @@ function getContactAsFormData(contact) { return null } + // default is that people are always marketable, unless opted out + if (!contact.hasOwnProperty('accepts_dit_email_marketing')) { + contact.accepts_dit_email_marketing = true + } + let result = { id: contact.id, company: contact.company.id, @@ -24,6 +29,7 @@ function getContactAsFormData(contact) { primary: contact.primary ? 'yes' : 'no', full_telephone_number: contact.full_telephone_number, email: contact.email, + accepts_dit_email_marketing: contact.accepts_dit_email_marketing, address_same_as_company: contact.address_same_as_company ? 'yes' : 'no', address_1: contact.address_1, address_2: contact.address_2, diff --git a/src/client/components/ContactForm/index.jsx b/src/client/components/ContactForm/index.jsx index d8e4285c472..63c2f8d3bc0 100644 --- a/src/client/components/ContactForm/index.jsx +++ b/src/client/components/ContactForm/index.jsx @@ -17,6 +17,7 @@ import { FieldInput, FieldRadios, FieldTextarea, + FieldCheckboxes, FieldAddress, Main, FormLayout, @@ -79,6 +80,7 @@ const _ContactForm = ({ // We need to convert these to YES / NO strings primary, addressSameAsCompany, + acceptsDitEmailMarketing, // These need to be renamed, so that they are compatible with the fields of // the address sub-form addressPostcode: postcode, @@ -173,6 +175,7 @@ const _ContactForm = ({ city, county, postcode, + acceptsDitEmailMarketing, addressSameAsCompany, primary, email, @@ -186,6 +189,8 @@ const _ContactForm = ({ email, valid_email: true, notes: moreDetails, + accepts_dit_email_marketing: + acceptsDitEmailMarketing.includes(YES), primary, company, address_same_as_company: @@ -246,9 +251,12 @@ const _ContactForm = ({ country: addressCountry?.id, primary: boolToYesNo(primary), addressSameAsCompany: boolToYesNo(addressSameAsCompany), + acceptsDitEmailMarketing: [ + boolToYesNo(acceptsDitEmailMarketing), + ].filter(Boolean), }} > - {() => ( + {({ values }) => ( <> + { - const consentGiven = transformContactConsents(contact) - return ( -
- Contact consent - {isNil(contact.consentData) ? ( -

- There is no consent data available for this contact -

- ) : ( -

- {`This contact has ${consentGiven ? 'given' : 'not given'} consent to be contacted.`} -

- )} -
- ) -} - -export default ConsentDetails diff --git a/src/client/modules/Contacts/ContactDetails/ContactDetails.jsx b/src/client/modules/Contacts/ContactDetails/ContactDetails.jsx index 399cac32f9b..89ece6364d3 100644 --- a/src/client/modules/Contacts/ContactDetails/ContactDetails.jsx +++ b/src/client/modules/Contacts/ContactDetails/ContactDetails.jsx @@ -7,6 +7,8 @@ import { ContactResource } from '../../../components/Resource' import { SummaryTable, ErrorSummary } from '../../../components' import urls from '../../../../lib/urls' import { + EMAIL_CONSENT_NO, + EMAIL_CONSENT_YES, LEFT_COMPANY_OPTION, NO_CONTACT_OPTION, ROLE_CHANGE_OPTION, @@ -14,7 +16,6 @@ import { import { ID, TASK_ARCHIVE_CONTACT } from './state' import ArchiveForm from '../../../components/ArchiveForm' import ContactLayout from '../../../components/Layout/ContactLayout' -import ConsentDetails from './ConsentDetails' const getAddress = (contact, companyAddress) => { const address = contact.addressSameAsCompany @@ -81,6 +82,14 @@ const ContactDetails = ({ contactId, companyAddress, permissions }) => ( children={contact.notes} /> ) : null} + {!contact.archived ? ( ) : null} - - { - context('When a falsey contact is passed', () => { - it('Should return false', () => { - expect(transformContactConsents(undefined)).to.equal(false) - }) - }) - - context('When a contact has no consent data', () => { - it('Should return false', () => { - expect(transformContactConsents({})).to.equal(false) - }) - }) - - context( - 'When a contact has a single domain and has not given consent', - () => { - it('Should return false', () => { - expect( - transformContactConsents({ - consentData: [ - { - consentDomain: 'International', - emailContactConsent: false, - }, - ], - }) - ).to.equal(false) - }) - } - ) - - context('When a contact has a single domain and has given consent', () => { - it('Should return true', () => { - expect( - transformContactConsents({ - consentData: [ - { - consentDomain: 'International', - emailContactConsent: true, - }, - ], - }) - ).to.equal(true) - }) - }) - - context( - 'When a contact has a multiple domains and has given consent to one', - () => { - it('Should return true', () => { - expect( - transformContactConsents({ - consentData: [ - { - consentDomain: 'International', - emailContactConsent: true, - }, - { - consentDomain: 'International', - emailContactConsent: false, - }, - ], - }) - ).to.equal(true) - }) - } - ) - - context( - 'When a contact has a multiple domains and has given consent to all', - () => { - it('Should return true', () => { - expect( - transformContactConsents({ - consentData: [ - { - consentDomain: 'International', - emailContactConsent: true, - }, - { - consentDomain: 'International', - emailContactConsent: true, - }, - ], - }) - ).to.equal(true) - }) - } - ) -}) diff --git a/src/client/modules/Contacts/ContactDetails/transformers.js b/src/client/modules/Contacts/ContactDetails/transformers.js deleted file mode 100644 index 28d69ec9a73..00000000000 --- a/src/client/modules/Contacts/ContactDetails/transformers.js +++ /dev/null @@ -1,7 +0,0 @@ -export const transformContactConsents = (contact) => { - if (!contact || !contact.consentData) { - return false - } - - return contact.consentData.some((consent) => consent.emailContactConsent) -} diff --git a/test/component/cypress/specs/Contacts/ConsentDetails.cy.jsx b/test/component/cypress/specs/Contacts/ConsentDetails.cy.jsx deleted file mode 100644 index b40d202303b..00000000000 --- a/test/component/cypress/specs/Contacts/ConsentDetails.cy.jsx +++ /dev/null @@ -1,66 +0,0 @@ -import React from 'react' - -import ConsentDetails from '../../../../../src/client/modules/Contacts/ContactDetails/ConsentDetails' - -describe('ConsentDetails', () => { - context('When contact has no consent data', () => { - beforeEach(() => { - cy.mount() - }) - - it('should render a message that this data is missing for this contact', () => { - cy.get('p').should( - 'have.text', - 'There is no consent data available for this contact' - ) - }) - }) - - context('When a contact has consented', () => { - beforeEach(() => { - cy.mount( - - ) - }) - - it('should render the expected message', () => { - cy.get('p').should( - 'have.text', - 'This contact has given consent to be contacted.' - ) - }) - }) - - context('When a contact has not consented', () => { - beforeEach(() => { - cy.mount( - - ) - }) - - it('should render the expected message', () => { - cy.get('p').should( - 'have.text', - 'This contact has not given consent to be contacted.' - ) - }) - }) -}) diff --git a/test/end-to-end/cypress/specs/DIT/companies-spec.js b/test/end-to-end/cypress/specs/DIT/companies-spec.js index f4060a54dbf..bc140513164 100644 --- a/test/end-to-end/cypress/specs/DIT/companies-spec.js +++ b/test/end-to-end/cypress/specs/DIT/companies-spec.js @@ -49,11 +49,12 @@ describe('Contacts', () => { cy.contains('You have successfully added a new contact Company Contact') - assertKeyValueTable('contact-details-table', { + assertKeyValueTable('bodyMainContent', { 'Job title': 'Coffee machine operator', 'Phone number': '44 0778877778800', Address: '100 Path, A town, 12345, United States', Email: 'company.contact@dit.com', + 'Email marketing': 'Cannot be marketed to', }) }) diff --git a/test/functional/cypress/specs/contacts/create-and-edit-spec.js b/test/functional/cypress/specs/contacts/create-and-edit-spec.js index 882d84a813f..198e17e5da8 100644 --- a/test/functional/cypress/specs/contacts/create-and-edit-spec.js +++ b/test/functional/cypress/specs/contacts/create-and-edit-spec.js @@ -45,6 +45,13 @@ const assertRadioGroup = (label, option) => const assertRadioGroupNoOptionChecked = (label) => cy.contains(label).parent().find('input').should('not.be.checked') +const assertNoMarketingConsent = () => + cy + .contains('The company contact does accept email marketing') + .parent() + .find('input') + .should('not.be.checked') + const NEW_CONTACT_ID = '14890695-ce54-4419-88d3-9224754ecbc0' describe('Create contact form', () => { beforeEach(() => { @@ -56,6 +63,8 @@ describe('Create contact form', () => { 'Add contact at Zboncak Group|271eb29e-425b-4cd8-b386-3208c3a5f978': null, }) + assertNoMarketingConsent() + assertRadioGroupNoOptionChecked('Is this person a primary contact?') assertRadioGroupNoOptionChecked( 'Is this contact’s work address the same as the company address?' @@ -307,6 +316,8 @@ describe('Edit contact', () => { `/companies/${ZBONCAK_COMPANY_ID}` ) + assertNoMarketingConsent() + assertRadioGroup('Is this person a primary contact?', 'Yes') assertRadioGroup( 'Is this contact’s work address the same as the company address?', diff --git a/test/functional/cypress/specs/contacts/details-spec.js b/test/functional/cypress/specs/contacts/details-spec.js index 7137d4d33c5..a0a95bc13da 100644 --- a/test/functional/cypress/specs/contacts/details-spec.js +++ b/test/functional/cypress/specs/contacts/details-spec.js @@ -1,4 +1,8 @@ import { contacts } from '../../../../../src/lib/urls' +import { + EMAIL_CONSENT_NO, + EMAIL_CONSENT_YES, +} from '../../../../../src/apps/contacts/constants' const completeUKContact = require('../../../../sandbox/fixtures/v3/contact/contact-complete-details-uk.json') const incompleteUKContact = require('../../../../sandbox/fixtures/v3/contact/contact-incomplete-details-uk.json') @@ -45,6 +49,7 @@ describe('View contact details', () => { '123 Test Street, Address Line 2, Sandbox Town, Test County, AB1 2CD, United Kingdom', Email: completeUKContact.email, 'More details': completeUKContact.notes, + 'Email marketing': EMAIL_CONSENT_YES, }) }) @@ -55,10 +60,6 @@ describe('View contact details', () => { .should('have.attr', 'href', contacts.edit(completeUKContact.id)) }) - it('should render consent detail', () => { - 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]') @@ -121,6 +122,7 @@ describe('View contact details', () => { 'Job title': incompleteUKContact.job_title, Address: '123 Test Street, Sandbox Town, AB1 2CD, United Kingdom', Email: incompleteUKContact.email, + 'Email marketing': EMAIL_CONSENT_YES, }) }) }) @@ -136,6 +138,7 @@ describe('View contact details', () => { Address: '3 Priory Court, Kingshill Road, Dursley, Gloucestershire, GL11 4DH, United Kingdom', Email: companyAddresscontact.email, + 'Email marketing': EMAIL_CONSENT_NO, }) }) }) @@ -152,6 +155,7 @@ describe('View contact details', () => { '123 Test Boulevard, Basney, US State, 9416875, United States', Email: usContact.email, 'More details': usContact.notes, + 'Email marketing': EMAIL_CONSENT_NO, }) }) }) @@ -196,13 +200,10 @@ describe('View contact details', () => { '123 Test Street, Address Line 2, Sandbox Town, Test County, AB1 2CD, United Kingdom', Email: archiveContact.email, 'More details': archiveContact.notes, + 'Email marketing': EMAIL_CONSENT_YES, }) }) - it('should not render consent detail', () => { - 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') }) @@ -248,6 +249,7 @@ describe('View contact details', () => { '123 Test Street, Address Line 2, Sandbox Town, Test County, AB1 2CD, United Kingdom', Email: invalidEmailContact.email, 'More details': invalidEmailContact.notes, + 'Email marketing': EMAIL_CONSENT_YES, }) }) }) diff --git a/test/sandbox/fixtures/v3/contact/contact-by-id-uk.json b/test/sandbox/fixtures/v3/contact/contact-by-id-uk.json index b3eef423adb..323ff2911d8 100644 --- a/test/sandbox/fixtures/v3/contact/contact-by-id-uk.json +++ b/test/sandbox/fixtures/v3/contact/contact-by-id-uk.json @@ -1,50 +1,43 @@ { - "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": "contact@bob.com", - "address_same_as_company": false, + "primary":true, + "telephone_countrycode":"", + "telephone_number":"", + "full_telephone_number":"222 3453454", + "email":"contact@bob.com", + "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", - "consent_data": [ - { - "source_system": "System A", - "consent_domain": "Domestic", - "consent": false - } - ] + "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" } diff --git a/test/sandbox/fixtures/v3/contact/contact-complete-details-uk.json b/test/sandbox/fixtures/v3/contact/contact-complete-details-uk.json index 954ea12b46f..5874086a9c2 100644 --- a/test/sandbox/fixtures/v3/contact/contact-complete-details-uk.json +++ b/test/sandbox/fixtures/v3/contact/contact-complete-details-uk.json @@ -1,51 +1,44 @@ { - "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": "contact@bob.com", - "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 - } - ] -} + "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":"contact@bob.com", + "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" + }