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 10 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
66 changes: 41 additions & 25 deletions test/services/licences/fetch-agreements.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,62 @@ const { describe, it, 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'

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

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

describe('and the agreement has not been deleted', () => {
beforeEach(async () => {
licenceAgreement = await LicenceAgreementHelper.add({
endDate: new Date('2040-05-01'),
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
financialAgreementId: financialAgreement.id,
startDate: new Date('2022-04-01'),
signedOn: new Date('2022-04-01')
})
})

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({
startDate: new Date('2022-04-01'),
signedOn: new Date('2022-04-01'),
endDate: new Date('2040-05-01'),
financialAgreement: {
id: financialAgreement.id,
code: financialAgreement.code
}
}, { 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: new Date('2040-05-01'),
financialAgreementId: financialAgreement.id,
startDate: new Date('2022-04-01'),
signedOn: new Date('2022-04-01'),
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