-
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 new Minimum Charge Transaction presenter (#505)
https://eaflood.atlassian.net/browse/WATER-4156 Related to WATER-4155 and the work to replace the legacy bill page with our own we're now starting to build the page it will link to; a view of the bill licence and all its transactions. This adds a presenter that given a `TransactionModel` instance whose charge type is `minimum_charge` will return an object containing formatted details about the transaction. The presenter doesn't need to make any distinction between PRESROC and SROC transactions as they are both displayed in the same way.
- Loading branch information
1 parent
b03a4aa
commit 34554b8
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
app/presenters/bill-licences/minimum-charge-transaction.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,37 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats data for minimum charge transaction for the bill-licence page | ||
* @module MinimumChargeTransactionPresenter | ||
*/ | ||
|
||
const { formatMoney } = require('../base.presenter.js') | ||
|
||
/** | ||
* Formats data for minimum charge transaction for the bill-licence page | ||
* | ||
* @param {module:TransactionModel} transaction an instance of `TransactionModel` that represents a minimum charge | ||
* transaction | ||
* | ||
* @returns {Object} a formatted representation of the transaction specifically for the bill-licence page | ||
*/ | ||
function go (transaction) { | ||
const { | ||
chargeType, | ||
isCredit, | ||
netAmount | ||
} = transaction | ||
|
||
return { | ||
billableDays: '', | ||
chargeType, | ||
creditAmount: isCredit ? formatMoney(netAmount) : '', | ||
debitAmount: isCredit ? '' : formatMoney(netAmount), | ||
description: 'Minimum charge', | ||
quantity: '' | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
63 changes: 63 additions & 0 deletions
63
test/presenters/bill-licences/minimum-charge-transaction.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,63 @@ | ||
'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 MinimumChargeTransactionPresenter = require('../../../app/presenters/bill-licences/minimum-charge-transaction.presenter.js') | ||
|
||
describe('Minimum Charge Transaction presenter', () => { | ||
let transaction | ||
|
||
describe('when provided with a minimum charge transaction', () => { | ||
beforeEach(() => { | ||
transaction = { | ||
chargeType: 'minimum_charge', | ||
netAmount: 2401 | ||
} | ||
}) | ||
|
||
describe('that is a credit', () => { | ||
beforeEach(() => { | ||
transaction.isCredit = true | ||
}) | ||
|
||
it('returns the credit property populated and the debit empty', () => { | ||
const result = MinimumChargeTransactionPresenter.go(transaction) | ||
|
||
expect(result.creditAmount).to.equal('£24.01') | ||
expect(result.debitAmount).to.equal('') | ||
}) | ||
}) | ||
|
||
describe('that is a debit', () => { | ||
beforeEach(() => { | ||
transaction.isCredit = false | ||
}) | ||
|
||
it('returns the debit property populated and the credit empty', () => { | ||
const result = MinimumChargeTransactionPresenter.go(transaction) | ||
|
||
expect(result.creditAmount).to.equal('') | ||
expect(result.debitAmount).to.equal('£24.01') | ||
}) | ||
}) | ||
|
||
it('correctly presents the data', () => { | ||
const result = MinimumChargeTransactionPresenter.go(transaction) | ||
|
||
expect(result).to.equal({ | ||
billableDays: '', | ||
chargeType: 'minimum_charge', | ||
creditAmount: '', | ||
debitAmount: '£24.01', | ||
description: 'Minimum charge', | ||
quantity: '' | ||
}) | ||
}) | ||
}) | ||
}) |