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 all 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
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()
})
})
})
})
Loading