Add account balance enquiry via GET /accounts/balance
The CBS API now exposes a balance endpoint, which it previously did not. Several comments in the codebase asserted that no such endpoint existed anywhere in the API; those are corrected here rather than left to mislead. Balance is fetched lazily, per account, from the Account Details card: - `accounts.balance` endpoint, `CbsAccountBalance` type, and a `getAccountBalance` query with `keepUnusedDataFor: 0` — a balance is the most perishable figure in the app and must not outlive its screen. - The call is triggered by the customer, not by render. Every call reaches the core banking system, and a balance should not appear over someone's shoulder just for opening a screen. - `supportsBalanceEnquiry` gates the control by account type only, with no status check: a dormant savings account cannot be debited but still has a balance. Deposits are excluded because the endpoint does not serve them. - `ACCOUNT_BALANCE_NOT_AVAILABLE` added to the error catalogue as a non-retryable refusal, so the card states it instead of inviting a tap that gets the identical answer. Also carries in-progress work already present in the tree: customer-facing account type labels (`accountTypeLabel`) applied across the account card, selector, mini statement, balance enquiry and MMID screens. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
2dcb10775c
commit
86f9647437
@@ -9,9 +9,16 @@ import {
|
||||
} from './cbsErrors';
|
||||
|
||||
describe('error code catalogue', () => {
|
||||
it('covers all 45 documented codes, with no duplicates', () => {
|
||||
expect(CBS_ERROR_CODES).toHaveLength(45);
|
||||
expect(new Set(CBS_ERROR_CODES).size).toBe(45);
|
||||
it('covers all 46 documented codes, with no duplicates', () => {
|
||||
expect(CBS_ERROR_CODES).toHaveLength(46);
|
||||
expect(new Set(CBS_ERROR_CODES).size).toBe(46);
|
||||
});
|
||||
|
||||
it('does not invite a retry when the bank withholds a balance', () => {
|
||||
// The account exists and the bank simply will not price it. Repeating the
|
||||
// call gets the same refusal, so the card must not offer a retry.
|
||||
expect(isCbsErrorCode('ACCOUNT_BALANCE_NOT_AVAILABLE')).toBe(true);
|
||||
expect(isRetryableError('ACCOUNT_BALANCE_NOT_AVAILABLE')).toBe(false);
|
||||
});
|
||||
|
||||
it('knows the cheque book codes', () => {
|
||||
|
||||
@@ -17,6 +17,7 @@ export const CBS_ERROR_CODES = [
|
||||
'CUSTOMER_NOT_FOUND',
|
||||
'NO_ACCOUNTS_FOUND',
|
||||
'ACCOUNT_NOT_FOUND',
|
||||
'ACCOUNT_BALANCE_NOT_AVAILABLE',
|
||||
'CHEQUE_NOT_FOUND',
|
||||
'STOP_PAYMENT_NOT_AVAILABLE',
|
||||
'INVALID_DATE_RANGE',
|
||||
@@ -142,6 +143,15 @@ const ERROR_COPY: Record<AnyErrorCode, ErrorCopy> = {
|
||||
title: 'Account unavailable',
|
||||
description: 'That account is no longer part of your profile.',
|
||||
},
|
||||
/**
|
||||
* The account exists but the bank will not give a balance for it — a deposit
|
||||
* asked of the wrong endpoint, or a product the connector cannot read. Not
|
||||
* retryable: the identical call gets the identical answer.
|
||||
*/
|
||||
ACCOUNT_BALANCE_NOT_AVAILABLE: {
|
||||
title: 'Balance unavailable',
|
||||
description: 'Your bank does not provide a balance for this account.',
|
||||
},
|
||||
/**
|
||||
* Nothing on file for this account and cheque number. The bank keeps no
|
||||
* separate record of issued cheques, so this also covers the common case of
|
||||
|
||||
@@ -29,6 +29,16 @@ export const endpoints = {
|
||||
*/
|
||||
list: '/accounts',
|
||||
mmid: '/accounts/mmid',
|
||||
/**
|
||||
* One transactable account's current balance, by `accountNumber` query
|
||||
* parameter. Read live from the bank on every call — nothing is cached
|
||||
* here, and nothing about a balance may be.
|
||||
*
|
||||
* SAVINGS and CURRENT only. A deposit's balance is a term-deposit concept
|
||||
* and lives on `depositDetail` below, which is why the bank keeps the two
|
||||
* apart rather than answering both from one endpoint.
|
||||
*/
|
||||
balance: '/accounts/balance',
|
||||
/**
|
||||
* A page of ledger entries for one account. Takes the full account number
|
||||
* from `list` above, and an optional `fromDate`/`toDate` pair that the
|
||||
|
||||
Reference in New Issue
Block a user