Skip to content

Commit

Permalink
refactor: use updated model
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangoulding committed Jan 30, 2025
1 parent 068c88f commit 957febe
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ function _licenceContactDetails(licenceDocumentHeader) {
]
}

function _licenceEntityRoles(licenceEntityRoles) {
return licenceEntityRoles.map(_licenceEntity).sort(_sortLicenceEntity)
}

function _licenceEntity(entity) {
return {
role: ROLES[entity.role],
email: entity.licenceEntity.name
}
}

function _sortLicenceEntity(a, b) {
function _licenceEntityRoles(licenceEntityRoles) {
return licenceEntityRoles.map(_licenceEntity).sort(_sortLicenceEntities)
}

function _sortLicenceEntities(a, b) {
if (a.role < b.role) {
return -1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,59 +40,95 @@ describe('View Licence Contact Details presenter', () => {
address: ['Crinkley Bottom', 'Cricket St Thomas', 'Somerset', 'TA20 1KL', 'United Kingdom'],
role: 'Returns to',
name: 'Mr N Edmonds'
},
{
email: '[email protected]',
role: 'Primary user'
},
{
email: '[email protected]',
role: 'Returns agent'
}
]
})
})

describe('the "licenceContactDetails" property', () => {
describe('the "licenceContactDetails.address" property', () => {
it('returns the address of the property', () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)

expect(result.licenceContactDetails[0].address).to.equal([
'ENVIRONMENT AGENCY',
'HORIZON HOUSE',
'DEANERY ROAD',
'BRISTOL',
'BS1 5AH',
'United Kingdom'
])
describe('when the licence contact is a "contact"', () => {
describe('the "licenceContactDetails.address" property', () => {
it('returns the address of the property', () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)

expect(result.licenceContactDetails[0].address).to.equal([
'ENVIRONMENT AGENCY',
'HORIZON HOUSE',
'DEANERY ROAD',
'BRISTOL',
'BS1 5AH',
'United Kingdom'
])
})
})
})

describe('the "licenceContactDetails.role" property', () => {
describe('when one of the licence contact details has the role type of "Enforcement officer"', () => {
it('returns licenceContactDetails without the contact with the role type of "Enforcement officer"', () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)
describe('the "licenceContactDetails.role" property', () => {
describe('when one of the licence contact details has the role type of "Enforcement officer"', () => {
it('returns licenceContactDetails without the contact with the role type of "Enforcement officer"', () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)

const hasEnforcementOfficer = result.licenceContactDetails.some((contact) => {
return contact.role === 'Enforcement officer'
})
const hasEnforcementOfficer = result.licenceContactDetails.some((contact) => {
return contact.role === 'Enforcement officer'
})

expect(hasEnforcementOfficer).to.be.false()
expect(hasEnforcementOfficer).to.be.false()
})
})
})
})

describe('the "licenceContacts.name" property', () => {
describe('when the initials are null', () => {
beforeEach(() => {
licenceContactDetailsData.licenceDocumentHeader.metadata.contacts[3].initials = null
describe('the "licenceContacts.name" property', () => {
describe('when the initials are null', () => {
beforeEach(() => {
licenceContactDetailsData.licenceDocumentHeader.metadata.contacts[3].initials = null
})

it("returns the licence contact's forename and name", () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)

expect(result.licenceContactDetails[2].name).to.equal('Mr Noel Edmonds')
})
})

it("returns the licence contact's forename and name", () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)
describe('when the initials are not null', () => {
it("returns the licence contact's forename and name", () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)

expect(result.licenceContactDetails[2].name).to.equal('Mr Noel Edmonds')
expect(result.licenceContactDetails[2].name).to.equal('Mr N Edmonds')
})
})
})
})

describe('when the initials are not null', () => {
it("returns the licence contact's forename and name", () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)
describe('when the licence contact is a "licenceEntityRole"', () => {
describe('the "licenceContactDetails" property', () => {
describe('and the role is "primary_user"', () => {
it('returns the email and formatted role', () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)

expect(result.licenceContactDetails[2].name).to.equal('Mr N Edmonds')
expect(result.licenceContactDetails[3]).to.equal({
email: '[email protected]',
role: 'Primary user'
})
})
})

describe('and the role is "user_returns"', () => {
it('returns the email and formatted role', () => {
const result = ViewLicenceContactDetailsPresenter.go(licenceContactDetailsData)

expect(result.licenceContactDetails[4]).to.equal({
email: '[email protected]',
role: 'Returns agent'
})
})
})
})
})
Expand Down Expand Up @@ -175,7 +211,20 @@ function _testFetchLicenceContactDetailsData() {
],
IsCurrent: false
},
licenceEntityRoles: []
licenceEntityRoles: [
{
role: 'primary_user',
licenceEntity: {
name: '[email protected]'
}
},
{
role: 'user_returns',
licenceEntity: {
name: '[email protected]'
}
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { expect } = Code

// Test helpers
const LicenceHelper = require('../../support/helpers/licence.helper.js')
const LicenceDocumentHeaderHelper = require('../../support/helpers/licence-document-header.helper.js')
const CRMContactDetailsSeeder = require('../../support/seeders/crm-contact-details.seeder.js')

// Thing under test
const FetchLicenceContactDetailsService = require('../../../app/services/licences/fetch-licence-contact-details.service.js')
Expand All @@ -18,16 +18,18 @@ describe('Fetch Licence Contact Details service', () => {
let licence
let licenceId
let licenceRef
let licenceDocumentHeader
let licenceDocumentHeaderId

describe('when the licence has a licence document header', () => {
before(async () => {
licence = await LicenceHelper.add()
const { primaryUser: licenceDocumentHeader } = await CRMContactDetailsSeeder.seed(false)

licence = await LicenceHelper.add({
licenceRef: licenceDocumentHeader.licenceRef
})

licenceId = licence.id
licenceRef = licence.licenceRef

licenceDocumentHeader = await LicenceDocumentHeaderHelper.add({ licenceRef })
licenceDocumentHeaderId = licenceDocumentHeader.id
})

Expand All @@ -39,42 +41,58 @@ describe('Fetch Licence Contact Details service', () => {
licenceRef,
licenceDocumentHeader: {
id: licenceDocumentHeaderId,
licenceEntityRoles: [],
licenceEntityRoles: [
{
role: 'primary_user',
licenceEntity: {
name: '[email protected]'
}
},
{
role: 'user_returns',
licenceEntity: {
name: '[email protected]'
}
}
],
metadata: {
Name: 'GUPTA',
Town: 'BRISTOL',
County: 'AVON',
Country: '',
Expires: null,
Forename: 'AMARA',
Initials: 'A',
Modified: '20080327',
Postcode: 'BS1 5AH',
Name: 'Primary User test',
contacts: [
{
name: 'GUPTA',
addressLine1: '4',
addressLine2: 'Privet Drive',
addressLine3: null,
addressLine4: null,
country: null,
county: 'Surrey',
forename: 'Harry',
initials: 'J',
name: 'Primary User test',
postcode: 'WD25 7LR',
role: 'Licence holder',
town: 'BRISTOL',
type: 'Person',
county: 'AVON',
salutation: null,
town: 'Little Whinging',
type: 'Person'
},
{
addressLine1: '4',
addressLine2: 'Privet Drive',
addressLine3: null,
addressLine4: null,
country: null,
forename: 'AMARA',
initials: 'A',
postcode: 'BS1 5AH',
county: 'Surrey',
forename: 'Harry',
initials: 'J',
name: 'Primary User test',
postcode: 'WD25 7LR',
role: 'Returns to',
salutation: null,
addressLine1: 'ENVIRONMENT AGENCY',
addressLine2: 'HORIZON HOUSE',
addressLine3: 'DEANERY ROAD',
addressLine4: null
town: 'Little Whinging',
type: 'Person'
}
],
isCurrent: true,
isSummer: true,
Salutation: '',
AddressLine1: 'ENVIRONMENT AGENCY',
AddressLine2: 'HORIZON HOUSE',
AddressLine3: 'DEANERY ROAD',
AddressLine4: ''
isSummer: true
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { describe, it, before } = (exports.lab = Lab.script())
const { expect } = Code

// Test helpers
const RecipientsSeeder = require('../../../support/seeders/recipients.seeder.js')
const CRMContactDetailsSeeder = require('../../../support/seeders/crm-contact-details.seeder.js')

// Thing under test
const RecipientsService = require('../../../../app/services/notifications/setup/fetch-recipients.service.js')
Expand All @@ -22,7 +22,7 @@ describe('Notifications Setup - Recipients service', () => {
dueDate = '2023-04-28' // matches return log date
isSummer = 'false'

recipients = await RecipientsSeeder.seed()
recipients = await CRMContactDetailsSeeder.seed()
})

describe('when there is a "primary user"', () => {
Expand Down
Loading

0 comments on commit 957febe

Please sign in to comment.