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

Licence Import Supplementary billing test endpoint #1435

Merged
merged 9 commits into from
Oct 22, 2024
32 changes: 30 additions & 2 deletions app/controllers/check.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,36 @@
* @module CheckController
*/

const DetermineSupplementaryBillingFlagsService = require('../services/import/determine-supplementary-billing-flags.service.js')
const ProcessLicenceReturnLogsService = require('../services/jobs/return-logs/process-licence-return-logs.service.js')

const redirectStatusCode = 204
const NO_CONTENT_STATUS_CODE = 204

/**
* A test end point for the licence supplementary billing flags process
*
* This endpoint takes a licenceId and an expired, lapsed and revoked date. It passes this onto the
* `DetermineSupplementaryBillingFlagsService` to test if it correctly flags the licence for supplementary billing. This
* normally happens during the licence import process.
*
* @param request - the hapi request object
* @param h - the hapi response object
*
* @returns {Promise<object>} - A promise that resolves to an HTTP response object with a 204 status code
*/
async function flagForBilling (request, h) {
const { licenceId, expiredDate, lapsedDate, revokedDate } = request.payload

const transformedLicence = {
expiredDate,
lapsedDate,
revokedDate
}

await DetermineSupplementaryBillingFlagsService.go(transformedLicence, licenceId)

return h.response().code(NO_CONTENT_STATUS_CODE)
}

/**
* A test end point to create return logs for a given licence reference
Expand All @@ -28,9 +55,10 @@ async function returnLogsForLicence (_request, h) {

ProcessLicenceReturnLogsService.go(licenceReference)

return h.response().code(redirectStatusCode)
return h.response().code(NO_CONTENT_STATUS_CODE)
}

module.exports = {
flagForBilling,
returnLogsForLicence
}
15 changes: 15 additions & 0 deletions app/routes/check.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
const CheckController = require('../controllers/check.controller.js')

const routes = [
{
method: 'POST',
path: '/check/flag-for-billing',
options: {
handler: CheckController.flagForBilling,
app: {
excludeFromProd: true,
plainOutput: true
},
auth: false,
plugins: {
crumb: false
}
}
},
{
method: 'POST',
path: '/check/licence-return-logs',
Expand Down
Loading