view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-24 12:14:08 +01:00
parent dde77e717a
commit 046852703f
94 changed files with 1333 additions and 4885 deletions

View File

@@ -1,93 +1,118 @@
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 = {
it('should transform LeagueWalletInputDTO to LeagueWalletViewData correctly', () => {
const leagueWalletApiDto = {
leagueId: 'league-123',
balance: 5000,
currency: 'USD',
totalRevenue: 5000,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
canWithdraw: true,
transactions: [
{
id: 'txn-1',
type: 'sponsorship',
amount: 1000,
fee: 0,
netAmount: 1000,
status: 'completed',
createdAt: '2024-01-01T10:00:00Z',
date: '2024-01-01T10:00:00Z',
description: 'Sponsorship payment',
},
],
};
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
expect(result).toEqual({
leagueId: 'league-123',
balance: 5000,
formattedBalance: expect.any(String),
formattedBalance: 'USD 5,000',
totalRevenue: 5000,
formattedTotalRevenue: expect.any(String),
formattedTotalRevenue: 'USD 5,000',
totalFees: 0,
formattedTotalFees: expect.any(String),
formattedTotalFees: 'USD 0',
totalWithdrawals: 0,
pendingPayouts: 0,
formattedPendingPayouts: expect.any(String),
formattedPendingPayouts: 'USD 0',
currency: 'USD',
canWithdraw: true,
withdrawalBlockReason: undefined,
transactions: [
{
id: 'txn-1',
type: 'sponsorship',
amount: 1000,
fee: 0,
netAmount: 1000,
status: 'completed',
createdAt: '2024-01-01T10:00:00Z',
date: '2024-01-01T10:00:00Z',
description: 'Sponsorship payment',
formattedAmount: expect.any(String),
amountColor: 'green',
formattedDate: expect.any(String),
statusColor: 'green',
typeColor: 'blue',
reference: undefined,
},
],
});
});
it('should handle empty transactions', () => {
const leagueWalletApiDto: LeagueWalletApiDto = {
const leagueWalletApiDto = {
leagueId: 'league-456',
balance: 0,
currency: 'USD',
totalRevenue: 0,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
canWithdraw: true,
transactions: [],
};
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
expect(result.transactions).toHaveLength(0);
expect(result.balance).toBe(0);
});
it('should handle multiple transactions', () => {
const leagueWalletApiDto: LeagueWalletApiDto = {
const leagueWalletApiDto = {
leagueId: 'league-789',
balance: 10000,
currency: 'USD',
totalRevenue: 10000,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
canWithdraw: true,
transactions: [
{
id: 'txn-1',
type: 'sponsorship',
amount: 5000,
fee: 0,
netAmount: 5000,
status: 'completed',
createdAt: '2024-01-01T10:00:00Z',
date: '2024-01-01T10:00:00Z',
description: 'Sponsorship payment',
},
{
id: 'txn-2',
type: 'withdrawal',
amount: -1000,
fee: 0,
netAmount: -1000,
status: 'completed',
createdAt: '2024-01-02T10:00:00Z',
date: '2024-01-02T10:00:00Z',
description: 'Payout',
},
],
};
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
expect(result.transactions).toHaveLength(2);
});
@@ -95,38 +120,50 @@ describe('LeagueWalletViewDataBuilder', () => {
describe('data transformation', () => {
it('should preserve all DTO fields in the output', () => {
const leagueWalletApiDto: LeagueWalletApiDto = {
const leagueWalletApiDto = {
leagueId: 'league-101',
balance: 7500,
currency: 'EUR',
totalRevenue: 7500,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
canWithdraw: true,
transactions: [
{
id: 'txn-1',
type: 'deposit',
amount: 2500,
fee: 0,
netAmount: 2500,
status: 'completed',
createdAt: '2024-01-01T10:00:00Z',
date: '2024-01-01T10:00:00Z',
description: 'Test transaction',
},
],
};
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
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 = {
const leagueWalletApiDto = {
leagueId: 'league-102',
balance: 5000,
currency: 'USD',
totalRevenue: 5000,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
canWithdraw: true,
transactions: [],
};
const originalDto = { ...leagueWalletApiDto };
LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const originalDto = JSON.parse(JSON.stringify(leagueWalletApiDto));
LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
expect(leagueWalletApiDto).toEqual(originalDto);
});
@@ -134,78 +171,106 @@ describe('LeagueWalletViewDataBuilder', () => {
describe('edge cases', () => {
it('should handle negative balance', () => {
const leagueWalletApiDto: LeagueWalletApiDto = {
const leagueWalletApiDto = {
leagueId: 'league-103',
balance: -500,
currency: 'USD',
totalRevenue: 0,
totalFees: 0,
totalWithdrawals: 500,
pendingPayouts: 0,
canWithdraw: false,
transactions: [
{
id: 'txn-1',
type: 'withdrawal',
amount: -500,
fee: 0,
netAmount: -500,
status: 'completed',
createdAt: '2024-01-01T10:00:00Z',
date: '2024-01-01T10:00:00Z',
description: 'Overdraft',
},
],
};
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
expect(result.balance).toBe(-500);
expect(result.transactions[0].amountColor).toBe('red');
});
it('should handle pending transactions', () => {
const leagueWalletApiDto: LeagueWalletApiDto = {
const leagueWalletApiDto = {
leagueId: 'league-104',
balance: 1000,
currency: 'USD',
totalRevenue: 1000,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
canWithdraw: true,
transactions: [
{
id: 'txn-1',
type: 'sponsorship',
amount: 500,
fee: 0,
netAmount: 500,
status: 'pending',
createdAt: '2024-01-01T10:00:00Z',
date: '2024-01-01T10:00:00Z',
description: 'Pending payment',
},
],
};
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
expect(result.transactions[0].statusColor).toBe('yellow');
expect(result.transactions[0].status).toBe('pending');
});
it('should handle failed transactions', () => {
const leagueWalletApiDto: LeagueWalletApiDto = {
const leagueWalletApiDto = {
leagueId: 'league-105',
balance: 1000,
currency: 'USD',
totalRevenue: 1000,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
canWithdraw: true,
transactions: [
{
id: 'txn-1',
type: 'sponsorship',
amount: 500,
fee: 0,
netAmount: 500,
status: 'failed',
createdAt: '2024-01-01T10:00:00Z',
date: '2024-01-01T10:00:00Z',
description: 'Failed payment',
},
],
};
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
expect(result.transactions[0].statusColor).toBe('red');
expect(result.transactions[0].status).toBe('failed');
});
it('should handle different currencies', () => {
const leagueWalletApiDto: LeagueWalletApiDto = {
const leagueWalletApiDto = {
leagueId: 'league-106',
balance: 1000,
currency: 'EUR',
totalRevenue: 1000,
totalFees: 0,
totalWithdrawals: 0,
pendingPayouts: 0,
canWithdraw: true,
transactions: [],
};
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto);
const result = LeagueWalletViewDataBuilder.build(leagueWalletApiDto as any);
expect(result.currency).toBe('EUR');
});