Skip to content

Commit

Permalink
CLS2-1246 Adding is_high_value latest audit log entry to EYB search r… (
Browse files Browse the repository at this point in the history
#7567)

* CLS2-1246 Adding is_high_value latest audit log entry to EYB search results
  • Loading branch information
stuart-mindt authored Feb 19, 2025
1 parent 44e36a9 commit c8e97b6
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
48 changes: 45 additions & 3 deletions src/client/modules/Investments/EYBLeads/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const transformLeadToListItem = ({
landing_timeframe,
proposed_investment_region,
is_high_value,
audit_log,
}) => {
const tags = [
{
Expand All @@ -27,11 +28,49 @@ export const transformLeadToListItem = ({
},
]

const getLowHighValueAuditLog = (auditLog) => {
return (
auditLog?.filter?.((entry) =>
entry.changes?.hasOwnProperty('is_high_value')
) || []
)
}

const getLatestIsHighValueChange = (auditLog) => {
const highValueChanges = getLowHighValueAuditLog(auditLog)
if (highValueChanges.length === 0) return null

const latestChange = highValueChanges.reduce((latest, entry) =>
new Date(entry.timestamp) > new Date(latest.timestamp) ? entry : latest
)

return [
{
label: 'Value modified on',
value: formatDate(latestChange.timestamp, DATE_FORMAT_COMPACT),
},
{
label: 'Value change',
value: latestChange.changes.is_high_value[0]
? 'High to Low'
: 'Low to High',
},
]
}

const metadata = [
{
label: 'Submitted to EYB',
value: formatDate(triage_created, DATE_FORMAT_COMPACT),
},
]

const latestChangeMetadata = getLatestIsHighValueChange(audit_log)
if (latestChangeMetadata) {
metadata.push(...latestChangeMetadata)
}

metadata.push(
{ label: 'Estimated spend', value: spend },
{ label: 'Sector', value: sector ? sector.name : '' },
{
Expand All @@ -41,14 +80,17 @@ export const transformLeadToListItem = ({
{
label: 'Location',
value: proposed_investment_region ? proposed_investment_region.name : '',
},
].filter((metadata) => metadata.value)
}
)

// Remove any entries with falsy values
const filteredMetadata = metadata.filter((item) => item.value)

return {
id,
headingUrl: urls.investments.eybLeads.details(id),
headingText: company ? company.name : company_name,
tags,
metadata,
metadata: filteredMetadata,
}
}
4 changes: 4 additions & 0 deletions test/api-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9043,6 +9043,10 @@
"type": "string"
}
},
"audit_log": {
"type": "string",
"readOnly": true
},
"reasons_for_abandonment": {
"type": "array",
"items": {
Expand Down
1 change: 1 addition & 0 deletions test/functional/cypress/fakers/eyb-leads.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const eybLeadFaker = (overrides = {}) => ({
id: faker.string.uuid(),
},
],
audit_log: [],
...overrides,
})

Expand Down
56 changes: 56 additions & 0 deletions test/functional/cypress/specs/investments/eyb-leads-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ const EYB_LEAD_LIST = Array(
triage_modified: DATE_TIME_STRING,
triage_created: DATE_TIME_STRING,
is_high_value: false,
audit_log: [
{
id: 777,
timestamp: '2025-02-17T09:00:20.773368Z',
changes: {
is_high_value: [true, false],
},
},
{
id: 777,
timestamp: '2025-02-15T09:00:20.773368Z',
changes: {
is_high_value: [false, true],
},
},
],
}),
eybLeadFaker({
triage_modified: DATE_TIME_STRING,
Expand All @@ -104,6 +120,22 @@ const EYB_LEAD_LIST = Array(
id: OVERSEAS_REGION_ID_2,
},
},
audit_log: [
{
id: 244,
timestamp: '2025-02-14T09:00:20.773368Z',
changes: {
is_high_value: [false, true],
},
},
{
id: 445,
timestamp: '2025-02-11T09:00:20.773368Z',
changes: {
is_high_value: [true, false],
},
},
],
})
)

Expand Down Expand Up @@ -168,6 +200,8 @@ const getEYBLeadsByOverseasRegionId = (overseasRegionID) => {
describe('EYB leads collection page', () => {
context('When visiting the EYB leads tab', () => {
const eybLead = EYB_LEAD_LIST[0]
const eybLeadWithAuditDataHighToLowValue = EYB_LEAD_LIST[3]
const eybLeadWithAuditDataLowToHighValue = EYB_LEAD_LIST[4]

beforeEach(() => {
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`, {
Expand Down Expand Up @@ -245,6 +279,28 @@ describe('EYB leads collection page', () => {
.eq(4)
.should('contain', COMPANY_NAME_DEFAULT)
})
it('should display the audit log metadata for each collection item correctly', () => {
cy.get('[data-test="collection-item"]')
.eq(3)
.should(
'contain',
`Value modified on ${formatDate(eybLeadWithAuditDataHighToLowValue.audit_log[0].timestamp, DATE_FORMAT_COMPACT)}`
)
.should('contain', `Value change High to Low`)

cy.get('[data-test="collection-item"]')
.eq(1)
.should('not.contain', 'Value modified on')
.should('not.contain', `Value change`)

cy.get('[data-test="collection-item"]')
.eq(4)
.should(
'contain',
`Value modified on ${formatDate(eybLeadWithAuditDataLowToHighValue.audit_log[0].timestamp, DATE_FORMAT_COMPACT)}`
)
.should('contain', `Value change Low to High`)
})
})

context('When filtering the EYB leads collection by company name', () => {
Expand Down

0 comments on commit c8e97b6

Please sign in to comment.