Skip to content

Commit

Permalink
Change BankAccount#statusLine to report ambiguous bank accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubb committed Jul 28, 2020
1 parent 2889485 commit 08bdded
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spec/bank_account_report_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('BankAccountReport', () => {
it('returns the report', () => {
expect(report.generate()).toEqual([
'000000051\n',
'664371495 ERR\n',
'664371485\n',
'49006771? ILL\n',
'1234?678? ILL\n'
])
Expand Down
16 changes: 16 additions & 0 deletions spec/bank_account_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ describe('BankAccount', () => {
expect(bankAccount.statusLine()).toBe('345882864 ERR\n')
})
})

describe('when the bank account is ambiguous', () => {
const text = [
' _ _ _ _ _ _ _ _ _ ',
'|_||_||_||_||_||_||_||_||_|',
'|_||_||_||_||_||_||_||_||_|'
]

const bankAccount = BankAccount.parse(text.join('\n'))

it('returns the ambiguous status', () => {
expect(bankAccount.statusLine()).toBe(
"888888888 AMB ['888886888', '888888880', '888888988']\n"
)
})
})
})

describe('#alternatives', () => {
Expand Down
13 changes: 10 additions & 3 deletions src/bank_account.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,17 @@ class BankAccount {
* @returns {string}
*/
statusLine () {
// Display illegible or error status. If the Bank Account
const alternatives = this.alternatives()
if (alternatives.length === 1) return alternatives[0].statusLine()

const ambiguous = alternatives.map(ba => `'${ba.format()}'`).join(', ')

// If there are ambiguous Bank Account numbers return them,
// otherwise display illegible or error status. If the Bank Account
// is valid, then return no status.
const status = !this.isLegible() ? ' ILL' :
!this.isValid() ? ' ERR' :
const status = ambiguous ? ` AMB [${ambiguous}]` :
!this.isLegible() ? ' ILL' :
!this.isValid() ? ' ERR' :
''

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

0 comments on commit 08bdded

Please sign in to comment.