Files
gridpilot.gg/apps/website/lib/view-models/LeagueWalletViewModel.test.ts
2026-01-12 01:01:49 +01:00

88 lines
2.9 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { LeagueWalletViewModel } from './LeagueWalletViewModel';
import { WalletTransactionViewModel, FullTransactionDto } from './WalletTransactionViewModel';
const createTransaction = (overrides: Partial<FullTransactionDto> = {}): WalletTransactionViewModel =>
new WalletTransactionViewModel({
id: 'tx-1',
type: 'sponsorship',
description: 'Test transaction',
amount: 100,
fee: 10,
netAmount: 90,
date: new Date('2024-01-01T00:00:00Z'),
status: 'completed',
reference: 'ref-1',
...overrides,
});
describe('LeagueWalletViewModel', () => {
it('maps core wallet fields from DTO', () => {
const transactions = [createTransaction()];
const vm = new LeagueWalletViewModel({
balance: 250.5,
currency: 'USD',
totalRevenue: 1000,
totalFees: 50,
totalWithdrawals: 200,
pendingPayouts: 75,
transactions,
canWithdraw: true,
withdrawalBlockReason: undefined,
});
expect(vm.balance).toBe(250.5);
expect(vm.currency).toBe('USD');
expect(vm.totalRevenue).toBe(1000);
expect(vm.totalFees).toBe(50);
expect(vm.totalWithdrawals).toBe(200);
expect(vm.pendingPayouts).toBe(75);
expect(vm.transactions).toBe(transactions);
expect(vm.canWithdraw).toBe(true);
expect(vm.withdrawalBlockReason).toBeUndefined();
});
it('formats monetary fields as currency strings', () => {
const vm = new LeagueWalletViewModel({
balance: 250.5,
currency: 'USD',
totalRevenue: 1234.56,
totalFees: 78.9,
totalWithdrawals: 0,
pendingPayouts: 42,
transactions: [],
canWithdraw: false,
});
expect(vm.formattedBalance).toBe('$250.50');
expect(vm.formattedTotalRevenue).toBe('$1234.56');
expect(vm.formattedTotalFees).toBe('$78.90');
expect(vm.formattedPendingPayouts).toBe('$42.00');
});
it('filters transactions by type and supports all', () => {
const sponsorshipTx = createTransaction({ type: 'sponsorship' });
const membershipTx = createTransaction({ type: 'membership', id: 'tx-2' });
const withdrawalTx = createTransaction({ type: 'withdrawal', id: 'tx-3' });
const prizeTx = createTransaction({ type: 'prize', id: 'tx-4' });
const vm = new LeagueWalletViewModel({
balance: 0,
currency: 'USD',
totalRevenue: 0,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
transactions: [sponsorshipTx, membershipTx, withdrawalTx, prizeTx],
canWithdraw: false,
});
expect(vm.getFilteredTransactions('all')).toHaveLength(4);
expect(vm.getFilteredTransactions('sponsorship')).toEqual([sponsorshipTx]);
expect(vm.getFilteredTransactions('membership')).toEqual([membershipTx]);
expect(vm.getFilteredTransactions('withdrawal')).toEqual([withdrawalTx]);
expect(vm.getFilteredTransactions('prize')).toEqual([prizeTx]);
});
});