test: increase test coverage for listings, auth, and search modules
Add 33 new test files to reach coverage targets: - Listings: 13 → 28 test files (50%+) - Auth: 21 → 36 test files (50%+) - Search: 10 → 13 test files (59%+) New tests cover domain entities, value objects, services, guards, decorators, DTOs, repositories, controllers, and event handlers. Total: 204 test files, 1178 tests passing. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { AgentVerifiedEvent } from '../events/agent-verified.event';
|
||||
import { UserDeactivatedEvent } from '../events/user-deactivated.event';
|
||||
import { UserKycUpdatedEvent } from '../events/user-kyc-updated.event';
|
||||
import { UserRegisteredEvent } from '../events/user-registered.event';
|
||||
|
||||
describe('Auth Domain Events — construction & property access', () => {
|
||||
describe('UserRegisteredEvent', () => {
|
||||
it('stores aggregateId, phone and role', () => {
|
||||
const event = new UserRegisteredEvent('u-1', '+84900000001', 'BUYER');
|
||||
expect(event.aggregateId).toBe('u-1');
|
||||
expect(event.phone).toBe('+84900000001');
|
||||
expect(event.role).toBe('BUYER');
|
||||
});
|
||||
|
||||
it('has eventName "user.registered"', () => {
|
||||
const event = new UserRegisteredEvent('u-2', '+84900000002', 'AGENT');
|
||||
expect(event.eventName).toBe('user.registered');
|
||||
});
|
||||
|
||||
it('sets occurredAt to a recent Date', () => {
|
||||
const before = new Date();
|
||||
const event = new UserRegisteredEvent('u-3', '+84900000003', 'SELLER');
|
||||
const after = new Date();
|
||||
expect(event.occurredAt.getTime()).toBeGreaterThanOrEqual(before.getTime());
|
||||
expect(event.occurredAt.getTime()).toBeLessThanOrEqual(after.getTime());
|
||||
});
|
||||
});
|
||||
|
||||
describe('AgentVerifiedEvent', () => {
|
||||
it('stores aggregateId and userId', () => {
|
||||
const event = new AgentVerifiedEvent('agent-1', 'user-1');
|
||||
expect(event.aggregateId).toBe('agent-1');
|
||||
expect(event.userId).toBe('user-1');
|
||||
});
|
||||
|
||||
it('has eventName "agent.verified"', () => {
|
||||
const event = new AgentVerifiedEvent('agent-2', 'user-2');
|
||||
expect(event.eventName).toBe('agent.verified');
|
||||
});
|
||||
|
||||
it('sets occurredAt to a Date instance', () => {
|
||||
const event = new AgentVerifiedEvent('agent-3', 'user-3');
|
||||
expect(event.occurredAt).toBeInstanceOf(Date);
|
||||
});
|
||||
});
|
||||
|
||||
describe('UserKycUpdatedEvent', () => {
|
||||
it('stores aggregateId, newStatus, and previousStatus', () => {
|
||||
const event = new UserKycUpdatedEvent('u-1', 'APPROVED', 'PENDING');
|
||||
expect(event.aggregateId).toBe('u-1');
|
||||
expect(event.newStatus).toBe('APPROVED');
|
||||
expect(event.previousStatus).toBe('PENDING');
|
||||
});
|
||||
|
||||
it('has eventName "user.kyc_updated"', () => {
|
||||
const event = new UserKycUpdatedEvent('u-2', 'REJECTED', 'APPROVED');
|
||||
expect(event.eventName).toBe('user.kyc_updated');
|
||||
});
|
||||
|
||||
it('tracks status transition from NONE to PENDING', () => {
|
||||
const event = new UserKycUpdatedEvent('u-3', 'PENDING', 'NONE');
|
||||
expect(event.newStatus).toBe('PENDING');
|
||||
expect(event.previousStatus).toBe('NONE');
|
||||
});
|
||||
});
|
||||
|
||||
describe('UserDeactivatedEvent', () => {
|
||||
it('stores aggregateId', () => {
|
||||
const event = new UserDeactivatedEvent('u-1');
|
||||
expect(event.aggregateId).toBe('u-1');
|
||||
});
|
||||
|
||||
it('has eventName "user.deactivated"', () => {
|
||||
const event = new UserDeactivatedEvent('u-2');
|
||||
expect(event.eventName).toBe('user.deactivated');
|
||||
});
|
||||
|
||||
it('sets occurredAt to a Date instance', () => {
|
||||
const event = new UserDeactivatedEvent('u-3');
|
||||
expect(event.occurredAt).toBeInstanceOf(Date);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user