diff --git a/app/controllers/bill-runs.controller.js b/app/controllers/bill-runs.controller.js index 577bf64df5..a4d47a345a 100644 --- a/app/controllers/bill-runs.controller.js +++ b/app/controllers/bill-runs.controller.js @@ -46,8 +46,7 @@ async function create (request, h) { async function review (request, h) { const { id } = request.params - - const pageData = await ReviewBillRunService.go(id) + const pageData = await ReviewBillRunService.go(id, request.payload) return h.view('bill-runs/review.njk', { pageTitle: 'Review licences', diff --git a/app/models/bill-run.model.js b/app/models/bill-run.model.js index 8f0c7d1fb9..c1dd698222 100644 --- a/app/models/bill-run.model.js +++ b/app/models/bill-run.model.js @@ -16,12 +16,12 @@ class BillRunModel extends BaseModel { static get relationMappings () { return { - region: { - relation: Model.BelongsToOneRelation, - modelClass: 'region.model', + billRunVolumes: { + relation: Model.HasManyRelation, + modelClass: 'bill-run-volume.model', join: { - from: 'billRuns.regionId', - to: 'regions.id' + from: 'billRuns.id', + to: 'billRunVolumes.billRunId' } }, bills: { @@ -32,12 +32,20 @@ class BillRunModel extends BaseModel { to: 'bills.billRunId' } }, - billRunVolumes: { + region: { + relation: Model.BelongsToOneRelation, + modelClass: 'region.model', + join: { + from: 'billRuns.regionId', + to: 'regions.id' + } + }, + reviewLicences: { relation: Model.HasManyRelation, - modelClass: 'bill-run-volume.model', + modelClass: 'review-licence.model', join: { from: 'billRuns.id', - to: 'billRunVolumes.billRunId' + to: 'reviewLicences.billRunId' } } } diff --git a/app/models/review-licence.model.js b/app/models/review-licence.model.js index aa9c89f23b..b7e3636573 100644 --- a/app/models/review-licence.model.js +++ b/app/models/review-licence.model.js @@ -16,6 +16,14 @@ class ReviewLicenceModel extends BaseModel { static get relationMappings () { return { + billRun: { + relation: Model.BelongsToOneRelation, + modelClass: 'bill-run.model', + join: { + from: 'reviewLicences.billRunId', + to: 'billRuns.id' + } + }, licence: { relation: Model.BelongsToOneRelation, modelClass: 'licence.model', diff --git a/app/presenters/bill-runs/two-part-tariff/review-bill-run.presenter.js b/app/presenters/bill-runs/two-part-tariff/review-bill-run.presenter.js index 7f9509422b..1f2887b20b 100644 --- a/app/presenters/bill-runs/two-part-tariff/review-bill-run.presenter.js +++ b/app/presenters/bill-runs/two-part-tariff/review-bill-run.presenter.js @@ -10,26 +10,33 @@ const { formatLongDate } = require('../../base.presenter.js') /** * Prepares and processes bill run and licence data for presentation * - * @param {module:BillRunModel} billRun the data from the bill run - * @param {module:LicenceModel} licences the licences data asociated with the bill run + * @param {module:BillRunModel} billRun The data from the bill run + * @param {module:LicenceModel} licences The licences data asociated with the bill run + * @param {String} filterLicenceHolder The string that the licence holder is to be filtered on if any * - * @returns {Object} the prepared bill run and licence data to be passed to the review page + * @returns {Object} The prepared bill run and licence data to be passed to the review page */ -function go (billRun, licences) { - const { licencesToReviewCount, preparedLicences } = _prepareLicences(licences) +function go (billRun, licences, filterLicenceHolder) { + const { numberOfLicencesToReview, preparedLicences } = _prepareLicences(licences) - const preparedBillRun = _prepareBillRun(billRun, preparedLicences, licencesToReviewCount) + const preparedBillRun = _prepareBillRun(billRun, preparedLicences, numberOfLicencesToReview) + const filterData = { openFilter: false } - return { ...preparedBillRun, preparedLicences } + if (filterLicenceHolder) { + filterData.openFilter = true + filterData.licenceHolder = filterLicenceHolder + } + + return { ...preparedBillRun, preparedLicences, filterData } } function _prepareLicences (licences) { - let licencesToReviewCount = 0 + let numberOfLicencesToReview = 0 const preparedLicences = [] for (const licence of licences) { if (licence.status === 'review') { - licencesToReviewCount++ + numberOfLicencesToReview++ } preparedLicences.push({ @@ -41,18 +48,19 @@ function _prepareLicences (licences) { }) } - return { preparedLicences, licencesToReviewCount } + return { preparedLicences, numberOfLicencesToReview } } -function _prepareBillRun (billRun, billRunLicences, licencesToReviewCount) { +function _prepareBillRun (billRun, preparedLicences, numberOfLicencesToReview) { return { region: billRun.region.displayName, status: billRun.status, dateCreated: formatLongDate(billRun.createdAt), financialYear: _financialYear(billRun.toFinancialYearEnding), billRunType: 'two-part tariff', - numberOfLicences: billRunLicences.length, - licencesToReviewCount + numberOfLicencesDisplayed: preparedLicences.length, + numberOfLicencesToReview, + totalNumberOfLicences: billRun.reviewLicences[0].totalNumberOfLicences } } @@ -64,13 +72,12 @@ function _financialYear (financialYearEnding) { } function _getIssueOnLicence (issues) { - if (issues.length > 1) { + // if there is more than one issue the issues will be seperated by a comma + if (issues.includes(',')) { return 'Multiple Issues' - } else if (issues.length === 1) { - return issues[0] - } else { - return '' } + + return issues } module.exports = { diff --git a/app/routes/bill-runs.routes.js b/app/routes/bill-runs.routes.js index 95d359a2d0..b9d62a1e37 100644 --- a/app/routes/bill-runs.routes.js +++ b/app/routes/bill-runs.routes.js @@ -71,6 +71,19 @@ const routes = [ description: 'Review two-part tariff match and allocation results' } }, + { + method: 'POST', + path: '/bill-runs/{id}/review', + handler: BillRunsController.review, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'POST request recieved when filtering applied to review two-part tariff match and allocation results' + } + }, { method: 'GET', path: '/bill-runs/{id}/review/{licenceId}', diff --git a/app/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.js b/app/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.js index d3b0feea58..552bfa1457 100644 --- a/app/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.js +++ b/app/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.js @@ -15,41 +15,48 @@ const ReviewLicenceModel = require('../../../models/review-licence.model.js') * ref. * * @param {String} id The UUID for the bill run + * @param {Object} payload The `request.payload` containing the filter data. This only contains data when there is a + * POST request, which only occurs when a filter is applied to the results. * - * @returns {Promise} an object containing the billRun data and an array of licences for the bill run + * @returns {Promise} An object containing the billRun data and an array of licences for the bill run. Also + * included is any data that has been used to filter the results */ -async function go (id) { - const billRun = await _fetchBillRun(id) - const licences = await _fetchBillRunLicences(id) +async function go (id, payload) { + const filterLicenceHolder = payload?.filterLicenceHolder - return { billRun, licences } -} + const billRun = await _fetchBillRun(id) + const licences = await _fetchBillRunLicences(id, filterLicenceHolder) -async function _fetchBillRunLicences (id) { - return ReviewLicenceModel.query() - .where('billRunId', id) - .orderBy('status', 'desc') + return { billRun, licences, filterLicenceHolder } } async function _fetchBillRun (id) { return BillRunModel.query() .findById(id) - .select([ - 'id', - 'createdAt', - 'status', - 'toFinancialYearEnding', - 'batchType' - ]) + .select('id', 'createdAt', 'status', 'toFinancialYearEnding', 'batchType') .withGraphFetched('region') .modifyGraph('region', (builder) => { - builder.select([ - 'id', - 'displayName' - ]) + builder.select('id', 'displayName') + }) + .withGraphFetched('reviewLicences') + .modifyGraph('reviewLicences', (builder) => { + builder.count('licenceId as totalNumberOfLicences') + .groupBy('billRunId') }) } +async function _fetchBillRunLicences (id, filterLicenceHolder) { + const reviewLicenceQuery = ReviewLicenceModel.query() + .where('billRunId', id) + .orderBy('status', 'desc') + + if (filterLicenceHolder) { + reviewLicenceQuery.whereILike('licenceHolder', `%${filterLicenceHolder}%`) + } + + return reviewLicenceQuery +} + module.exports = { go } diff --git a/app/services/bill-runs/two-part-tariff/review-bill-run.service.js b/app/services/bill-runs/two-part-tariff/review-bill-run.service.js index 8b13e48083..0eb518652e 100644 --- a/app/services/bill-runs/two-part-tariff/review-bill-run.service.js +++ b/app/services/bill-runs/two-part-tariff/review-bill-run.service.js @@ -11,15 +11,17 @@ const ReviewBillRunPresenter = require('../../../presenters/bill-runs/two-part-t /** * Orchestrates fetching and presenting the data needed for the review bill run page * - * @param {string} id The UUID for the bill run to review + * @param {String} id The UUID for the bill run to review + * @param {Object} payload The `request.payload` containing the filter data. This is only passed to the service when + * there is a POST request, which only occurs when a filter is applied to the results. * - * @returns {Promise} an object representing the `pageData` needed by the review bill run template. It contains details of - * the bill run and the licences linked to it. + * @returns {Promise} An object representing the `pageData` needed by the review bill run template. It contains + * details of the bill run and the licences linked to it as well as any data that has been used to filter the results. */ -async function go (id) { - const { billRun, licences } = await FetchBillRunLicencesService.go(id) +async function go (id, payload = null) { + const { billRun, licences, filterLicenceHolder } = await FetchBillRunLicencesService.go(id, payload) - const pageData = ReviewBillRunPresenter.go(billRun, licences) + const pageData = ReviewBillRunPresenter.go(billRun, licences, filterLicenceHolder) return pageData } diff --git a/app/views/bill-runs/review.njk b/app/views/bill-runs/review.njk index 8c58ef1c6e..92ad01ecfa 100644 --- a/app/views/bill-runs/review.njk +++ b/app/views/bill-runs/review.njk @@ -13,12 +13,10 @@ {% block breadcrumbs %} {# Back link #} - {{ - govukBackLink({ + {{ govukBackLink({ text: 'Go back to bill runs', href: '/billing/batch/list' - }) - }} + }) }} {% endblock %} {% block content %} @@ -36,10 +34,10 @@ {% endif %}

- {{govukTag({ + {{ govukTag({ text: status, classes: colour - })}} + }) }}

{# Bill run meta-data #} @@ -102,10 +100,10 @@ {# Dynamic message either telling the user they have issues to deal with or that they can generate bills #} - {% if licencesToReviewCount > 0 %} + {% if numberOfLicencesToReview > 0 %}
{{ govukInsetText({ - text: 'You need to review ' + licencesToReviewCount + ' licences with returns data issues. You can then continue and send the bill run.' + text: 'You need to review ' + numberOfLicencesToReview + ' licences with returns data issues. You can then continue and send the bill run.' }) }}
{% else %} @@ -118,11 +116,51 @@
{{ govukButton({ classes: "govuk-button--secondary govuk-!-margin-bottom-0", - text: 'Cancel bill run', - href: 'cancel' + text: "Cancel bill run", + href: "cancel" }) }}
+ + {% set filtersForm %} +

Filter by

+ +
+ {{ govukInput({ + label: { + text: "Licence holder", + classes: "govuk-label--s", + isPageHeading: false + }, + classes: "govuk-input--width-20", + id: "filterLicenceHolder", + name: "filterLicenceHolder", + value: filterData.licenceHolder + }) }} + +
+ {{ govukButton({ + text: "Apply filters" + }) }} + + {{ govukButton({ + text: "Clear filters", + classes: "govuk-button--secondary ", + name: "clearFilters", + type: "reset", + href: "review" + }) }} +
+
+ {% endset %} + + {{ govukDetails({ + summaryText: "Filter licences", + html: filtersForm | safe, + classes: "govuk-!-margin-bottom-2", + open: filterData.openFilter + }) }} + {# Generate the row data for the table #} {% set tableRows = [] %} {% if preparedLicences.length > 0 %} @@ -154,9 +192,16 @@ {% endfor %} {% endif %} + {# Sets the caption to be used in the table below #} + {% if totalNumberOfLicences > numberOfLicencesDisplayed %} + {% set caption = "Showing " + numberOfLicencesDisplayed + " of " + totalNumberOfLicences + " licences" %} + {% else %} + {% set caption = "Showing all " + totalNumberOfLicences + " licences" %} + {% endif %} + {# Table displaying details of the licences in the bill run. These results take into account any filter that is set #} {{ govukTable({ - caption: "Showing all " + numberOfLicences + " licences", + caption: caption, captionClasses: "govuk-table__caption--s govuk-!-margin-bottom-2", firstCellIsHeader: false, head: [ diff --git a/test/controllers/bill-runs.controller.test.js b/test/controllers/bill-runs.controller.test.js index 170b9d4024..20ed8a894d 100644 --- a/test/controllers/bill-runs.controller.test.js +++ b/test/controllers/bill-runs.controller.test.js @@ -263,7 +263,66 @@ describe('Bill Runs controller', () => { expect(response.statusCode).to.equal(200) expect(response.payload).to.contain('two-part tariff') expect(response.payload).to.contain('Southern (Test replica)') - expect(response.payload).to.contain('Showing all 1 licences') + expect(response.payload).to.contain('Showing all 2 licences') + }) + }) + }) + + describe('POST /bill-runs/{id}/review', () => { + let options + + beforeEach(async () => { + options = { + method: 'POST', + url: '/bill-runs/97db1a27-8308-4aba-b463-8a6af2558b28/review', + auth: { + strategy: 'session', + credentials: { scope: ['billing'] } + } + } + }) + + describe('when a request is valid', () => { + describe('and no filters have been applied', () => { + beforeEach(() => { + Sinon.stub(ReviewBillRunService, 'go').resolves(_reviewBillRunData()) + }) + + it('returns a 200 response', async () => { + const response = await server.inject(options) + + expect(response.statusCode).to.equal(200) + expect(response.payload).to.contain('two-part tariff') + expect(response.payload).to.contain('Southern (Test replica)') + expect(response.payload).to.contain( + 'You need to review 1 licences with returns data issues. You can then continue and send the bill run.' + ) + expect(response.payload).to.contain('Showing all 2 licences') + }) + }) + + describe('and a filter has been applied', () => { + beforeEach(() => { + const reviewBillRunData = _reviewBillRunData() + + // edit the data to represent the filter being applied + reviewBillRunData.filterData = { openFilter: true, licenceHolder: 'big' } + reviewBillRunData.numberOfLicencesDisplayed = 1 + + Sinon.stub(ReviewBillRunService, 'go').resolves(reviewBillRunData) + }) + + it('returns a 200 response', async () => { + const response = await server.inject(options) + + expect(response.statusCode).to.equal(200) + expect(response.payload).to.contain('two-part tariff') + expect(response.payload).to.contain('Southern (Test replica)') + expect(response.payload).to.contain( + 'You need to review 1 licences with returns data issues. You can then continue and send the bill run.' + ) + expect(response.payload).to.contain('Showing 1 of 2 licences') + }) }) }) }) @@ -387,19 +446,27 @@ function _reviewBillRunData () { status: 'review', dateCreated: '6 November 2023', financialYear: '2021 to 2022', - chargeScheme: 'Current', billRunType: 'two-part tariff', - numberOfLicences: 1, - licencesToReviewCount: 1, - licences: [ + numberOfLicencesDisplayed: 2, + numberOfLicencesToReview: 1, + totalNumberOfLicences: 2, + preparedLicences: [ { licenceId: 'cc4bbb18-0d6a-4254-ac2c-7409de814d7e', licenceRef: '1/11/11/*1/1111', licenceHolder: 'Big Farm Ltd', - licenceIssues: 'Multiple Issues', - licenceStatus: 'review' + status: 'review', + issue: 'Multiple Issues' + }, + { + licenceId: '9442527a-64f3-471a-a3e4-fa0683a3d505', + licenceRef: '2/22/22/*2/2222', + licenceHolder: 'Small Farm Ltd', + status: 'ready', + issue: 'Multiple Issues' } - ] + ], + filterData: { openFilter: false } } } diff --git a/test/models/bill-run.model.test.js b/test/models/bill-run.model.test.js index 25c8bf1d39..d456270736 100644 --- a/test/models/bill-run.model.test.js +++ b/test/models/bill-run.model.test.js @@ -16,6 +16,8 @@ const BillRunVolumeModel = require('../../app/models/bill-run-volume.model.js') const DatabaseSupport = require('../support/database.js') const RegionHelper = require('../support/helpers/region.helper.js') const RegionModel = require('../../app/models/region.model.js') +const ReviewLicenceHelper = require('../support/helpers/review-licence.helper.js') +const ReviewLicenceModel = require('../../app/models/review-licence.model.js') // Thing under test const BillRunModel = require('../../app/models/bill-run.model.js') @@ -140,6 +142,42 @@ describe('Bill Run model', () => { expect(result.billRunVolumes).to.include(testBillRunVolumes[1]) }) }) + + describe('when linking to review Licences', () => { + let testReviewLicences + + beforeEach(async () => { + testRecord = await BillRunHelper.add() + const { id } = testRecord + + testReviewLicences = [] + for (let i = 0; i < 2; i++) { + const reviewLicence = await ReviewLicenceHelper.add({ billRunId: id }) + testReviewLicences.push(reviewLicence) + } + }) + + it('can successfully run a related query', async () => { + const query = await BillRunModel.query() + .innerJoinRelated('reviewLicences') + + expect(query).to.exist() + }) + + it('can eager load the review licences', async () => { + const result = await BillRunModel.query() + .findById(testRecord.id) + .withGraphFetched('reviewLicences') + + expect(result).to.be.instanceOf(BillRunModel) + expect(result.id).to.equal(testRecord.id) + + expect(result.reviewLicences).to.be.an.array() + expect(result.reviewLicences[0]).to.be.an.instanceOf(ReviewLicenceModel) + expect(result.reviewLicences).to.include(testReviewLicences[0]) + expect(result.reviewLicences).to.include(testReviewLicences[1]) + }) + }) }) describe('Static getters', () => { diff --git a/test/models/review-licence.model.test.js b/test/models/review-licence.model.test.js index 08cb6e5e56..27e20f60fd 100644 --- a/test/models/review-licence.model.test.js +++ b/test/models/review-licence.model.test.js @@ -9,6 +9,8 @@ const { expect } = Code // Test helpers const DatabaseSupport = require('../support/database.js') +const BillRunHelper = require('../support/helpers/bill-run.helper.js') +const BillRunModel = require('../../app/models/bill-run.model.js') const LicenceHelper = require('../support/helpers/licence.helper.js') const LicenceModel = require('../../app/models/licence.model.js') const ReviewChargeVersionHelper = require('../support/helpers/review-charge-version.helper.js') @@ -41,7 +43,36 @@ describe('Review Licence model', () => { }) describe('Relationships', () => { - describe('when linking to licence', () => { + describe('when linking to a bill run', () => { + let testBillRun + + beforeEach(async () => { + testBillRun = await BillRunHelper.add() + + testRecord = await ReviewLicenceHelper.add({ billRunId: testBillRun.id }) + }) + + it('can successfully run a related query', async () => { + const query = await ReviewLicenceModel.query() + .innerJoinRelated('billRun') + + expect(query).to.exist() + }) + + it('can eager load the bill run', async () => { + const result = await ReviewLicenceModel.query() + .findById(testRecord.id) + .withGraphFetched('billRun') + + expect(result).to.be.instanceOf(ReviewLicenceModel) + expect(result.id).to.equal(testRecord.id) + + expect(result.billRun).to.be.instanceOf(BillRunModel) + expect(result.billRun).to.equal(testBillRun) + }) + }) + + describe('when linking to a licence', () => { let testLicence beforeEach(async () => { diff --git a/test/presenters/bill-runs/two-part-tariff/review-bill-run.presenter.test.js b/test/presenters/bill-runs/two-part-tariff/review-bill-run.presenter.test.js index 2a89038684..dac9f9c17a 100644 --- a/test/presenters/bill-runs/two-part-tariff/review-bill-run.presenter.test.js +++ b/test/presenters/bill-runs/two-part-tariff/review-bill-run.presenter.test.js @@ -24,8 +24,9 @@ describe('Review Bill Run presenter', () => { dateCreated: '17 January 2024', financialYear: '2022 to 2023', billRunType: 'two-part tariff', - numberOfLicences: 3, - licencesToReviewCount: 1, + numberOfLicencesDisplayed: 3, + numberOfLicencesToReview: 1, + totalNumberOfLicences: 3, preparedLicences: [ { id: 'cc4bbb18-0d6a-4254-ac2c-7409de814d7e', @@ -48,7 +49,19 @@ describe('Review Bill Run presenter', () => { status: 'review', issue: 'Multiple Issues' } - ] + ], + filterData: { openFilter: false } + }) + }) + + describe('and a filter has been applied', () => { + const filterLicenceHolder = 'big farm' + + it('correctly presents the data', () => { + const result = ReviewBillRunPresenter.go(testBillRun, testLicences, filterLicenceHolder) + + expect(result.filterData.openFilter).to.equal(true) + expect(result.filterData.licenceHolder).to.equal(filterLicenceHolder) }) }) }) @@ -63,7 +76,8 @@ function _testBillRun () { batchType: 'two_part_tariff', region: { displayName: 'Southern (Test replica)' - } + }, + reviewLicences: [{ totalNumberOfLicences: 3 }] } } @@ -74,7 +88,7 @@ function _testLicences () { licenceId: 'cc4bbb18-0d6a-4254-ac2c-7409de814d7e', licenceRef: '1/11/11/*11/1111', licenceHolder: 'Big Farm Ltd', - issues: [], + issues: '', status: 'ready' }, // Licence with a single issue @@ -82,7 +96,7 @@ function _testLicences () { licenceId: '395bdc01-605b-44f5-9d90-5836cc013799', licenceRef: '2/22/22/*S2/2222', licenceHolder: 'Bob Bobbles', - issues: ['Abstraction outside period'], + issues: 'Abstraction outside period', status: 'ready' }, // Licence with multiple issues @@ -90,11 +104,7 @@ function _testLicences () { licenceId: 'fdae33da-9195-4b97-976a-9791bc4f6b66', licenceRef: '3/33/33/*3/3333', licenceHolder: 'Farmer Palmer', - issues: [ - 'Abstraction outside period', - 'Over abstraction', - 'Overlap of charge dates' - ], + issues: 'Abstraction outside period, Over abstraction, Overlap of charge dates', status: 'review' } ] diff --git a/test/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.test.js b/test/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.test.js index 3e6da92916..0543f8e110 100644 --- a/test/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.test.js +++ b/test/services/bill-runs/two-part-tariff/fetch-bill-run-licences.service.test.js @@ -32,10 +32,18 @@ describe('Fetch Bill Run Licences service', () => { describe('and there are licences in the bill run', () => { let testLicenceReady + let testLicenceReview beforeEach(async () => { - testLicenceReady = await ReviewLicenceHelper.add({ billRunId: billRun.id }) - await ReviewLicenceHelper.add({ billRunId: billRun.id, status: 'review' }) + testLicenceReady = await ReviewLicenceHelper.add({ + billRunId: billRun.id, + licenceHolder: 'Ready Licence Holder Ltd' + }) + testLicenceReview = await ReviewLicenceHelper.add({ + billRunId: billRun.id, + licenceHolder: 'Review Licence Holder Ltd', + status: 'review' + }) }) it('returns details of the bill run and the licences in it', async () => { @@ -47,11 +55,17 @@ describe('Fetch Bill Run Licences service', () => { expect(result.billRun.toFinancialYearEnding).to.equal(billRun.toFinancialYearEnding) expect(result.billRun.batchType).to.equal(billRun.batchType) expect(result.billRun.region.displayName).to.equal(region.displayName) + expect(result.billRun.reviewLicences[0].totalNumberOfLicences).to.equal(2) expect(result.licences).to.have.length(2) + expect(result.licences[0].licenceId).to.equal(testLicenceReview.licenceId) + expect(result.licences[0].licenceHolder).to.equal('Review Licence Holder Ltd') + expect(result.licences[0].licenceRef).to.equal(testLicenceReview.licenceRef) expect(result.licences[1].licenceId).to.equal(testLicenceReady.licenceId) - expect(result.licences[1].licenceHolder).to.equal('Licence Holder Ltd') + expect(result.licences[1].licenceHolder).to.equal('Ready Licence Holder Ltd') expect(result.licences[1].licenceRef).to.equal(testLicenceReady.licenceRef) + + expect(result.filterLicenceHolder).to.be.undefined() }) it("orders the licence by 'review status'", async () => { @@ -60,6 +74,39 @@ describe('Fetch Bill Run Licences service', () => { expect(result.licences[0].status).to.equal('review') expect(result.licences[1].status).to.equal('ready') }) + + describe('and a filter has been applied to the licence holder', () => { + let payload + + beforeEach(async () => { + payload = { filterLicenceHolder: 'ready licence' } + }) + + it('returns details of the bill run and the licences in it', async () => { + const result = await FetchBillRunLicencesService.go(billRun.id, payload) + + expect(result.billRun.id).to.equal(billRun.id) + expect(result.billRun.createdAt).to.equal(billRun.createdAt) + expect(result.billRun.status).to.equal(billRun.status) + expect(result.billRun.toFinancialYearEnding).to.equal(billRun.toFinancialYearEnding) + expect(result.billRun.batchType).to.equal(billRun.batchType) + expect(result.billRun.region.displayName).to.equal(region.displayName) + expect(result.billRun.reviewLicences[0].totalNumberOfLicences).to.equal(2) + + expect(result.licences).to.have.length(1) + expect(result.licences[0].licenceId).to.equal(testLicenceReady.licenceId) + expect(result.licences[0].licenceHolder).to.equal('Ready Licence Holder Ltd') + expect(result.licences[0].licenceRef).to.equal(testLicenceReady.licenceRef) + + expect(result.filterLicenceHolder).to.equal('ready licence') + }) + + it("orders the licence by 'review status'", async () => { + const result = await FetchBillRunLicencesService.go(billRun.id, payload) + + expect(result.licences[0].status).to.equal('ready') + }) + }) }) })