import { ProcessWalletTransactionPresenter } from './ProcessWalletTransactionPresenter'; import { ProcessWalletTransactionResultDTO } from '../dtos/ProcessWalletTransactionDTO'; import { TransactionType } from '../dtos/TransactionType'; describe('ProcessWalletTransactionPresenter', () => { let presenter: ProcessWalletTransactionPresenter; beforeEach(() => { presenter = new ProcessWalletTransactionPresenter(); }); describe('present', () => { it('should store the result', () => { const result: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-123', leagueId: 'league-123', balance: 1000, totalRevenue: 5000, totalPlatformFees: 250, totalWithdrawn: 3000, createdAt: new Date('2024-01-01'), currency: 'USD', }, transaction: { id: 'transaction-123', walletId: 'wallet-123', type: TransactionType.DEPOSIT, amount: 100, description: 'Test deposit', createdAt: new Date('2024-01-02'), }, }; presenter.present(result); expect(presenter.getResponseModel()).toEqual(result); }); it('should overwrite previous result', () => { const firstResult: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-123', leagueId: 'league-123', balance: 1000, totalRevenue: 5000, totalPlatformFees: 250, totalWithdrawn: 3000, createdAt: new Date('2024-01-01'), currency: 'USD', }, transaction: { id: 'transaction-123', walletId: 'wallet-123', type: TransactionType.DEPOSIT, amount: 100, description: 'Test deposit', createdAt: new Date('2024-01-02'), }, }; const secondResult: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-456', leagueId: 'league-456', balance: 2000, totalRevenue: 10000, totalPlatformFees: 500, totalWithdrawn: 6000, createdAt: new Date('2024-01-02'), currency: 'EUR', }, transaction: { id: 'transaction-456', walletId: 'wallet-456', type: TransactionType.WITHDRAWAL, amount: 200, description: 'Test withdrawal', createdAt: new Date('2024-01-03'), }, }; presenter.present(firstResult); presenter.present(secondResult); expect(presenter.getResponseModel()).toEqual(secondResult); }); }); describe('getResponseModel', () => { it('should return null when not presented', () => { expect(presenter.getResponseModel()).toBeNull(); }); it('should return the result after present()', () => { const result: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-123', leagueId: 'league-123', balance: 1000, totalRevenue: 5000, totalPlatformFees: 250, totalWithdrawn: 3000, createdAt: new Date('2024-01-01'), currency: 'USD', }, transaction: { id: 'transaction-123', walletId: 'wallet-123', type: TransactionType.DEPOSIT, amount: 100, description: 'Test deposit', createdAt: new Date('2024-01-02'), }, }; presenter.present(result); expect(presenter.getResponseModel()).toEqual(result); }); }); describe('reset', () => { it('should clear the result', () => { const result: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-123', leagueId: 'league-123', balance: 1000, totalRevenue: 5000, totalPlatformFees: 250, totalWithdrawn: 3000, createdAt: new Date('2024-01-01'), currency: 'USD', }, transaction: { id: 'transaction-123', walletId: 'wallet-123', type: TransactionType.DEPOSIT, amount: 100, description: 'Test deposit', createdAt: new Date('2024-01-02'), }, }; presenter.present(result); presenter.reset(); expect(presenter.getResponseModel()).toBeNull(); }); it('should allow presenting again after reset', () => { const firstResult: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-123', leagueId: 'league-123', balance: 1000, totalRevenue: 5000, totalPlatformFees: 250, totalWithdrawn: 3000, createdAt: new Date('2024-01-01'), currency: 'USD', }, transaction: { id: 'transaction-123', walletId: 'wallet-123', type: TransactionType.DEPOSIT, amount: 100, description: 'Test deposit', createdAt: new Date('2024-01-02'), }, }; const secondResult: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-456', leagueId: 'league-456', balance: 2000, totalRevenue: 10000, totalPlatformFees: 500, totalWithdrawn: 6000, createdAt: new Date('2024-01-02'), currency: 'EUR', }, transaction: { id: 'transaction-456', walletId: 'wallet-456', type: TransactionType.WITHDRAWAL, amount: 200, description: 'Test withdrawal', createdAt: new Date('2024-01-03'), }, }; presenter.present(firstResult); presenter.reset(); presenter.present(secondResult); expect(presenter.getResponseModel()).toEqual(secondResult); }); }); describe('viewModel', () => { it('should return the result', () => { const result: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-123', leagueId: 'league-123', balance: 1000, totalRevenue: 5000, totalPlatformFees: 250, totalWithdrawn: 3000, createdAt: new Date('2024-01-01'), currency: 'USD', }, transaction: { id: 'transaction-123', walletId: 'wallet-123', type: TransactionType.DEPOSIT, amount: 100, description: 'Test deposit', createdAt: new Date('2024-01-02'), }, }; presenter.present(result); expect(presenter.viewModel).toEqual(result); }); it('should throw error when accessed before present()', () => { expect(() => presenter.viewModel).toThrow('Presenter not presented'); }); it('should throw error after reset', () => { const result: ProcessWalletTransactionResultDTO = { wallet: { id: 'wallet-123', leagueId: 'league-123', balance: 1000, totalRevenue: 5000, totalPlatformFees: 250, totalWithdrawn: 3000, createdAt: new Date('2024-01-01'), currency: 'USD', }, transaction: { id: 'transaction-123', walletId: 'wallet-123', type: TransactionType.DEPOSIT, amount: 100, description: 'Test deposit', createdAt: new Date('2024-01-02'), }, }; presenter.present(result); presenter.reset(); expect(() => presenter.viewModel).toThrow('Presenter not presented'); }); }); });