Skip to content

Commit

Permalink
Create add transaction endpoint (#80)
Browse files Browse the repository at this point in the history
This change creates the POST /v2/{regimeId}/bill-runs/{billRunId}/transactions endpoint, along with a v1 endpoint that passes the request to the 'not supported' controller.
  • Loading branch information
StuAA78 authored Dec 4, 2020
1 parent e95a1a2 commit 51557df
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const BaseCalculateChargeController = require('./base_calculate_charge.controlle

const NotSupportedController = require('./not_supported.controller')

const PresrocAddBillRunTransactionController = require('./presroc/add_bill_run_transaction.controller')
const PresrocBillRunsController = require('./presroc/bill_runs.controller')
const PresrocTransactionsController = require('./presroc/transactions.controller')
const PresrocCalculateChargeController = require('./presroc/calculate_charge.controller')
Expand All @@ -24,6 +25,7 @@ module.exports = {
AuthorisedSystemsController,
BaseCalculateChargeController,
DatabaseController,
PresrocAddBillRunTransactionController,
PresrocBillRunsController,
PresrocTransactionsController,
PresrocCalculateChargeController,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

class PresrocAddBillRunTransactionController {
static async create (_req, _h) {
return 'hello, pre-sroc add bill run transaction'
}
}

module.exports = PresrocAddBillRunTransactionController
18 changes: 16 additions & 2 deletions app/routes/bill_run.routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict'

const { NotSupportedController, PresrocBillRunsController } = require('../controllers')
const {
NotSupportedController,
PresrocAddBillRunTransactionController,
PresrocBillRunsController
} = require('../controllers')

const routes = [
{
Expand All @@ -10,8 +14,18 @@ const routes = [
},
{
method: 'POST',
path: '/v2/{regimeId}/billruns',
path: '/v2/{regimeId}/bill-runs',
handler: PresrocBillRunsController.create
},
{
method: 'POST',
path: '/v1/{regimeId}/billruns/{billRunId}/transactions',
handler: NotSupportedController.index
},
{
method: 'POST',
path: '/v2/{regimeId}/bill-runs/{billRunId}/transactions',
handler: PresrocAddBillRunTransactionController.create
}
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict'

// Test framework dependencies
const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const Sinon = require('sinon')

const { describe, it, before, after } = exports.lab = Lab.script()
const { expect } = Code

// For running our service
const { deployment } = require('../../../server')

// Test helpers
const { AuthorisationHelper } = require('../../support/helpers')

// Things we need to stub
const JsonWebToken = require('jsonwebtoken')

describe('Presroc Add Bill Run Transaction controller', () => {
const clientID = '1234546789'
const billRunId = 'b976d8e4-3644-11eb-adc1-0242ac120002'
let server
let authToken

before(async () => {
server = await deployment()
authToken = AuthorisationHelper.nonAdminToken(clientID)

Sinon
.stub(JsonWebToken, 'verify')
.returns(AuthorisationHelper.decodeToken(authToken))
})

after(async () => {
Sinon.restore()
})

describe('Add a bill run transaction: POST /v2/{regimeId}/bill-runs/{billRunId}/transactions', () => {
const options = (token, payload) => {
return {
method: 'POST',
url: `/v2/wrls/bill-runs/${billRunId}/transactions`,
headers: { authorization: `Bearer ${token}` },
payload: payload
}
}

it('responds to POST request', async () => {
const response = await server.inject(options(authToken, {}))

expect(response.statusCode).to.equal(200)
})
})
})
4 changes: 2 additions & 2 deletions test/controllers/presroc/bill_runs.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe('Presroc Bill Runs controller', () => {
Sinon.restore()
})

describe('Adding an authorised system: POST /v2/{regimeId}/billruns', () => {
describe('Adding an authorised system: POST /v2/{regimeId}/bill-runs', () => {
const options = (token, payload) => {
return {
method: 'POST',
url: '/v2/wrls/billruns',
url: '/v2/wrls/bill-runs',
headers: { authorization: `Bearer ${token}` },
payload: payload
}
Expand Down

0 comments on commit 51557df

Please sign in to comment.