import { describe, it, expect } from 'vitest'; import { LeagueWalletViewDataBuilder } from './LeagueWalletViewDataBuilder'; import type { LeagueWalletApiDto } from '@/lib/types/tbd/LeagueWalletApiDto'; describe('LeagueWalletViewDataBuilder', () => { describe('happy paths', () => { it('should transform LeagueWalletApiDto to LeagueWalletViewData correctly', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-123', balance: 5000, currency: 'USD', transactions: [ { id: 'txn-1', amount: 1000, status: 'completed', createdAt: '2024-01-01T10:00:00Z', description: 'Sponsorship payment', }, ], }; const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(result).toEqual({ leagueId: 'league-123', balance: 5000, formattedBalance: expect.any(String), totalRevenue: 5000, formattedTotalRevenue: expect.any(String), totalFees: 0, formattedTotalFees: expect.any(String), pendingPayouts: 0, formattedPendingPayouts: expect.any(String), currency: 'USD', transactions: [ { id: 'txn-1', amount: 1000, status: 'completed', createdAt: '2024-01-01T10:00:00Z', description: 'Sponsorship payment', formattedAmount: expect.any(String), amountColor: 'green', formattedDate: expect.any(String), statusColor: 'green', typeColor: 'blue', }, ], }); }); it('should handle empty transactions', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-456', balance: 0, currency: 'USD', transactions: [], }; const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(result.transactions).toHaveLength(0); expect(result.balance).toBe(0); }); it('should handle multiple transactions', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-789', balance: 10000, currency: 'USD', transactions: [ { id: 'txn-1', amount: 5000, status: 'completed', createdAt: '2024-01-01T10:00:00Z', description: 'Sponsorship payment', }, { id: 'txn-2', amount: -1000, status: 'completed', createdAt: '2024-01-02T10:00:00Z', description: 'Payout', }, ], }; const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(result.transactions).toHaveLength(2); }); }); describe('data transformation', () => { it('should preserve all DTO fields in the output', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-101', balance: 7500, currency: 'EUR', transactions: [ { id: 'txn-1', amount: 2500, status: 'completed', createdAt: '2024-01-01T10:00:00Z', description: 'Test transaction', }, ], }; const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(result.leagueId).toBe(leagueWalletApiDto.leagueId); expect(result.balance).toBe(leagueWalletApiDto.balance); expect(result.currency).toBe(leagueWalletApiDto.currency); }); it('should not modify the input DTO', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-102', balance: 5000, currency: 'USD', transactions: [], }; const originalDto = { ...leagueWalletApiDto }; LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(leagueWalletApiDto).toEqual(originalDto); }); }); describe('edge cases', () => { it('should handle negative balance', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-103', balance: -500, currency: 'USD', transactions: [ { id: 'txn-1', amount: -500, status: 'completed', createdAt: '2024-01-01T10:00:00Z', description: 'Overdraft', }, ], }; const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(result.balance).toBe(-500); expect(result.transactions[0].amountColor).toBe('red'); }); it('should handle pending transactions', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-104', balance: 1000, currency: 'USD', transactions: [ { id: 'txn-1', amount: 500, status: 'pending', createdAt: '2024-01-01T10:00:00Z', description: 'Pending payment', }, ], }; const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(result.transactions[0].statusColor).toBe('yellow'); }); it('should handle failed transactions', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-105', balance: 1000, currency: 'USD', transactions: [ { id: 'txn-1', amount: 500, status: 'failed', createdAt: '2024-01-01T10:00:00Z', description: 'Failed payment', }, ], }; const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(result.transactions[0].statusColor).toBe('red'); }); it('should handle different currencies', () => { const leagueWalletApiDto: LeagueWalletApiDto = { leagueId: 'league-106', balance: 1000, currency: 'EUR', transactions: [], }; const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto); expect(result.currency).toBe('EUR'); }); }); });