core tests
This commit is contained in:
@@ -1,8 +1,174 @@
|
||||
import * as mod from '@core/payments/domain/entities/MemberPayment';
|
||||
import {
|
||||
MemberPayment,
|
||||
MemberPaymentStatus,
|
||||
} from '@core/payments/domain/entities/MemberPayment';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('payments/domain/entities/MemberPayment.ts', () => {
|
||||
it('imports', () => {
|
||||
expect(mod).toBeTruthy();
|
||||
describe('payments/domain/entities/MemberPayment', () => {
|
||||
describe('MemberPaymentStatus enum', () => {
|
||||
it('should have correct status values', () => {
|
||||
expect(MemberPaymentStatus.PENDING).toBe('pending');
|
||||
expect(MemberPaymentStatus.PAID).toBe('paid');
|
||||
expect(MemberPaymentStatus.OVERDUE).toBe('overdue');
|
||||
});
|
||||
});
|
||||
|
||||
describe('MemberPayment interface', () => {
|
||||
it('should have all required properties', () => {
|
||||
const payment: MemberPayment = {
|
||||
id: 'payment-123',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 100,
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
status: MemberPaymentStatus.PENDING,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(payment.id).toBe('payment-123');
|
||||
expect(payment.feeId).toBe('fee-456');
|
||||
expect(payment.driverId).toBe('driver-789');
|
||||
expect(payment.amount).toBe(100);
|
||||
expect(payment.platformFee).toBe(10);
|
||||
expect(payment.netAmount).toBe(90);
|
||||
expect(payment.status).toBe(MemberPaymentStatus.PENDING);
|
||||
expect(payment.dueDate).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should support optional paidAt property', () => {
|
||||
const payment: MemberPayment = {
|
||||
id: 'payment-123',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 100,
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
status: MemberPaymentStatus.PAID,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
paidAt: new Date('2024-01-15'),
|
||||
};
|
||||
|
||||
expect(payment.paidAt).toEqual(new Date('2024-01-15'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('MemberPayment.rehydrate', () => {
|
||||
it('should rehydrate a MemberPayment from props', () => {
|
||||
const props: MemberPayment = {
|
||||
id: 'payment-123',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 100,
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
status: MemberPaymentStatus.PENDING,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = MemberPayment.rehydrate(props);
|
||||
|
||||
expect(rehydrated).toEqual(props);
|
||||
expect(rehydrated.id).toBe('payment-123');
|
||||
expect(rehydrated.feeId).toBe('fee-456');
|
||||
expect(rehydrated.driverId).toBe('driver-789');
|
||||
expect(rehydrated.amount).toBe(100);
|
||||
expect(rehydrated.platformFee).toBe(10);
|
||||
expect(rehydrated.netAmount).toBe(90);
|
||||
expect(rehydrated.status).toBe(MemberPaymentStatus.PENDING);
|
||||
expect(rehydrated.dueDate).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should preserve optional paidAt when rehydrating', () => {
|
||||
const props: MemberPayment = {
|
||||
id: 'payment-123',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 100,
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
status: MemberPaymentStatus.PAID,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
paidAt: new Date('2024-01-15'),
|
||||
};
|
||||
|
||||
const rehydrated = MemberPayment.rehydrate(props);
|
||||
|
||||
expect(rehydrated.paidAt).toEqual(new Date('2024-01-15'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Business rules and invariants', () => {
|
||||
it('should calculate netAmount correctly (amount - platformFee)', () => {
|
||||
const payment: MemberPayment = {
|
||||
id: 'payment-123',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 100,
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
status: MemberPaymentStatus.PENDING,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(payment.netAmount).toBe(payment.amount - payment.platformFee);
|
||||
});
|
||||
|
||||
it('should support different payment statuses', () => {
|
||||
const pendingPayment: MemberPayment = {
|
||||
id: 'payment-123',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 100,
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
status: MemberPaymentStatus.PENDING,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const paidPayment: MemberPayment = {
|
||||
id: 'payment-124',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 100,
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
status: MemberPaymentStatus.PAID,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
paidAt: new Date('2024-01-15'),
|
||||
};
|
||||
|
||||
const overduePayment: MemberPayment = {
|
||||
id: 'payment-125',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 100,
|
||||
platformFee: 10,
|
||||
netAmount: 90,
|
||||
status: MemberPaymentStatus.OVERDUE,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(pendingPayment.status).toBe(MemberPaymentStatus.PENDING);
|
||||
expect(paidPayment.status).toBe(MemberPaymentStatus.PAID);
|
||||
expect(overduePayment.status).toBe(MemberPaymentStatus.OVERDUE);
|
||||
});
|
||||
|
||||
it('should handle zero and negative amounts', () => {
|
||||
const zeroPayment: MemberPayment = {
|
||||
id: 'payment-123',
|
||||
feeId: 'fee-456',
|
||||
driverId: 'driver-789',
|
||||
amount: 0,
|
||||
platformFee: 0,
|
||||
netAmount: 0,
|
||||
status: MemberPaymentStatus.PENDING,
|
||||
dueDate: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(zeroPayment.amount).toBe(0);
|
||||
expect(zeroPayment.platformFee).toBe(0);
|
||||
expect(zeroPayment.netAmount).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,200 @@
|
||||
import * as mod from '@core/payments/domain/entities/MembershipFee';
|
||||
import {
|
||||
MembershipFee,
|
||||
MembershipFeeType,
|
||||
} from '@core/payments/domain/entities/MembershipFee';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('payments/domain/entities/MembershipFee.ts', () => {
|
||||
it('imports', () => {
|
||||
expect(mod).toBeTruthy();
|
||||
describe('payments/domain/entities/MembershipFee', () => {
|
||||
describe('MembershipFeeType enum', () => {
|
||||
it('should have correct fee type values', () => {
|
||||
expect(MembershipFeeType.SEASON).toBe('season');
|
||||
expect(MembershipFeeType.MONTHLY).toBe('monthly');
|
||||
expect(MembershipFeeType.PER_RACE).toBe('per_race');
|
||||
});
|
||||
});
|
||||
|
||||
describe('MembershipFee interface', () => {
|
||||
it('should have all required properties', () => {
|
||||
const fee: MembershipFee = {
|
||||
id: 'fee-123',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 100,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(fee.id).toBe('fee-123');
|
||||
expect(fee.leagueId).toBe('league-456');
|
||||
expect(fee.type).toBe(MembershipFeeType.SEASON);
|
||||
expect(fee.amount).toBe(100);
|
||||
expect(fee.enabled).toBe(true);
|
||||
expect(fee.createdAt).toEqual(new Date('2024-01-01'));
|
||||
expect(fee.updatedAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should support optional seasonId property', () => {
|
||||
const fee: MembershipFee = {
|
||||
id: 'fee-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 100,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(fee.seasonId).toBe('season-789');
|
||||
});
|
||||
});
|
||||
|
||||
describe('MembershipFee.rehydrate', () => {
|
||||
it('should rehydrate a MembershipFee from props', () => {
|
||||
const props: MembershipFee = {
|
||||
id: 'fee-123',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 100,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = MembershipFee.rehydrate(props);
|
||||
|
||||
expect(rehydrated).toEqual(props);
|
||||
expect(rehydrated.id).toBe('fee-123');
|
||||
expect(rehydrated.leagueId).toBe('league-456');
|
||||
expect(rehydrated.type).toBe(MembershipFeeType.SEASON);
|
||||
expect(rehydrated.amount).toBe(100);
|
||||
expect(rehydrated.enabled).toBe(true);
|
||||
expect(rehydrated.createdAt).toEqual(new Date('2024-01-01'));
|
||||
expect(rehydrated.updatedAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should preserve optional seasonId when rehydrating', () => {
|
||||
const props: MembershipFee = {
|
||||
id: 'fee-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 100,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = MembershipFee.rehydrate(props);
|
||||
|
||||
expect(rehydrated.seasonId).toBe('season-789');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Business rules and invariants', () => {
|
||||
it('should support different fee types', () => {
|
||||
const seasonFee: MembershipFee = {
|
||||
id: 'fee-123',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 100,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const monthlyFee: MembershipFee = {
|
||||
id: 'fee-124',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.MONTHLY,
|
||||
amount: 50,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const perRaceFee: MembershipFee = {
|
||||
id: 'fee-125',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.PER_RACE,
|
||||
amount: 10,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(seasonFee.type).toBe(MembershipFeeType.SEASON);
|
||||
expect(monthlyFee.type).toBe(MembershipFeeType.MONTHLY);
|
||||
expect(perRaceFee.type).toBe(MembershipFeeType.PER_RACE);
|
||||
});
|
||||
|
||||
it('should handle enabled/disabled state', () => {
|
||||
const enabledFee: MembershipFee = {
|
||||
id: 'fee-123',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 100,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const disabledFee: MembershipFee = {
|
||||
id: 'fee-124',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 0,
|
||||
enabled: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(enabledFee.enabled).toBe(true);
|
||||
expect(disabledFee.enabled).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle zero and negative amounts', () => {
|
||||
const zeroFee: MembershipFee = {
|
||||
id: 'fee-123',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 0,
|
||||
enabled: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(zeroFee.amount).toBe(0);
|
||||
expect(zeroFee.enabled).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle different league and season combinations', () => {
|
||||
const leagueOnlyFee: MembershipFee = {
|
||||
id: 'fee-123',
|
||||
leagueId: 'league-456',
|
||||
type: MembershipFeeType.MONTHLY,
|
||||
amount: 50,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const leagueAndSeasonFee: MembershipFee = {
|
||||
id: 'fee-124',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
type: MembershipFeeType.SEASON,
|
||||
amount: 100,
|
||||
enabled: true,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(leagueOnlyFee.leagueId).toBe('league-456');
|
||||
expect(leagueOnlyFee.seasonId).toBeUndefined();
|
||||
expect(leagueAndSeasonFee.leagueId).toBe('league-456');
|
||||
expect(leagueAndSeasonFee.seasonId).toBe('season-789');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,311 @@
|
||||
import * as mod from '@core/payments/domain/entities/Payment';
|
||||
import {
|
||||
Payment,
|
||||
PaymentStatus,
|
||||
PaymentType,
|
||||
PayerType,
|
||||
} from '@core/payments/domain/entities/Payment';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('payments/domain/entities/Payment.ts', () => {
|
||||
it('imports', () => {
|
||||
expect(mod).toBeTruthy();
|
||||
describe('payments/domain/entities/Payment', () => {
|
||||
describe('PaymentType enum', () => {
|
||||
it('should have correct payment type values', () => {
|
||||
expect(PaymentType.SPONSORSHIP).toBe('sponsorship');
|
||||
expect(PaymentType.MEMBERSHIP_FEE).toBe('membership_fee');
|
||||
});
|
||||
});
|
||||
|
||||
describe('PayerType enum', () => {
|
||||
it('should have correct payer type values', () => {
|
||||
expect(PayerType.SPONSOR).toBe('sponsor');
|
||||
expect(PayerType.DRIVER).toBe('driver');
|
||||
});
|
||||
});
|
||||
|
||||
describe('PaymentStatus enum', () => {
|
||||
it('should have correct status values', () => {
|
||||
expect(PaymentStatus.PENDING).toBe('pending');
|
||||
expect(PaymentStatus.COMPLETED).toBe('completed');
|
||||
expect(PaymentStatus.FAILED).toBe('failed');
|
||||
expect(PaymentStatus.REFUNDED).toBe('refunded');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Payment interface', () => {
|
||||
it('should have all required properties', () => {
|
||||
const payment: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.PENDING,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(payment.id).toBe('payment-123');
|
||||
expect(payment.type).toBe(PaymentType.SPONSORSHIP);
|
||||
expect(payment.amount).toBe(1000);
|
||||
expect(payment.platformFee).toBe(50);
|
||||
expect(payment.netAmount).toBe(950);
|
||||
expect(payment.payerId).toBe('sponsor-456');
|
||||
expect(payment.payerType).toBe(PayerType.SPONSOR);
|
||||
expect(payment.leagueId).toBe('league-789');
|
||||
expect(payment.status).toBe(PaymentStatus.PENDING);
|
||||
expect(payment.createdAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should support optional seasonId property', () => {
|
||||
const payment: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.MEMBERSHIP_FEE,
|
||||
amount: 100,
|
||||
platformFee: 5,
|
||||
netAmount: 95,
|
||||
payerId: 'driver-456',
|
||||
payerType: PayerType.DRIVER,
|
||||
leagueId: 'league-789',
|
||||
seasonId: 'season-999',
|
||||
status: PaymentStatus.COMPLETED,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
completedAt: new Date('2024-01-15'),
|
||||
};
|
||||
|
||||
expect(payment.seasonId).toBe('season-999');
|
||||
expect(payment.completedAt).toEqual(new Date('2024-01-15'));
|
||||
});
|
||||
|
||||
it('should support optional completedAt property', () => {
|
||||
const payment: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.COMPLETED,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
completedAt: new Date('2024-01-15'),
|
||||
};
|
||||
|
||||
expect(payment.completedAt).toEqual(new Date('2024-01-15'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Payment.rehydrate', () => {
|
||||
it('should rehydrate a Payment from props', () => {
|
||||
const props: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.PENDING,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = Payment.rehydrate(props);
|
||||
|
||||
expect(rehydrated).toEqual(props);
|
||||
expect(rehydrated.id).toBe('payment-123');
|
||||
expect(rehydrated.type).toBe(PaymentType.SPONSORSHIP);
|
||||
expect(rehydrated.amount).toBe(1000);
|
||||
expect(rehydrated.platformFee).toBe(50);
|
||||
expect(rehydrated.netAmount).toBe(950);
|
||||
expect(rehydrated.payerId).toBe('sponsor-456');
|
||||
expect(rehydrated.payerType).toBe(PayerType.SPONSOR);
|
||||
expect(rehydrated.leagueId).toBe('league-789');
|
||||
expect(rehydrated.status).toBe(PaymentStatus.PENDING);
|
||||
expect(rehydrated.createdAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should preserve optional seasonId when rehydrating', () => {
|
||||
const props: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.MEMBERSHIP_FEE,
|
||||
amount: 100,
|
||||
platformFee: 5,
|
||||
netAmount: 95,
|
||||
payerId: 'driver-456',
|
||||
payerType: PayerType.DRIVER,
|
||||
leagueId: 'league-789',
|
||||
seasonId: 'season-999',
|
||||
status: PaymentStatus.COMPLETED,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
completedAt: new Date('2024-01-15'),
|
||||
};
|
||||
|
||||
const rehydrated = Payment.rehydrate(props);
|
||||
|
||||
expect(rehydrated.seasonId).toBe('season-999');
|
||||
expect(rehydrated.completedAt).toEqual(new Date('2024-01-15'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Business rules and invariants', () => {
|
||||
it('should calculate netAmount correctly (amount - platformFee)', () => {
|
||||
const payment: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.PENDING,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(payment.netAmount).toBe(payment.amount - payment.platformFee);
|
||||
});
|
||||
|
||||
it('should support different payment types', () => {
|
||||
const sponsorshipPayment: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.PENDING,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const membershipFeePayment: Payment = {
|
||||
id: 'payment-124',
|
||||
type: PaymentType.MEMBERSHIP_FEE,
|
||||
amount: 100,
|
||||
platformFee: 5,
|
||||
netAmount: 95,
|
||||
payerId: 'driver-456',
|
||||
payerType: PayerType.DRIVER,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.COMPLETED,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(sponsorshipPayment.type).toBe(PaymentType.SPONSORSHIP);
|
||||
expect(membershipFeePayment.type).toBe(PaymentType.MEMBERSHIP_FEE);
|
||||
});
|
||||
|
||||
it('should support different payer types', () => {
|
||||
const sponsorPayment: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.PENDING,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const driverPayment: Payment = {
|
||||
id: 'payment-124',
|
||||
type: PaymentType.MEMBERSHIP_FEE,
|
||||
amount: 100,
|
||||
platformFee: 5,
|
||||
netAmount: 95,
|
||||
payerId: 'driver-456',
|
||||
payerType: PayerType.DRIVER,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.COMPLETED,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(sponsorPayment.payerType).toBe(PayerType.SPONSOR);
|
||||
expect(driverPayment.payerType).toBe(PayerType.DRIVER);
|
||||
});
|
||||
|
||||
it('should support different payment statuses', () => {
|
||||
const pendingPayment: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.PENDING,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const completedPayment: Payment = {
|
||||
id: 'payment-124',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.COMPLETED,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
completedAt: new Date('2024-01-15'),
|
||||
};
|
||||
|
||||
const failedPayment: Payment = {
|
||||
id: 'payment-125',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.FAILED,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const refundedPayment: Payment = {
|
||||
id: 'payment-126',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 1000,
|
||||
platformFee: 50,
|
||||
netAmount: 950,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.REFUNDED,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(pendingPayment.status).toBe(PaymentStatus.PENDING);
|
||||
expect(completedPayment.status).toBe(PaymentStatus.COMPLETED);
|
||||
expect(failedPayment.status).toBe(PaymentStatus.FAILED);
|
||||
expect(refundedPayment.status).toBe(PaymentStatus.REFUNDED);
|
||||
});
|
||||
|
||||
it('should handle zero and negative amounts', () => {
|
||||
const zeroPayment: Payment = {
|
||||
id: 'payment-123',
|
||||
type: PaymentType.SPONSORSHIP,
|
||||
amount: 0,
|
||||
platformFee: 0,
|
||||
netAmount: 0,
|
||||
payerId: 'sponsor-456',
|
||||
payerType: PayerType.SPONSOR,
|
||||
leagueId: 'league-789',
|
||||
status: PaymentStatus.PENDING,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(zeroPayment.amount).toBe(0);
|
||||
expect(zeroPayment.platformFee).toBe(0);
|
||||
expect(zeroPayment.netAmount).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,298 @@
|
||||
import * as mod from '@core/payments/domain/entities/Prize';
|
||||
import { Prize, PrizeType } from '@core/payments/domain/entities/Prize';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('payments/domain/entities/Prize.ts', () => {
|
||||
it('imports', () => {
|
||||
expect(mod).toBeTruthy();
|
||||
describe('payments/domain/entities/Prize', () => {
|
||||
describe('PrizeType enum', () => {
|
||||
it('should have correct prize type values', () => {
|
||||
expect(PrizeType.CASH).toBe('cash');
|
||||
expect(PrizeType.MERCHANDISE).toBe('merchandise');
|
||||
expect(PrizeType.OTHER).toBe('other');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Prize interface', () => {
|
||||
it('should have all required properties', () => {
|
||||
const prize: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(prize.id).toBe('prize-123');
|
||||
expect(prize.leagueId).toBe('league-456');
|
||||
expect(prize.seasonId).toBe('season-789');
|
||||
expect(prize.position).toBe(1);
|
||||
expect(prize.name).toBe('Champion Prize');
|
||||
expect(prize.amount).toBe(1000);
|
||||
expect(prize.type).toBe(PrizeType.CASH);
|
||||
expect(prize.awarded).toBe(false);
|
||||
expect(prize.createdAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should support optional description property', () => {
|
||||
const prize: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
description: 'Awarded to the champion of the season',
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(prize.description).toBe('Awarded to the champion of the season');
|
||||
});
|
||||
|
||||
it('should support optional awardedTo and awardedAt properties', () => {
|
||||
const prize: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: true,
|
||||
awardedTo: 'driver-999',
|
||||
awardedAt: new Date('2024-06-01'),
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(prize.awardedTo).toBe('driver-999');
|
||||
expect(prize.awardedAt).toEqual(new Date('2024-06-01'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Prize.rehydrate', () => {
|
||||
it('should rehydrate a Prize from props', () => {
|
||||
const props: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = Prize.rehydrate(props);
|
||||
|
||||
expect(rehydrated).toEqual(props);
|
||||
expect(rehydrated.id).toBe('prize-123');
|
||||
expect(rehydrated.leagueId).toBe('league-456');
|
||||
expect(rehydrated.seasonId).toBe('season-789');
|
||||
expect(rehydrated.position).toBe(1);
|
||||
expect(rehydrated.name).toBe('Champion Prize');
|
||||
expect(rehydrated.amount).toBe(1000);
|
||||
expect(rehydrated.type).toBe(PrizeType.CASH);
|
||||
expect(rehydrated.awarded).toBe(false);
|
||||
expect(rehydrated.createdAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should preserve optional description when rehydrating', () => {
|
||||
const props: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
description: 'Awarded to the champion of the season',
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = Prize.rehydrate(props);
|
||||
|
||||
expect(rehydrated.description).toBe('Awarded to the champion of the season');
|
||||
});
|
||||
|
||||
it('should preserve optional awardedTo and awardedAt when rehydrating', () => {
|
||||
const props: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: true,
|
||||
awardedTo: 'driver-999',
|
||||
awardedAt: new Date('2024-06-01'),
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = Prize.rehydrate(props);
|
||||
|
||||
expect(rehydrated.awardedTo).toBe('driver-999');
|
||||
expect(rehydrated.awardedAt).toEqual(new Date('2024-06-01'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Business rules and invariants', () => {
|
||||
it('should support different prize types', () => {
|
||||
const cashPrize: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const merchandisePrize: Prize = {
|
||||
id: 'prize-124',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 2,
|
||||
name: 'T-Shirt',
|
||||
amount: 50,
|
||||
type: PrizeType.MERCHANDISE,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const otherPrize: Prize = {
|
||||
id: 'prize-125',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 3,
|
||||
name: 'Special Recognition',
|
||||
amount: 0,
|
||||
type: PrizeType.OTHER,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(cashPrize.type).toBe(PrizeType.CASH);
|
||||
expect(merchandisePrize.type).toBe(PrizeType.MERCHANDISE);
|
||||
expect(otherPrize.type).toBe(PrizeType.OTHER);
|
||||
});
|
||||
|
||||
it('should handle awarded and unawarded prizes', () => {
|
||||
const unawardedPrize: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const awardedPrize: Prize = {
|
||||
id: 'prize-124',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: true,
|
||||
awardedTo: 'driver-999',
|
||||
awardedAt: new Date('2024-06-01'),
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(unawardedPrize.awarded).toBe(false);
|
||||
expect(unawardedPrize.awardedTo).toBeUndefined();
|
||||
expect(unawardedPrize.awardedAt).toBeUndefined();
|
||||
|
||||
expect(awardedPrize.awarded).toBe(true);
|
||||
expect(awardedPrize.awardedTo).toBe('driver-999');
|
||||
expect(awardedPrize.awardedAt).toEqual(new Date('2024-06-01'));
|
||||
});
|
||||
|
||||
it('should handle different positions', () => {
|
||||
const firstPlacePrize: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const secondPlacePrize: Prize = {
|
||||
id: 'prize-124',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 2,
|
||||
name: 'Runner-Up Prize',
|
||||
amount: 500,
|
||||
type: PrizeType.CASH,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const thirdPlacePrize: Prize = {
|
||||
id: 'prize-125',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 3,
|
||||
name: 'Third Place Prize',
|
||||
amount: 250,
|
||||
type: PrizeType.CASH,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(firstPlacePrize.position).toBe(1);
|
||||
expect(secondPlacePrize.position).toBe(2);
|
||||
expect(thirdPlacePrize.position).toBe(3);
|
||||
});
|
||||
|
||||
it('should handle zero and negative amounts', () => {
|
||||
const zeroPrize: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Participation Prize',
|
||||
amount: 0,
|
||||
type: PrizeType.OTHER,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(zeroPrize.amount).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle different league and season combinations', () => {
|
||||
const leagueOnlyPrize: Prize = {
|
||||
id: 'prize-123',
|
||||
leagueId: 'league-456',
|
||||
seasonId: 'season-789',
|
||||
position: 1,
|
||||
name: 'Champion Prize',
|
||||
amount: 1000,
|
||||
type: PrizeType.CASH,
|
||||
awarded: false,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(leagueOnlyPrize.leagueId).toBe('league-456');
|
||||
expect(leagueOnlyPrize.seasonId).toBe('season-789');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,284 @@
|
||||
import * as mod from '@core/payments/domain/entities/Wallet';
|
||||
import {
|
||||
ReferenceType,
|
||||
Transaction,
|
||||
TransactionType,
|
||||
Wallet,
|
||||
} from '@core/payments/domain/entities/Wallet';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('payments/domain/entities/Wallet.ts', () => {
|
||||
it('imports', () => {
|
||||
expect(mod).toBeTruthy();
|
||||
describe('payments/domain/entities/Wallet', () => {
|
||||
describe('TransactionType enum', () => {
|
||||
it('should have correct transaction type values', () => {
|
||||
expect(TransactionType.DEPOSIT).toBe('deposit');
|
||||
expect(TransactionType.WITHDRAWAL).toBe('withdrawal');
|
||||
expect(TransactionType.PLATFORM_FEE).toBe('platform_fee');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ReferenceType enum', () => {
|
||||
it('should have correct reference type values', () => {
|
||||
expect(ReferenceType.SPONSORSHIP).toBe('sponsorship');
|
||||
expect(ReferenceType.MEMBERSHIP_FEE).toBe('membership_fee');
|
||||
expect(ReferenceType.PRIZE).toBe('prize');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Wallet interface', () => {
|
||||
it('should have all required properties', () => {
|
||||
const wallet: Wallet = {
|
||||
id: 'wallet-123',
|
||||
leagueId: 'league-456',
|
||||
balance: 1000,
|
||||
totalRevenue: 5000,
|
||||
totalPlatformFees: 250,
|
||||
totalWithdrawn: 3750,
|
||||
currency: 'USD',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(wallet.id).toBe('wallet-123');
|
||||
expect(wallet.leagueId).toBe('league-456');
|
||||
expect(wallet.balance).toBe(1000);
|
||||
expect(wallet.totalRevenue).toBe(5000);
|
||||
expect(wallet.totalPlatformFees).toBe(250);
|
||||
expect(wallet.totalWithdrawn).toBe(3750);
|
||||
expect(wallet.currency).toBe('USD');
|
||||
expect(wallet.createdAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Wallet.rehydrate', () => {
|
||||
it('should rehydrate a Wallet from props', () => {
|
||||
const props: Wallet = {
|
||||
id: 'wallet-123',
|
||||
leagueId: 'league-456',
|
||||
balance: 1000,
|
||||
totalRevenue: 5000,
|
||||
totalPlatformFees: 250,
|
||||
totalWithdrawn: 3750,
|
||||
currency: 'USD',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = Wallet.rehydrate(props);
|
||||
|
||||
expect(rehydrated).toEqual(props);
|
||||
expect(rehydrated.id).toBe('wallet-123');
|
||||
expect(rehydrated.leagueId).toBe('league-456');
|
||||
expect(rehydrated.balance).toBe(1000);
|
||||
expect(rehydrated.totalRevenue).toBe(5000);
|
||||
expect(rehydrated.totalPlatformFees).toBe(250);
|
||||
expect(rehydrated.totalWithdrawn).toBe(3750);
|
||||
expect(rehydrated.currency).toBe('USD');
|
||||
expect(rehydrated.createdAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Transaction interface', () => {
|
||||
it('should have all required properties', () => {
|
||||
const transaction: Transaction = {
|
||||
id: 'txn-123',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.DEPOSIT,
|
||||
amount: 1000,
|
||||
description: 'Sponsorship payment',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(transaction.id).toBe('txn-123');
|
||||
expect(transaction.walletId).toBe('wallet-456');
|
||||
expect(transaction.type).toBe(TransactionType.DEPOSIT);
|
||||
expect(transaction.amount).toBe(1000);
|
||||
expect(transaction.description).toBe('Sponsorship payment');
|
||||
expect(transaction.createdAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should support optional referenceId and referenceType properties', () => {
|
||||
const transaction: Transaction = {
|
||||
id: 'txn-123',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.DEPOSIT,
|
||||
amount: 1000,
|
||||
description: 'Sponsorship payment',
|
||||
referenceId: 'payment-789',
|
||||
referenceType: ReferenceType.SPONSORSHIP,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(transaction.referenceId).toBe('payment-789');
|
||||
expect(transaction.referenceType).toBe(ReferenceType.SPONSORSHIP);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Transaction.rehydrate', () => {
|
||||
it('should rehydrate a Transaction from props', () => {
|
||||
const props: Transaction = {
|
||||
id: 'txn-123',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.DEPOSIT,
|
||||
amount: 1000,
|
||||
description: 'Sponsorship payment',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = Transaction.rehydrate(props);
|
||||
|
||||
expect(rehydrated).toEqual(props);
|
||||
expect(rehydrated.id).toBe('txn-123');
|
||||
expect(rehydrated.walletId).toBe('wallet-456');
|
||||
expect(rehydrated.type).toBe(TransactionType.DEPOSIT);
|
||||
expect(rehydrated.amount).toBe(1000);
|
||||
expect(rehydrated.description).toBe('Sponsorship payment');
|
||||
expect(rehydrated.createdAt).toEqual(new Date('2024-01-01'));
|
||||
});
|
||||
|
||||
it('should preserve optional referenceId and referenceType when rehydrating', () => {
|
||||
const props: Transaction = {
|
||||
id: 'txn-123',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.DEPOSIT,
|
||||
amount: 1000,
|
||||
description: 'Sponsorship payment',
|
||||
referenceId: 'payment-789',
|
||||
referenceType: ReferenceType.SPONSORSHIP,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const rehydrated = Transaction.rehydrate(props);
|
||||
|
||||
expect(rehydrated.referenceId).toBe('payment-789');
|
||||
expect(rehydrated.referenceType).toBe(ReferenceType.SPONSORSHIP);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Business rules and invariants', () => {
|
||||
it('should calculate balance correctly', () => {
|
||||
const wallet: Wallet = {
|
||||
id: 'wallet-123',
|
||||
leagueId: 'league-456',
|
||||
balance: 1000,
|
||||
totalRevenue: 5000,
|
||||
totalPlatformFees: 250,
|
||||
totalWithdrawn: 3750,
|
||||
currency: 'USD',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
// Balance should be: totalRevenue - totalPlatformFees - totalWithdrawn
|
||||
const expectedBalance = wallet.totalRevenue - wallet.totalPlatformFees - wallet.totalWithdrawn;
|
||||
expect(wallet.balance).toBe(expectedBalance);
|
||||
});
|
||||
|
||||
it('should support different transaction types', () => {
|
||||
const depositTransaction: Transaction = {
|
||||
id: 'txn-123',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.DEPOSIT,
|
||||
amount: 1000,
|
||||
description: 'Sponsorship payment',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const withdrawalTransaction: Transaction = {
|
||||
id: 'txn-124',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.WITHDRAWAL,
|
||||
amount: 500,
|
||||
description: 'Withdrawal to bank',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const platformFeeTransaction: Transaction = {
|
||||
id: 'txn-125',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.PLATFORM_FEE,
|
||||
amount: 50,
|
||||
description: 'Platform fee deduction',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(depositTransaction.type).toBe(TransactionType.DEPOSIT);
|
||||
expect(withdrawalTransaction.type).toBe(TransactionType.WITHDRAWAL);
|
||||
expect(platformFeeTransaction.type).toBe(TransactionType.PLATFORM_FEE);
|
||||
});
|
||||
|
||||
it('should support different reference types', () => {
|
||||
const sponsorshipTransaction: Transaction = {
|
||||
id: 'txn-123',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.DEPOSIT,
|
||||
amount: 1000,
|
||||
description: 'Sponsorship payment',
|
||||
referenceId: 'payment-789',
|
||||
referenceType: ReferenceType.SPONSORSHIP,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const membershipFeeTransaction: Transaction = {
|
||||
id: 'txn-124',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.DEPOSIT,
|
||||
amount: 100,
|
||||
description: 'Membership fee payment',
|
||||
referenceId: 'payment-790',
|
||||
referenceType: ReferenceType.MEMBERSHIP_FEE,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const prizeTransaction: Transaction = {
|
||||
id: 'txn-125',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.WITHDRAWAL,
|
||||
amount: 500,
|
||||
description: 'Prize payout',
|
||||
referenceId: 'prize-791',
|
||||
referenceType: ReferenceType.PRIZE,
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(sponsorshipTransaction.referenceType).toBe(ReferenceType.SPONSORSHIP);
|
||||
expect(membershipFeeTransaction.referenceType).toBe(ReferenceType.MEMBERSHIP_FEE);
|
||||
expect(prizeTransaction.referenceType).toBe(ReferenceType.PRIZE);
|
||||
});
|
||||
|
||||
it('should handle zero and negative amounts', () => {
|
||||
const zeroTransaction: Transaction = {
|
||||
id: 'txn-123',
|
||||
walletId: 'wallet-456',
|
||||
type: TransactionType.DEPOSIT,
|
||||
amount: 0,
|
||||
description: 'Zero amount transaction',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(zeroTransaction.amount).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle different currencies', () => {
|
||||
const usdWallet: Wallet = {
|
||||
id: 'wallet-123',
|
||||
leagueId: 'league-456',
|
||||
balance: 1000,
|
||||
totalRevenue: 5000,
|
||||
totalPlatformFees: 250,
|
||||
totalWithdrawn: 3750,
|
||||
currency: 'USD',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
const eurWallet: Wallet = {
|
||||
id: 'wallet-124',
|
||||
leagueId: 'league-457',
|
||||
balance: 1000,
|
||||
totalRevenue: 5000,
|
||||
totalPlatformFees: 250,
|
||||
totalWithdrawn: 3750,
|
||||
currency: 'EUR',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
};
|
||||
|
||||
expect(usdWallet.currency).toBe('USD');
|
||||
expect(eurWallet.currency).toBe('EUR');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user