Skip to content

Commit

Permalink
fix(AHWR-321): use organisation, not farmer, name (#256)
Browse files Browse the repository at this point in the history
* fix(AHWR-321): use organisation, not farmer, name

- stop allowing 404s from contact history (it now returns [] instead)
- remove debug logging for auth, just in case we go to prod
  • Loading branch information
mattyod authored Dec 23, 2024
1 parent 339b32a commit 6090ad5
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 121 deletions.
26 changes: 11 additions & 15 deletions app/api/contact-history.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const wreck = require('@hapi/wreck')
const _ = require('lodash')
const { applicationApiUri } = require('../config')
const { fieldsNames, labels, notAvailable } = require('./../constants/contact-history')

Expand All @@ -10,42 +9,39 @@ async function getContactHistory (reference, logger) {

return payload
} catch (err) {
if (err.output.statusCode === 404) {
return null
} else {
logger.setBindings({ err, endpoint })
throw err
}
logger.setBindings({ err, endpoint })
throw err
}
}

const getContactFieldData = (contactHistoryData, field) => {
const filteredData = contactHistoryData.filter(contact => contact?.data?.field === field)
if (filteredData.length) {
const oldValue = _.sortBy(filteredData, [function (data) { return new Date(data.createdAt) }])[0].data.oldValue
return `${labels[field]} ${oldValue}`
} else {
const filteredData = contactHistoryData.filter(contact => contact.data?.field === field)

if (filteredData.length === 0) {
return 'NA'
}

const [firstUpdate] = filteredData.sort((a, b) =>
new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
)

return `${labels[field]} ${firstUpdate.data.oldValue}`
}

const displayContactHistory = (contactHistory) => {
if (contactHistory) {
const orgEmail = getContactFieldData(contactHistory, fieldsNames.orgEmail)
const email = getContactFieldData(contactHistory, fieldsNames.email)
const farmerName = getContactFieldData(contactHistory, fieldsNames.farmerName)
const address = getContactFieldData(contactHistory, fieldsNames.address)
return {
orgEmail,
email,
farmerName,
address
}
} else {
return {
orgEmail: notAvailable,
email: notAvailable,
farmerName: notAvailable,
address: notAvailable
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/constants/contact-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ module.exports = {
fieldsNames: {
orgEmail: 'orgEmail',
email: 'email',
farmerName: 'farmerName',
address: 'address'
},
labels: {
orgEmail: 'Organisation email at start of agreement:',
email: 'User email at start of agreement:',
farmerName: 'Name at start of agreement:',
address: 'Address at start of agreement:'
},
notAvailable: 'NA'
Expand Down
2 changes: 1 addition & 1 deletion app/routes/agreement.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = [{
const summaryDetails = [
{ field: 'Agreement number', newValue: request.params.reference, oldValue: null },
{ field: 'Agreement date', newValue: formatedDateToUk(application.createdAt), oldValue: null },
{ field: 'Agreement holder', newValue: organisation?.farmerName, oldValue: contactHistoryDetails.farmerName },
{ field: 'Agreement holder', newValue: organisation?.name, oldValue: null },
{ field: 'Agreement holder email', newValue: organisation?.email, oldValue: contactHistoryDetails.email },
{ field: 'SBI number', newValue: organisation?.sbi, oldValue: null },
{ field: 'Address', newValue: organisation?.address, oldValue: contactHistoryDetails.address },
Expand Down
2 changes: 1 addition & 1 deletion app/routes/models/application-organisation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = (organisation) => {
return [
{ key: { text: 'Name:' }, value: { text: organisation?.farmerName } },
{ key: { text: 'Name:' }, value: { text: organisation?.name } },
{ key: { text: 'SBI number:' }, value: { text: organisation?.sbi } },
{ key: { text: 'Address:' }, value: { text: organisation?.address } },
{ key: { text: 'User Email address:' }, value: { text: organisation?.email } },
Expand Down
2 changes: 1 addition & 1 deletion app/routes/view-agreement.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
const contactHistoryDetails = displayContactHistory(contactHistory)
const organisation = application.data?.organisation
const listData = [
{ field: 'Name', newValue: organisation?.farmerName, oldValue: contactHistoryDetails.farmerName },
{ field: 'Name', newValue: organisation?.name, oldValue: null },
{ field: 'SBI number', newValue: organisation?.sbi, oldValue: null },
{ field: 'Address', newValue: organisation?.address, oldValue: contactHistoryDetails.address },
{ field: 'Email address', newValue: organisation?.email, oldValue: contactHistoryDetails.email },
Expand Down
2 changes: 1 addition & 1 deletion app/routes/view-claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
const applicationSummaryDetails = [
{ key: { text: 'Agreement number' }, value: { text: applicationReference } },
{ key: { text: 'Agreement date' }, value: { text: formatedDateToUk(application.createdAt) } },
{ key: { text: 'Agreement holder' }, value: { text: organisation?.farmerName } },
{ key: { text: 'Agreement holder' }, value: { text: organisation?.name } },
{ key: { text: 'Agreement holder email' }, value: { text: organisation?.email } },
{ key: { text: 'SBI number' }, value: { text: organisation?.sbi } },
{ key: { text: 'Address' }, value: { text: organisation?.address } },
Expand Down
125 changes: 60 additions & 65 deletions app/views/agreement.njk
Original file line number Diff line number Diff line change
@@ -1,70 +1,65 @@
{% extends './layouts/layout.njk'%}

{%block pageTitle %}{{ siteTitle }} - {{ businessName }}{%endblock%}
{% block pageTitle %}
{{ siteTitle }} - {{ businessName }}
{% endblock %}

{% block beforeContent %}
{{ govukBackLink({
text: "Back",
href: backLink
}) }}
{% endblock %}
{% block beforeContent %}
{{ govukBackLink({
text: "Back",
href: backLink
}) }}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-caption-l govuk-!-margin-bottom-3">
Agreement details and claims
</h1>
<h2 class="govuk-heading-l">{{ businessName }}</h2>
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
{% for item in applicationSummaryDetails %}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{item.field}}</dt>
<dd class="govuk-summary-list__value">
<p>{{item.newValue}}</p>
{% if (item.oldValue) and (item.oldValue != "NA") %}
<details class="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">View change</span>
</summary>
<div class="govuk-details__text">
{{ item.oldValue }}
</div>
</details>
{% endif %}
</dd>
</div>
{% endfor %}
</dl>
</div>
</div>
<div class="govuk-grid-row">
{% if claimsRowsTotal %}
<div class="govuk-grid-column-full">
<h3 class="govuk-heading-m">
Claims by this business
</h3>
{% endif %}
</div>
<div class="govuk-grid-column-full">
<div class="moj-scrollable-pane__wrapper">
{{ govukTable({
attributes: {
'data-module': 'moj-sortable-table'
},
firstCellIsHeader: false,
head: claimTable.header,
rows: claimTable.claims
}) }}
</div>
{{ govukPagination({
previous: model.previous,
next: model.next,
items: model.pages
})
}}
</div>
</div>
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-caption-l govuk-!-margin-bottom-3">Agreement details and claims</h1>
<h2 class="govuk-heading-l">{{ businessName }}</h2>
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
{% for item in applicationSummaryDetails %}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{item.field}}</dt>
<dd class="govuk-summary-list__value">
<p>{{item.newValue}}</p>
{% if (item.oldValue) and (item.oldValue != "NA") %}
<details class="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">View change</span>
</summary>
<div class="govuk-details__text">
{{ item.oldValue }}
</div>
</details>
{% endif %}
</dd>
</div>
{% endfor %}
</dl>
</div>
</div>
<div class="govuk-grid-row">
{% if claimsRowsTotal %}
<div class="govuk-grid-column-full">
<h3 class="govuk-heading-m">Claims by this business</h3>
{% endif %}
</div>
<div class="govuk-grid-column-full">
<div class="moj-scrollable-pane__wrapper">
{{ govukTable({
attributes: {
'data-module': 'moj-sortable-table'
},
firstCellIsHeader: false,
head: claimTable.header,
rows: claimTable.claims
}) }}
</div>
</div>
{%endblock%}
{{ govukPagination({
previous: model.previous,
next: model.next,
items: model.pages
})
}}
</div>
{%endblock%}
2 changes: 1 addition & 1 deletion app/views/view-agreement.njk
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@
{% endif %}
</div>
</div>
{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffc-ahwr-backoffice",
"version": "1.24.85",
"version": "1.24.86",
"description": "Back office of the health and welfare of your livestock",
"homepage": "https://github.com/DEFRA/ffc-ahwr-backoffice",
"main": "app/index.js",
Expand Down
5 changes: 0 additions & 5 deletions test/acceptance/wdio.bs.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const browserstack = require('browserstack-local')
//const { ReportAggregator, HtmlReporter } = require('@rpii/wdio-html-reporter')
//const log4js = require('@log4js-node/log4js-api')
const allureReporter = require('@wdio/allure-reporter')
//const cucumberJson = require('wdio-cucumberjs-json-reporter')
//const logger = log4js.getLogger('default')
const _ = require('lodash')
const timeStamp = new Date().toLocaleString()
const envRoot = (process.env.TEST_ENVIRONMENT_ROOT_URL || 'http://host.docker.internal:3004')
const chromeArgs = process.env.CHROME_ARGS ? process.env.CHROME_ARGS.split(' ') : []
Expand Down
2 changes: 1 addition & 1 deletion test/integration/narrow/routes/view-agreement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function expectApplicationDetails ($) {
expect($('.govuk-summary-list__row').length).toEqual(5)

expect($('.govuk-summary-list__key').eq(0).text()).toMatch('Name')
expect($('.govuk-summary-list__value').eq(0).text()).toMatch('Farmer name')
expect($('.govuk-summary-list__value').eq(0).text()).toMatch('My Farm')

expect($('.govuk-summary-list__key').eq(1).text()).toMatch('SBI number')
expect($('.govuk-summary-list__value').eq(1).text()).toMatch('333333333')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('View Application test with Date of Testing enabled', () => {
expect($('title').text()).toContain('Administration: User Agreement')
expect($('.govuk-summary-list__row').length).toEqual(5)
expect($('.govuk-summary-list__key').eq(0).text()).toMatch('Name')
expect($('.govuk-summary-list__value').eq(0).text()).toMatch('Farmer name')
expect($('.govuk-summary-list__value').eq(0).text()).toMatch('My Farm')

expect($('.govuk-summary-list__key').eq(1).text()).toMatch('SBI number')
expect($('.govuk-summary-list__value').eq(1).text()).toMatch('333333333')
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('View Application test with Date of Testing enabled', () => {
expect($('title').text()).toContain('Administration: User Agreement')
expect($('.govuk-summary-list__row').length).toEqual(5)
expect($('.govuk-summary-list__key').eq(0).text()).toMatch('Name')
expect($('.govuk-summary-list__value').eq(0).text()).toMatch('Farmer name')
expect($('.govuk-summary-list__value').eq(0).text()).toMatch('My Farm')

expect($('.govuk-summary-list__key').eq(1).text()).toMatch('SBI number')
expect($('.govuk-summary-list__value').eq(1).text()).toMatch('333333333')
Expand Down
8 changes: 4 additions & 4 deletions test/integration/narrow/routes/view-claim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('View claim test', () => {
offerStatus: 'accepted',
organisation: {
sbi: '113494460',
name: 'Mrs S Clark',
name: 'Test Farm Lodge',
email: '[email protected]',
orgEmail: '[email protected]',
address:
Expand Down Expand Up @@ -216,14 +216,14 @@ describe('View claim test', () => {
const content = [
{ key: 'Agreement number', value: 'AHWR-1234-APP1' },
{ key: 'Agreement date', value: '22/03/2024' },
{ key: 'Agreement holder', value: 'Russell Paul Davies' },
{ key: 'Agreement holder', value: 'Test Farm Lodge' },
{ key: 'Agreement holder email', value: '[email protected]' },
{ key: 'SBI number', value: '113494460' },
{ key: 'Address', value: 'Tesco Stores Ltd,Harwell,Betton,WHITE HOUSE FARM,VINCENT CLOSE,LEIGHTON BUZZARD,HR2 8AN,United Kingdom' },
{ key: 'Business email', value: '[email protected]' },
{ key: 'Status', value: 'Paid' },
{ key: 'Claim date', value: '25/03/2024' },
{ key: 'Business name', value: 'Mrs S Clark' },
{ key: 'Business name', value: 'Test Farm Lodge' },
{ key: 'Livestock', value: 'Pigs' },
{ key: 'Type of visit', value: 'Animal health and welfare review' },
{ key: 'Date of visit', value: '22/03/2024' },
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('View claim test', () => {
null,
{ key: 'Status', value: 'Recommended to pay' },
{ key: 'Claim date', value: '20/03/2024' },
{ key: 'Business name', value: 'Mrs S Clark' },
{ key: 'Business name', value: 'Test Farm Lodge' },
{ key: 'Livestock', value: 'Sheep' },
{ key: 'Type of visit', value: 'Endemic disease follow-ups' },
{ key: 'Date of visit', value: '22/03/2024' },
Expand Down
Loading

0 comments on commit 6090ad5

Please sign in to comment.