import { accountTypeLabel, isOperativeAccount, maskAccountNumber, } from './accountRules'; import type { CbsAccount } from '../../../types/cbs'; /** * The four accounts `GET /accounts` returns for a real profile, copied from a * live response. Two operative accounts and two deposits, which is the shape * the picker rules exist for. */ const LIVE_ACCOUNTS: CbsAccount[] = [ { accountNumber: '70108103544967', accountType: 'FIXED_DEPOSIT', status: 'ACTIVE', ifsc: 'SIM0000001', mmid: null, }, { accountNumber: '60108103544967', accountType: 'CURRENT', status: 'ACTIVE', ifsc: 'SIM0000001', mmid: '1072199', }, { accountNumber: '50108103544967', accountType: 'SAVINGS', status: 'ACTIVE', ifsc: 'SIM0000001', mmid: '1072220', }, { accountNumber: '80108103544967', accountType: 'RECURRING_DEPOSIT', status: 'ACTIVE', ifsc: 'SIM0000001', mmid: null, }, ]; describe('isOperativeAccount', () => { it('offers only the savings and current accounts from a live profile', () => { expect(LIVE_ACCOUNTS.filter(isOperativeAccount).map((a) => a.accountType)).toEqual([ 'CURRENT', 'SAVINGS', ]); }); it.each(['FIXED_DEPOSIT', 'RECURRING_DEPOSIT'] as const)( 'never offers a %s, even when it is active', (accountType) => { expect( isOperativeAccount({ accountNumber: '70108103544967', accountType, status: 'ACTIVE', ifsc: 'SIM0000001', mmid: null, }), ).toBe(false); }, ); // A dormant savings account is still the customer's, and still worth listing // on an enquiry screen — but a transfer debited from it would be refused. it.each(['DORMANT', 'BLOCKED', 'CLOSED'] as const)( 'does not offer a savings account that is %s', (status) => { expect( isOperativeAccount({ accountNumber: '50108103544967', accountType: 'SAVINGS', status, ifsc: 'SIM0000001', mmid: '1072220', }), ).toBe(false); }, ); }); describe('accountTypeLabel', () => { it('turns the API_SHAPE into something readable', () => { expect(accountTypeLabel('FIXED_DEPOSIT')).toBe('Fixed deposit'); expect(accountTypeLabel('RECURRING_DEPOSIT')).toBe('Recurring deposit'); expect(accountTypeLabel('SAVINGS')).toBe('Savings'); }); }); describe('maskAccountNumber', () => { // The unmasked number arrives only from `GET /accounts`, and must not reach // the screen except where the customer is confirming it. it('keeps only the last four digits', () => { expect(maskAccountNumber('50108103544967')).toBe('XXXX 4967'); }); });