-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add presenter for formatting response
We need something that handles formatting the response for the POST `/bill-runs` endpoint. We use what we did in DEFRA/water-abstraction-ui#2247 as a spec.
- Loading branch information
1 parent
4572721
commit e005c3a
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
app/presenters/supplementary-billing/create-billing-batch.presenter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats the response for the POST `/bill-runs` endpoint | ||
* @module CreateBillingBatchPresenter | ||
*/ | ||
|
||
function go (billingBatch) { | ||
const { | ||
billingBatchId: id, | ||
regionId: region, | ||
scheme, | ||
batchType, | ||
status | ||
} = billingBatch | ||
|
||
return { | ||
id, | ||
region, | ||
scheme, | ||
batchType, | ||
status | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
55 changes: 55 additions & 0 deletions
55
test/presenters/supplementary-billing/create-billing-batch.presenter.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { describe, it, beforeEach } = exports.lab = Lab.script() | ||
const { expect } = Code | ||
|
||
// Thing under test | ||
const CreateBillingBatchPresenter = require('../../../app/presenters/supplementary-billing/create-billing-batch.presenter.js') | ||
|
||
describe('Create Billing Batch presenter', () => { | ||
let data | ||
|
||
describe('when provided with a populated billing batch', () => { | ||
beforeEach(() => { | ||
data = { | ||
billingBatchId: 'f1288f6c-8503-4dc1-b114-75c408a14bd0', | ||
regionId: '6a472535-145c-4170-ab59-f555783fa6e7', | ||
scheme: 'sroc', | ||
status: 'processing' | ||
} | ||
}) | ||
|
||
it('correctly presents the data', () => { | ||
const result = CreateBillingBatchPresenter.go(data) | ||
|
||
expect(result.id).to.equal(data.billingBatchId) | ||
expect(result.region).to.equal(data.regionId) | ||
expect(result.scheme).to.equal(data.scheme) | ||
expect(result.status).to.equal(data.status) | ||
}) | ||
}) | ||
|
||
describe('when provided with unpopulated billing batch', () => { | ||
beforeEach(() => { | ||
data = { | ||
billingBatchId: null, | ||
regionId: null, | ||
scheme: null, | ||
status: null | ||
} | ||
}) | ||
|
||
it('correctly presents the data', () => { | ||
const result = CreateBillingBatchPresenter.go(data) | ||
|
||
expect(result.id).to.be.null() | ||
expect(result.region).to.be.null() | ||
expect(result.scheme).to.be.null() | ||
expect(result.status).to.be.null() | ||
}) | ||
}) | ||
}) |