test(api): add domain layer unit tests across all modules

Cover admin events, notifications, reviews, search VOs, listings (property,
media, events, price/geo/address VOs), auth events, payment events,
subscription events, and analytics events. Raises domain test coverage
from ~24% to ~75%.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-09 00:36:39 +07:00
parent 801e29e65c
commit 62f4f001b6
14 changed files with 973 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
import { describe, it, expect } from 'vitest';
import { PaymentCreatedEvent } from '../events/payment-created.event';
import { PaymentCompletedEvent } from '../events/payment-completed.event';
import { PaymentFailedEvent } from '../events/payment-failed.event';
describe('Payment Domain Events', () => {
describe('PaymentCreatedEvent', () => {
it('creates event with correct properties', () => {
const event = new PaymentCreatedEvent(
'payment-1',
'user-1',
'VNPAY',
'SUBSCRIPTION',
500_000n,
);
expect(event.eventName).toBe('payment.created');
expect(event.aggregateId).toBe('payment-1');
expect(event.userId).toBe('user-1');
expect(event.provider).toBe('VNPAY');
expect(event.type).toBe('SUBSCRIPTION');
expect(event.amountVND).toBe(500_000n);
expect(event.occurredAt).toBeInstanceOf(Date);
});
it('creates event for LISTING_FEE type', () => {
const event = new PaymentCreatedEvent(
'payment-2',
'user-2',
'VNPAY',
'LISTING_FEE',
100_000n,
);
expect(event.type).toBe('LISTING_FEE');
});
});
describe('PaymentCompletedEvent', () => {
it('creates event with correct properties', () => {
const event = new PaymentCompletedEvent('payment-1', 'user-1', 'VNPAY', 500_000n);
expect(event.eventName).toBe('payment.completed');
expect(event.aggregateId).toBe('payment-1');
expect(event.userId).toBe('user-1');
expect(event.provider).toBe('VNPAY');
expect(event.amountVND).toBe(500_000n);
expect(event.occurredAt).toBeInstanceOf(Date);
});
});
describe('PaymentFailedEvent', () => {
it('creates event with correct properties', () => {
const event = new PaymentFailedEvent('payment-1', 'user-1', 'VNPAY');
expect(event.eventName).toBe('payment.failed');
expect(event.aggregateId).toBe('payment-1');
expect(event.userId).toBe('user-1');
expect(event.provider).toBe('VNPAY');
expect(event.occurredAt).toBeInstanceOf(Date);
});
});
});