diff --git a/app/controllers/bill-runs.controller.js b/app/controllers/bill-runs.controller.js index ed7073a363..9f62a49676 100644 --- a/app/controllers/bill-runs.controller.js +++ b/app/controllers/bill-runs.controller.js @@ -13,7 +13,6 @@ const AmendBillableReturnsService = require('../services/bill-runs/two-part-tari const CalculateChargeService = require('../services/bill-runs/two-part-tariff/calculate-charge.service.js') const CancelBillRunService = require('../services/bill-runs/cancel-bill-run.service.js') const ChargeReferenceDetailsService = require('../services/bill-runs/two-part-tariff/charge-reference-details.service.js') -const CreateBillRunValidator = require('../validators/create-bill-run.validator.js') const GenerateBillRunService = require('../services/bill-runs/two-part-tariff/generate-bill-run.service.js') const IndexBillRunsService = require('../services/bill-runs/index-bill-runs.service.js') const MatchDetailsService = require('../services/bill-runs/two-part-tariff/match-details.service.js') @@ -21,7 +20,6 @@ const RemoveBillRunLicenceService = require('../services/bill-runs/two-part-tari const ReviewBillRunService = require('../services/bill-runs/two-part-tariff/review-bill-run.service.js') const ReviewLicenceService = require('../services/bill-runs/two-part-tariff/review-licence.service.js') const SendBillRunService = require('../services/bill-runs/send-bill-run.service.js') -const StartBillRunProcessService = require('../services/bill-runs/start-bill-run-process.service.js') const SubmitAmendedAdjustmentFactorService = require('../services/bill-runs/two-part-tariff/submit-amended-adjustment-factor.service.js') const SubmitAmendedAuthorisedVolumeService = require('../services/bill-runs/two-part-tariff/submit-amended-authorised-volume.service.js') const SubmitAmendedBillableReturnsService = require('..//services/bill-runs/two-part-tariff/submit-amended-billable-returns.service.js') @@ -92,23 +90,6 @@ async function chargeReferenceDetails (request, h) { }) } -async function create (request, h) { - const validatedData = CreateBillRunValidator.go(request.payload) - - if (validatedData.error) { - return Boom.badRequest(validatedData.error.details[0].message) - } - - try { - const { region, type, user, financialYearEnding } = validatedData.value - const result = await StartBillRunProcessService.go(region, type, user, financialYearEnding) - - return h.response(result).code(200) - } catch (error) { - return Boom.badImplementation(error.message) - } -} - async function index (request, h) { const { page } = request.query @@ -328,7 +309,6 @@ module.exports = { amendBillableReturns, cancel, chargeReferenceDetails, - create, index, matchDetails, previewCharge, diff --git a/app/routes/bill-runs.routes.js b/app/routes/bill-runs.routes.js index 348e0e6665..598e9f7e9d 100644 --- a/app/routes/bill-runs.routes.js +++ b/app/routes/bill-runs.routes.js @@ -18,21 +18,6 @@ const routes = [ } } }, - { - method: 'POST', - path: '/bill-runs', - options: { - handler: BillRunsController.create, - app: { - plainOutput: true - }, - auth: { - access: { - scope: ['billing'] - } - } - } - }, { method: 'GET', path: '/bill-runs/{id}', diff --git a/app/validators/create-bill-run.validator.js b/app/validators/create-bill-run.validator.js deleted file mode 100644 index 800fe3e7c4..0000000000 --- a/app/validators/create-bill-run.validator.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict' - -/** - * @module CreateBillRunValidator - */ - -const Joi = require('joi') - -const StaticLookupsLib = require('../lib/static-lookups.lib.js') - -/** - * Checks that the payload of a `create bill run` request is valid -*/ -function go (data) { - const schema = Joi.object({ - type: Joi.string().valid(...StaticLookupsLib.billRunTypes).required(), - scheme: Joi.string().valid('sroc').required(), - region: Joi.string().guid().required(), - user: Joi.string().email().required(), - financialYearEnding: Joi.number().integer().optional(), - previousBillRunId: Joi.string().guid().optional() - }) - - return schema.validate(data) -} - -module.exports = { - go -} diff --git a/test/controllers/bill-runs.controller.test.js b/test/controllers/bill-runs.controller.test.js index b93e83905c..83d0b38394 100644 --- a/test/controllers/bill-runs.controller.test.js +++ b/test/controllers/bill-runs.controller.test.js @@ -26,7 +26,6 @@ const RemoveBillRunLicenceService = require('../../app/services/bill-runs/two-pa const ReviewBillRunService = require('../../app/services/bill-runs/two-part-tariff/review-bill-run.service.js') const ReviewLicenceService = require('../../app/services/bill-runs/two-part-tariff/review-licence.service.js') const SendBillRunService = require('../../app/services/bill-runs/send-bill-run.service.js') -const StartBillRunProcessService = require('../../app/services/bill-runs/start-bill-run-process.service.js') const SubmitAmendedAdjustmentFactorService = require('../../app/services/bill-runs/two-part-tariff/submit-amended-adjustment-factor.service.js') const SubmitAmendedAuthorisedVolumeService = require('../../app/services/bill-runs/two-part-tariff/submit-amended-authorised-volume.service.js') const SubmitAmendedBillableReturnsService = require('../../app/services/bill-runs/two-part-tariff/submit-amended-billable-returns.service.js') @@ -115,73 +114,6 @@ describe('Bill Runs controller', () => { }) }) }) - - describe('POST', () => { - beforeEach(() => { - options = postRequestOptions( - '/bill-runs', - { - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk' - } - ) - }) - - describe('when a request is valid', () => { - const validResponse = { - id: 'f561990b-b29a-42f4-b71a-398c52339f78', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - scheme: 'sroc', - batchType: 'supplementary', - status: 'processing' - } - - beforeEach(async () => { - Sinon.stub(StartBillRunProcessService, 'go').resolves(validResponse) - }) - - it('returns a 200 response including details of the new bill run', async () => { - const response = await server.inject(options) - const payload = JSON.parse(response.payload) - - expect(response.statusCode).to.equal(200) - expect(payload).to.equal(validResponse) - }) - }) - - describe('when the request fails', () => { - describe('because the request is invalid', () => { - beforeEach(() => { - options.payload.scheme = 'INVALID' - }) - - it('returns an error response', async () => { - const response = await server.inject(options) - const payload = JSON.parse(response.payload) - - expect(response.statusCode).to.equal(400) - expect(payload.message).to.startWith('"scheme" must be') - }) - }) - - describe('because the bill run could not be initiated', () => { - beforeEach(async () => { - Sinon.stub(Boom, 'badImplementation').returns(new Boom.Boom('Bang', { statusCode: 500 })) - Sinon.stub(StartBillRunProcessService, 'go').rejects() - }) - - it('returns an error response', async () => { - const response = await server.inject(options) - const payload = JSON.parse(response.payload) - - expect(response.statusCode).to.equal(500) - expect(payload.message).to.equal('An internal server error occurred') - }) - }) - }) - }) }) describe('/bill-runs/{id}', () => { diff --git a/test/validators/create-bill-run.validator.test.js b/test/validators/create-bill-run.validator.test.js deleted file mode 100644 index 1f1206a4d2..0000000000 --- a/test/validators/create-bill-run.validator.test.js +++ /dev/null @@ -1,215 +0,0 @@ -'use strict' - -// Test framework dependencies -const Lab = require('@hapi/lab') -const Code = require('@hapi/code') - -const { describe, it } = exports.lab = Lab.script() -const { expect } = Code - -// Thing under test -const CreateBillRunValidator = require('../../app/validators/create-bill-run.validator.js') - -describe('Create Bill Run validator', () => { - describe('when valid data is provided', () => { - it('returns validated data', async () => { - const validData = { - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk', - financialYearEnding: 2023, - previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603' - } - - const result = await CreateBillRunValidator.go(validData) - - expect(result.value).to.equal({ - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk', - financialYearEnding: 2023, - previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603' - }) - }) - - describe('which does not include "financialYearEnding"', () => { - it('returns validated data', async () => { - const validData = { - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk', - previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603' - } - - const result = await CreateBillRunValidator.go(validData) - - expect(result.value).to.equal({ - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk', - previousBillRunId: '28a5fc2e-bdc9-4b48-96e7-5ee7b2f5d603' - }) - }) - }) - - describe('which does not include "previousBillRunId"', () => { - it('returns validated data', async () => { - const validData = { - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk', - financialYearEnding: 2023 - } - - const result = await CreateBillRunValidator.go(validData) - - expect(result.value).to.equal({ - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk', - financialYearEnding: 2023 - }) - }) - }) - }) - - describe('when invalid data is provided', () => { - describe('because "type" is missing', () => { - it('returns an error', async () => { - const invalidData = { - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - - describe('because "scheme" is missing', () => { - it('returns an error', async () => { - const invalidData = { - type: 'supplementary', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - - describe('because "region" is missing', () => { - it('returns an error', async () => { - const invalidData = { - type: 'supplementary', - scheme: 'sroc', - user: 'test.user@defra.gov.uk' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - - describe('because "user" is missing', () => { - it('returns an error', async () => { - const invalidData = { - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - - describe('because "type" has an invalid value', () => { - it('returns an error', async () => { - const invalidData = { - type: 'INVALID', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - - describe('because "scheme" has an invalid value', () => { - it('returns an error', async () => { - const invalidData = { - type: 'supplementary', - scheme: 'INVALID', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - - describe('because "region" has an invalid value', () => { - it('returns an error', async () => { - const invalidData = { - type: 'supplementary', - scheme: 'sroc', - region: 'INVALID', - user: 'test.user@defra.gov.uk' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - - describe('because "user" has an invalid value', () => { - it('returns an error', async () => { - const invalidData = { - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'INVALID' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - - describe('because "financialYearEnding" has an invalid value', () => { - it('returns an error', async () => { - const invalidData = { - type: 'supplementary', - scheme: 'sroc', - region: '07ae7f3a-2677-4102-b352-cc006828948c', - user: 'test.user@defra.gov.uk', - financialYearEnding: 'INVALID' - } - - const result = await CreateBillRunValidator.go(invalidData) - - expect(result.error).to.not.be.empty() - }) - }) - }) -})