Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleted agreements shouldn't show in the setup tab #1220

Merged
merged 13 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
40 changes: 29 additions & 11 deletions test/services/licences/fetch-agreements.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const FinancialAgreementHelper = require('../../support/helpers/financial-agreem
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'
let licenceAgreementData

beforeEach(async () => {
await DatabaseSupport.clean()
Expand All @@ -30,24 +30,42 @@ describe('Fetch Agreements service', () => {
code: 'S127'
})

await LicenceAgreementHelper.add({
licenceAgreementData = {
endDate: new Date('2040-05-01'),
financialAgreementId: financialAgreement.id,
licenceRef,
startDate: new Date('2022-04-01'),
signedOn: new Date('2022-04-01')
}
})

describe('and the agreement has not been deleted', () => {
beforeEach(async () => {
await LicenceAgreementHelper.add(licenceAgreementData)
})

it('returns the matching agreements data', async () => {
const results = await FetchAgreementsService.go(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'] })
})
})

it('returns the matching agreements data', async () => {
const results = await FetchAgreementsService.go(licenceRef)
describe('and the agreement has been deleted', () => {
beforeEach(async () => {
await LicenceAgreementHelper.add(licenceAgreementData.deletedAt = new Date())
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
})

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'] })
it('does not return the agreements data', async () => {
const results = await FetchAgreementsService.go(licenceRef)

expect(results).to.be.empty()
})
})
})
})
Loading