From c8e97b68b011f3071f1c28f2136457bff23b78f2 Mon Sep 17 00:00:00 2001 From: stuart-mindt <75611506+stuart-mindt@users.noreply.github.com> Date: Wed, 19 Feb 2025 12:36:55 +0000 Subject: [PATCH] =?UTF-8?q?CLS2-1246=20Adding=20is=5Fhigh=5Fvalue=20latest?= =?UTF-8?q?=20audit=20log=20entry=20to=20EYB=20search=20r=E2=80=A6=20(#756?= =?UTF-8?q?7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CLS2-1246 Adding is_high_value latest audit log entry to EYB search results --- .../Investments/EYBLeads/transformers.js | 48 +++++++++++++++- test/api-schema.json | 4 ++ test/functional/cypress/fakers/eyb-leads.js | 1 + .../specs/investments/eyb-leads-spec.js | 56 +++++++++++++++++++ 4 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/client/modules/Investments/EYBLeads/transformers.js b/src/client/modules/Investments/EYBLeads/transformers.js index e7e967d807..956c36cacd 100644 --- a/src/client/modules/Investments/EYBLeads/transformers.js +++ b/src/client/modules/Investments/EYBLeads/transformers.js @@ -14,6 +14,7 @@ export const transformLeadToListItem = ({ landing_timeframe, proposed_investment_region, is_high_value, + audit_log, }) => { const tags = [ { @@ -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 : '' }, { @@ -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, } } diff --git a/test/api-schema.json b/test/api-schema.json index 4d93523bc9..90f9992423 100644 --- a/test/api-schema.json +++ b/test/api-schema.json @@ -9043,6 +9043,10 @@ "type": "string" } }, + "audit_log": { + "type": "string", + "readOnly": true + }, "reasons_for_abandonment": { "type": "array", "items": { diff --git a/test/functional/cypress/fakers/eyb-leads.js b/test/functional/cypress/fakers/eyb-leads.js index 9fef8ef667..af694e69e8 100644 --- a/test/functional/cypress/fakers/eyb-leads.js +++ b/test/functional/cypress/fakers/eyb-leads.js @@ -119,6 +119,7 @@ const eybLeadFaker = (overrides = {}) => ({ id: faker.string.uuid(), }, ], + audit_log: [], ...overrides, }) diff --git a/test/functional/cypress/specs/investments/eyb-leads-spec.js b/test/functional/cypress/specs/investments/eyb-leads-spec.js index 5d50c288a5..69a6429ff6 100644 --- a/test/functional/cypress/specs/investments/eyb-leads-spec.js +++ b/test/functional/cypress/specs/investments/eyb-leads-spec.js @@ -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, @@ -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], + }, + }, + ], }) ) @@ -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}?*`, { @@ -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', () => {