Skip to content

Commit ab568c6

Browse files
committed
Change BankAccount#statusLine to report ambiguous bank accounts
1 parent 1274424 commit ab568c6

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

spec/bank_account_report_spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('BankAccountReport', () => {
5353
it('returns the report', () => {
5454
expect(report.generate()).toEqual([
5555
'000000051\n',
56-
'664371495 ERR\n',
56+
'664371485\n',
5757
'49006771? ILL\n',
5858
'1234?678? ILL\n'
5959
])

spec/bank_account_spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,22 @@ describe('BankAccount', () => {
331331
expect(bankAccount.statusLine()).toBe('345882864 ERR\n')
332332
})
333333
})
334+
335+
describe('when the bank account is ambiguous', () => {
336+
const text = [
337+
' _ _ _ _ _ _ _ _ _ ',
338+
'|_||_||_||_||_||_||_||_||_|',
339+
'|_||_||_||_||_||_||_||_||_|'
340+
]
341+
342+
const bankAccount = BankAccount.parse(text.join('\n'))
343+
344+
it('returns the ambiguous status', () => {
345+
expect(bankAccount.statusLine()).toBe(
346+
"888888888 AMB ['888886888', '888888880', '888888988']\n"
347+
)
348+
})
349+
})
334350
})
335351

336352
describe('#alternatives', () => {

src/bank_account.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,17 @@ class BankAccount {
123123
* @returns {string}
124124
*/
125125
statusLine () {
126-
// Display illegible or error status. If the Bank Account
126+
const alternatives = this.alternatives()
127+
if (alternatives.length === 1) return alternatives[0].statusLine()
128+
129+
const ambiguous = alternatives.map(ba => `'${ba.format()}'`).join(', ')
130+
131+
// If there are ambiguous Bank Account numbers return them,
132+
// otherwise display illegible or error status. If the Bank Account
127133
// is valid, then return no status.
128-
const status = !this.isLegible() ? ' ILL' :
129-
!this.isValid() ? ' ERR' :
134+
const status = ambiguous ? ` AMB [${ambiguous}]` :
135+
!this.isLegible() ? ' ILL' :
136+
!this.isValid() ? ' ERR' :
130137
''
131138

132139
return `${this.format()}${status}\n`

0 commit comments

Comments
 (0)