refactor
This commit is contained in:
73
core/racing/domain/value-objects/MembershipFee.test.ts
Normal file
73
core/racing/domain/value-objects/MembershipFee.test.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { MembershipFee } from './MembershipFee';
|
||||
import { Money } from './Money';
|
||||
|
||||
describe('MembershipFee', () => {
|
||||
it('should create valid membership fee', () => {
|
||||
const amount = Money.create(1000, 'USD');
|
||||
const fee = MembershipFee.create('season', amount);
|
||||
expect(fee.type).toBe('season');
|
||||
expect(fee.amount).toBe(amount);
|
||||
});
|
||||
|
||||
it('should validate type required', () => {
|
||||
const amount = Money.create(1000, 'USD');
|
||||
expect(() => MembershipFee.create('' as 'season', amount)).toThrow('MembershipFee type is required');
|
||||
});
|
||||
|
||||
it('should validate amount required', () => {
|
||||
expect(() => MembershipFee.create('season', null as unknown as Money)).toThrow('MembershipFee amount is required');
|
||||
});
|
||||
|
||||
it('should validate amount not negative', () => {
|
||||
expect(() => Money.create(-100, 'USD')).toThrow('Money amount cannot be negative');
|
||||
});
|
||||
|
||||
it('should get platform fee', () => {
|
||||
const amount = Money.create(1000, 'USD'); // $10.00
|
||||
const fee = MembershipFee.create('season', amount);
|
||||
const platformFee = fee.getPlatformFee();
|
||||
expect(platformFee.amount).toBe(100); // $1.00
|
||||
expect(platformFee.currency).toBe('USD');
|
||||
});
|
||||
|
||||
it('should get net amount', () => {
|
||||
const amount = Money.create(1000, 'USD'); // $10.00
|
||||
const fee = MembershipFee.create('season', amount);
|
||||
const netAmount = fee.getNetAmount();
|
||||
expect(netAmount.amount).toBe(900); // $9.00
|
||||
expect(netAmount.currency).toBe('USD');
|
||||
});
|
||||
|
||||
it('should check if recurring', () => {
|
||||
const amount = Money.create(1000, 'USD');
|
||||
const seasonFee = MembershipFee.create('season', amount);
|
||||
const monthlyFee = MembershipFee.create('monthly', amount);
|
||||
const perRaceFee = MembershipFee.create('per_race', amount);
|
||||
expect(seasonFee.isRecurring()).toBe(false);
|
||||
expect(monthlyFee.isRecurring()).toBe(true);
|
||||
expect(perRaceFee.isRecurring()).toBe(false);
|
||||
});
|
||||
|
||||
it('should have props', () => {
|
||||
const amount = Money.create(1000, 'USD');
|
||||
const fee = MembershipFee.create('season', amount);
|
||||
expect(fee.props).toEqual({
|
||||
type: 'season',
|
||||
amount,
|
||||
});
|
||||
});
|
||||
|
||||
it('equals', () => {
|
||||
const amount1 = Money.create(1000, 'USD');
|
||||
const amount2 = Money.create(1000, 'USD');
|
||||
const amount3 = Money.create(2000, 'USD');
|
||||
const fee1 = MembershipFee.create('season', amount1);
|
||||
const fee2 = MembershipFee.create('season', amount2);
|
||||
const fee3 = MembershipFee.create('monthly', amount1);
|
||||
const fee4 = MembershipFee.create('season', amount3);
|
||||
expect(fee1.equals(fee2)).toBe(true);
|
||||
expect(fee1.equals(fee3)).toBe(false);
|
||||
expect(fee1.equals(fee4)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user