Skip to content

Commit

Permalink
Deleted agreements shouldn't show in the setup tab (#1220)
Browse files Browse the repository at this point in the history
* Deleted agreements shouldn't show in the setup tab

https://eaflood.atlassian.net/browse/WATER-4604

Currently, when an agreement is deleted within the licence set up tab, the agreement still remains.
This is because the agreement is being 'soft deleted' rather than being removed from the database
completely by adding the current time and date to the 'deleted_at' column in the licence agreements table.
The logic for pulling licence agreements is missing instructions to only show licence agreements where the 'deleted_at' is null.

This PR is focused on not showing licence agreements in the licence set up tab where the licence has the 'deleted_at' column populated.
  • Loading branch information
rvsiyad authored Aug 2, 2024
1 parent eac0be2 commit 9a9e239
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
1 change: 1 addition & 0 deletions app/services/licences/fetch-agreements.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async function go (licenceRef) {
async function _fetch (licenceRef) {
return LicenceAgreementModel.query()
.where('licenceRef', licenceRef)
.whereNull('deletedAt')
.select([
'id',
'startDate',
Expand Down
72 changes: 46 additions & 26 deletions test/services/licences/fetch-agreements.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,70 @@
const Lab = require('@hapi/lab')
const Code = require('@hapi/code')

const { describe, it, beforeEach } = exports.lab = Lab.script()
const { describe, it, before, beforeEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const DatabaseSupport = require('../../support/database.js')
const FinancialAgreementHelper = require('../../support/helpers/financial-agreement.helper.js')
const LicenceAgreementHelper = require('../../support/helpers/licence-agreement.helper.js')

// Thing under test
const FetchAgreementsService =
require('../../../app/services/licences/fetch-agreements.service.js')
const FetchAgreementsService = require('../../../app/services/licences/fetch-agreements.service.js')

describe('Fetch Agreements service', () => {
const licenceRef = '01/12/34/1000'
const endDate = new Date('2040-05-01')
const signedOn = new Date('2022-04-01')
const startDate = new Date('2022-04-01')

beforeEach(async () => {
await DatabaseSupport.clean()
})
let licenceAgreement
let financialAgreement

describe('when the licence has agreements data', () => {
beforeEach(async () => {
const financialAgreement = await FinancialAgreementHelper.add({
id: '970168ce-06c3-4823-b84d-9da30b742bb8',
code: 'S127'
before(async () => {
financialAgreement = await FinancialAgreementHelper.add()
})

describe('and the agreement has not been deleted', () => {
beforeEach(async () => {
licenceAgreement = await LicenceAgreementHelper.add({
endDate,
financialAgreementId: financialAgreement.id,
startDate,
signedOn
})
})

await LicenceAgreementHelper.add({
endDate: new Date('2040-05-01'),
financialAgreementId: financialAgreement.id,
licenceRef,
startDate: new Date('2022-04-01'),
signedOn: new Date('2022-04-01')
it('returns the matching agreements data', async () => {
const results = await FetchAgreementsService.go(licenceAgreement.licenceRef)

expect(results[0]).to.equal({
endDate,
financialAgreement: {
id: financialAgreement.id,
code: financialAgreement.code
},
startDate,
signedOn
}, { skip: ['id'] })
})
})

it('returns the matching agreements data', async () => {
const results = await FetchAgreementsService.go(licenceRef)
describe('and the agreement has been deleted', () => {
beforeEach(async () => {
licenceAgreement = await LicenceAgreementHelper.add({
endDate,
financialAgreementId: financialAgreement.id,
startDate,
signedOn,
deletedAt: new Date()
})
})

it('does not return the agreements data', async () => {
const results = await FetchAgreementsService.go(licenceAgreement.licenceRef)

expect(results[0]).to.equal({
startDate: new Date('2022-04-01'),
signedOn: new Date('2022-04-01'),
endDate: new Date('2040-05-01'),
financialAgreement: { id: '970168ce-06c3-4823-b84d-9da30b742bb8', code: 'S127' }
}, { skip: ['id'] })
expect(results).to.be.empty()
})
})
})
})

0 comments on commit 9a9e239

Please sign in to comment.