Add bank selector dropdown and SWIFT/BIC registry
- Added Bank type and BankRegistry interface - Created banks service with CRUD operations - Added bank dropdown to Transactions page - Integrated ESTRBRRJ (strategy INVESTIMENTOS S/A CVC) as default - Added SWIFT code validation - Added unit tests for bank registry - Extended Transaction type with bankSwiftCode field
This commit is contained in:
@@ -32,8 +32,11 @@ export default function TransactionsPage() {
|
||||
},
|
||||
});
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const [selectedBankSwiftCode, setSelectedBankSwiftCode] = useState<string>('ESTRBRRJ');
|
||||
|
||||
const converter = getDefaultConverter();
|
||||
const banks = getAllBanks();
|
||||
const selectedBank = getBankBySwiftCode(selectedBankSwiftCode);
|
||||
|
||||
const handleSubmit = useCallback(async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -137,6 +140,7 @@ export default function TransactionsPage() {
|
||||
},
|
||||
purposeOfPayment: sanitizeString(formData.purposeOfPayment || ''),
|
||||
fxContractId: formData.fxContractId,
|
||||
bankSwiftCode: selectedBankSwiftCode,
|
||||
status: 'pending',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
|
||||
63
packages/utils/src/__tests__/banks.test.ts
Normal file
63
packages/utils/src/__tests__/banks.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import {
|
||||
getAllBanks,
|
||||
getBankBySwiftCode,
|
||||
searchBanks,
|
||||
addBank,
|
||||
validateSwiftCode,
|
||||
deactivateBank,
|
||||
} from '../banks';
|
||||
|
||||
describe('Bank Registry', () => {
|
||||
beforeEach(() => {
|
||||
// Reset to default state before each test
|
||||
// In a real implementation, we'd have a reset function
|
||||
});
|
||||
|
||||
it('should get all active banks', () => {
|
||||
const banks = getAllBanks();
|
||||
expect(banks.length).toBeGreaterThan(0);
|
||||
expect(banks.every((bank) => bank.active)).toBe(true);
|
||||
});
|
||||
|
||||
it('should get bank by SWIFT code', () => {
|
||||
const bank = getBankBySwiftCode('ESTRBRRJ');
|
||||
expect(bank).not.toBeNull();
|
||||
expect(bank?.swiftCode).toBe('ESTRBRRJ');
|
||||
expect(bank?.institutionName).toContain('strategy INVESTIMENTOS');
|
||||
});
|
||||
|
||||
it('should return null for non-existent SWIFT code', () => {
|
||||
const bank = getBankBySwiftCode('INVALID');
|
||||
expect(bank).toBeNull();
|
||||
});
|
||||
|
||||
it('should search banks by name', () => {
|
||||
const results = searchBanks('strategy');
|
||||
expect(results.length).toBeGreaterThan(0);
|
||||
expect(results[0].institutionName.toLowerCase()).toContain('strategy');
|
||||
});
|
||||
|
||||
it('should search banks by city', () => {
|
||||
const results = searchBanks('Rio');
|
||||
expect(results.length).toBeGreaterThan(0);
|
||||
expect(results[0].city.toLowerCase()).toContain('rio');
|
||||
});
|
||||
|
||||
it('should validate SWIFT code format', () => {
|
||||
const valid = validateSwiftCode('ESTRBRRJ');
|
||||
expect(valid.valid).toBe(true);
|
||||
expect(valid.errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should reject invalid SWIFT code format', () => {
|
||||
const invalid = validateSwiftCode('INVALID');
|
||||
expect(invalid.valid).toBe(false);
|
||||
expect(invalid.errors.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should accept 11-character SWIFT codes with branch', () => {
|
||||
const valid = validateSwiftCode('ESTRBRRJXXX');
|
||||
expect(valid.valid).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user