Skip to content

Commit 51557df

Browse files
authored
Create add transaction endpoint (#80)
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.
1 parent e95a1a2 commit 51557df

File tree

5 files changed

+84
-4
lines changed

5 files changed

+84
-4
lines changed

app/controllers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const BaseCalculateChargeController = require('./base_calculate_charge.controlle
1111

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

14+
const PresrocAddBillRunTransactionController = require('./presroc/add_bill_run_transaction.controller')
1415
const PresrocBillRunsController = require('./presroc/bill_runs.controller')
1516
const PresrocTransactionsController = require('./presroc/transactions.controller')
1617
const PresrocCalculateChargeController = require('./presroc/calculate_charge.controller')
@@ -24,6 +25,7 @@ module.exports = {
2425
AuthorisedSystemsController,
2526
BaseCalculateChargeController,
2627
DatabaseController,
28+
PresrocAddBillRunTransactionController,
2729
PresrocBillRunsController,
2830
PresrocTransactionsController,
2931
PresrocCalculateChargeController,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
class PresrocAddBillRunTransactionController {
4+
static async create (_req, _h) {
5+
return 'hello, pre-sroc add bill run transaction'
6+
}
7+
}
8+
9+
module.exports = PresrocAddBillRunTransactionController

app/routes/bill_run.routes.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
'use strict'
22

3-
const { NotSupportedController, PresrocBillRunsController } = require('../controllers')
3+
const {
4+
NotSupportedController,
5+
PresrocAddBillRunTransactionController,
6+
PresrocBillRunsController
7+
} = require('../controllers')
48

59
const routes = [
610
{
@@ -10,8 +14,18 @@ const routes = [
1014
},
1115
{
1216
method: 'POST',
13-
path: '/v2/{regimeId}/billruns',
17+
path: '/v2/{regimeId}/bill-runs',
1418
handler: PresrocBillRunsController.create
19+
},
20+
{
21+
method: 'POST',
22+
path: '/v1/{regimeId}/billruns/{billRunId}/transactions',
23+
handler: NotSupportedController.index
24+
},
25+
{
26+
method: 'POST',
27+
path: '/v2/{regimeId}/bill-runs/{billRunId}/transactions',
28+
handler: PresrocAddBillRunTransactionController.create
1529
}
1630
]
1731

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict'
2+
3+
// Test framework dependencies
4+
const Lab = require('@hapi/lab')
5+
const Code = require('@hapi/code')
6+
const Sinon = require('sinon')
7+
8+
const { describe, it, before, after } = exports.lab = Lab.script()
9+
const { expect } = Code
10+
11+
// For running our service
12+
const { deployment } = require('../../../server')
13+
14+
// Test helpers
15+
const { AuthorisationHelper } = require('../../support/helpers')
16+
17+
// Things we need to stub
18+
const JsonWebToken = require('jsonwebtoken')
19+
20+
describe('Presroc Add Bill Run Transaction controller', () => {
21+
const clientID = '1234546789'
22+
const billRunId = 'b976d8e4-3644-11eb-adc1-0242ac120002'
23+
let server
24+
let authToken
25+
26+
before(async () => {
27+
server = await deployment()
28+
authToken = AuthorisationHelper.nonAdminToken(clientID)
29+
30+
Sinon
31+
.stub(JsonWebToken, 'verify')
32+
.returns(AuthorisationHelper.decodeToken(authToken))
33+
})
34+
35+
after(async () => {
36+
Sinon.restore()
37+
})
38+
39+
describe('Add a bill run transaction: POST /v2/{regimeId}/bill-runs/{billRunId}/transactions', () => {
40+
const options = (token, payload) => {
41+
return {
42+
method: 'POST',
43+
url: `/v2/wrls/bill-runs/${billRunId}/transactions`,
44+
headers: { authorization: `Bearer ${token}` },
45+
payload: payload
46+
}
47+
}
48+
49+
it('responds to POST request', async () => {
50+
const response = await server.inject(options(authToken, {}))
51+
52+
expect(response.statusCode).to.equal(200)
53+
})
54+
})
55+
})

test/controllers/presroc/bill_runs.controller.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ describe('Presroc Bill Runs controller', () => {
4242
Sinon.restore()
4343
})
4444

45-
describe('Adding an authorised system: POST /v2/{regimeId}/billruns', () => {
45+
describe('Adding an authorised system: POST /v2/{regimeId}/bill-runs', () => {
4646
const options = (token, payload) => {
4747
return {
4848
method: 'POST',
49-
url: '/v2/wrls/billruns',
49+
url: '/v2/wrls/bill-runs',
5050
headers: { authorization: `Bearer ${token}` },
5151
payload: payload
5252
}

0 commit comments

Comments
 (0)