diff --git a/test/services/bill-runs/fetch-bill-runs.service.test.js b/test/services/bill-runs/fetch-bill-runs.service.test.js index 670fd25427..bae158e04e 100644 --- a/test/services/bill-runs/fetch-bill-runs.service.test.js +++ b/test/services/bill-runs/fetch-bill-runs.service.test.js @@ -10,6 +10,7 @@ const { expect } = Code // Test helpers const BillRunHelper = require('../../support/helpers/bill-run.helper.js') +const BillRunModel = require('../../../app/models/bill-run.model.js') const DatabaseConfig = require('../../../config/database.config.js') const RegionHelper = require('../../support/helpers/region.helper.js') @@ -103,6 +104,27 @@ describe('Fetch Bill Runs service', () => { }) }) }) + + describe('when there are no bill runs', () => { + beforeEach(async () => { + // There will usually be bill runs in the database from other tests so we stub the query to simulate no bill runs + const queryStub = Sinon.stub(BillRunModel, 'query') + + queryStub.returns({ + select: Sinon.stub().returnsThis(), + innerJoinRelated: Sinon.stub().returnsThis(), + orderBy: Sinon.stub().returnsThis(), + page: Sinon.stub().resolves({ results: [], total: 0 }) + }) + }) + + it('returns a result with no "results" and 0 for "total"', async () => { + const result = await FetchBillRunsService.go() + + expect(result.results).to.be.empty() + expect(result.total).to.equal(0) + }) + }) }) function _addBillRun (billRunNumber, createdAt, netTotal, creditNoteCount, invoiceCount, regionId) {