Skip to content

Commit

Permalink
fix: showing correct data for sheep (#26)
Browse files Browse the repository at this point in the history
* fix: showing correct data for sheep

* fix: linting

* refactor: sheep data

* refactor: sheep data

* fix: tests

* refactor: view application data rows

* feat: bump version
  • Loading branch information
shivanshuit914 authored Aug 8, 2022
1 parent 792d297 commit 7aa9699
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
35 changes: 22 additions & 13 deletions app/routes/view-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ const getFarmerApplication = (application) => {
}
}

const getSheepDataRows = (data, formatedDate) => {
const rows = []
if (data.sheepWorms) rows.push([{ text: formatedDate }, { text: 'Worms in sheep?' }, { text: upperFirstLetter(data.sheepWorms) }])
if (data.speciesTest) rows.push([{ text: formatedDate }, { text: 'Percentage reduction in EPG?' }, { text: data.speciesTest }])
if (data.sheepWormTreatment) rows.push([{ text: formatedDate }, { text: 'Active chemical used in worming treatment' }, { text: upperFirstLetter(data.sheepWormTreatment) }])

return rows
}

const getCattleDataRows = (data, formatedDate) => {
const rows = []
if (data.speciesVaccinated) rows.push([{ text: formatedDate }, { text: 'Species Vaccinated?' }, { text: upperFirstLetter(data.speciesVaccinated) }])
if (data.speciesLastVaccinated) rows.push([{ text: formatedDate }, { text: 'Last Vaccinated?' }, { text: `${data.speciesLastVaccinated.month}-${data.speciesLastVaccinated.year}` }])
if (data.speciesVaccinationUpToDate) rows.push([{ text: formatedDate }, { text: 'Vaccination up to date?' }, { text: upperFirstLetter(data.speciesVaccinationUpToDate) }])
return rows
}

const getVetVisitData = (vetVisit, species) => {
const { data, createdAt } = vetVisit
const formatedDate = formatedDateToUk(createdAt)
Expand All @@ -40,28 +57,20 @@ const getVetVisitData = (vetVisit, species) => {
[{ text: formatedDate }, { text: eligibleSpecies[species] }, { text: upperFirstLetter(data.eligibleSpecies) }]
)

if (data.speciesBvdInHerd) {
if (data.speciesBvdInHerd && (species === 'beef' || species === 'dairy')) {
rows.push([{ text: formatedDate }, { text: 'BVD in herd?' }, { text: upperFirstLetter(data.speciesBvdInHerd) }])
}

if (data.speciesTest && species === 'pigs') {
rows.push([{ text: formatedDate }, { text: 'PRRS in herd?' }, { text: upperFirstLetter(data.speciesTest) }])
}

if (data.speciesVaccinated) {
rows.push([{ text: formatedDate }, { text: 'Species Vaccinated?' }, { text: upperFirstLetter(data.speciesVaccinated) }])
}

if (data.speciesLastVaccinated) {
rows.push([{ text: formatedDate }, { text: 'Last Vaccinated?' }, { text: `${data.speciesLastVaccinated.month}-${data.speciesLastVaccinated.year}` }])
}

if (data.speciesVaccinationUpToDate) {
rows.push([{ text: formatedDate }, { text: 'Vaccination up to date?' }, { text: upperFirstLetter(data.speciesVaccinationUpToDate) }])
if (data.speciesVaccinated && (species === 'beef' || species === 'dairy')) {
rows.push(...getCattleDataRows(data, formatedDate))
}

if (data.sheepWorms) {
rows.push([{ text: formatedDate }, { text: 'Worms in sheep?' }, { text: upperFirstLetter(data.sheepWorms) }])
if (data.sheepWorms && species === 'sheep') {
rows.push(...getSheepDataRows(data, formatedDate))
}

rows.push([{ text: formatedDate }, { text: 'Report given?' }, { text: upperFirstLetter(data.reviewReport) }])
Expand Down
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.8.1",
"version": "1.8.2",
"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
3 changes: 2 additions & 1 deletion test/data/view-applications.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"eligibleSpecies": "yes",
"sheepWorms": "yes",
"reviewReport": "yes",
"speciesBvdInHerd": "yes"
"sheepWormTreatment": "LV",
"speciesTest": 40
},
"createdAt": "2022-06-06T14:27:51.251Z"
},
Expand Down
12 changes: 7 additions & 5 deletions test/integration/narrow/routes/view-application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ describe('View Application test', () => {
expect($('tbody:nth-child(2) tr:nth-child(1) td:nth-child(3)').text()).toContain('06/06/2022')
expect($('tbody:nth-child(2) tr:nth-child(2) td:nth-child(2)').text()).toContain(eligibleSpecies.sheep)
expect($('tbody:nth-child(2) tr:nth-child(2) td:nth-child(3)').text()).toContain('Yes')
expect($('tbody:nth-child(2) tr:nth-child(3) td:nth-child(2)').text()).toContain('BVD in herd?')
expect($('tbody:nth-child(2) tr:nth-child(3) td:nth-child(2)').text()).toContain('Worms in sheep?')
expect($('tbody:nth-child(2) tr:nth-child(3) td:nth-child(3)').text()).toContain('Yes')
expect($('tbody:nth-child(2) tr:nth-child(4) td:nth-child(2)').text()).toContain('Worms in sheep?')
expect($('tbody:nth-child(2) tr:nth-child(4) td:nth-child(3)').text()).toContain('Yes')
expect($('tbody:nth-child(2) tr:nth-child(5) td:nth-child(2)').text()).toContain('Report given?')
expect($('tbody:nth-child(2) tr:nth-child(5) td:nth-child(3)').text()).toContain('Yes')
expect($('tbody:nth-child(2) tr:nth-child(4) td:nth-child(2)').text()).toContain('Percentage reduction in EPG?')
expect($('tbody:nth-child(2) tr:nth-child(4) td:nth-child(3)').text()).toContain('40')
expect($('tbody:nth-child(2) tr:nth-child(5) td:nth-child(2)').text()).toContain('Active chemical used in worming treatment')
expect($('tbody:nth-child(2) tr:nth-child(5) td:nth-child(3)').text()).toContain('LV')
expect($('tbody:nth-child(2) tr:nth-child(6) td:nth-child(2)').text()).toContain('Report given?')
expect($('tbody:nth-child(2) tr:nth-child(6) td:nth-child(3)').text()).toContain('Yes')
expect($('#claim').text()).toContain('Not yet able to claim')
expect($('#payment').text()).toContain('Not yet paid')
expectPhaseBanner.ok($)
Expand Down

0 comments on commit 7aa9699

Please sign in to comment.