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,156 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { CancelUserDeletionCommand } from '../commands/cancel-user-deletion/cancel-user-deletion.command';
|
||||
import { ExportUserDataCommand } from '../commands/export-user-data/export-user-data.command';
|
||||
import { ForceDeleteUserCommand } from '../commands/force-delete-user/force-delete-user.command';
|
||||
import { LoginUserCommand } from '../commands/login-user/login-user.command';
|
||||
import { ProcessScheduledDeletionsCommand } from '../commands/process-scheduled-deletions/process-scheduled-deletions.command';
|
||||
import { RefreshTokenCommand } from '../commands/refresh-token/refresh-token.command';
|
||||
import { RegisterUserCommand } from '../commands/register-user/register-user.command';
|
||||
import { RequestUserDeletionCommand } from '../commands/request-user-deletion/request-user-deletion.command';
|
||||
import { VerifyKycCommand } from '../commands/verify-kyc/verify-kyc.command';
|
||||
import { GetAgentByUserIdQuery } from '../queries/get-agent-by-user-id/get-agent-by-user-id.query';
|
||||
import { GetProfileQuery } from '../queries/get-profile/get-profile.query';
|
||||
|
||||
describe('Auth Commands & Queries', () => {
|
||||
describe('RegisterUserCommand', () => {
|
||||
it('stores all required properties', () => {
|
||||
const cmd = new RegisterUserCommand('0912345678', 'P@ssw0rd!', 'Nguyen Van A');
|
||||
expect(cmd.phone).toBe('0912345678');
|
||||
expect(cmd.password).toBe('P@ssw0rd!');
|
||||
expect(cmd.fullName).toBe('Nguyen Van A');
|
||||
});
|
||||
|
||||
it('stores optional email', () => {
|
||||
const cmd = new RegisterUserCommand('0912345678', 'P@ssw0rd!', 'Nguyen Van A', 'test@email.com');
|
||||
expect(cmd.email).toBe('test@email.com');
|
||||
});
|
||||
|
||||
it('email is undefined when not provided', () => {
|
||||
const cmd = new RegisterUserCommand('0912345678', 'P@ssw0rd!', 'Nguyen Van A');
|
||||
expect(cmd.email).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('LoginUserCommand', () => {
|
||||
it('stores userId, phone, and role', () => {
|
||||
const cmd = new LoginUserCommand('user-1', '0912345678', 'BUYER');
|
||||
expect(cmd.userId).toBe('user-1');
|
||||
expect(cmd.phone).toBe('0912345678');
|
||||
expect(cmd.role).toBe('BUYER');
|
||||
});
|
||||
|
||||
it('accepts different roles', () => {
|
||||
const cmd = new LoginUserCommand('user-2', '0987654321', 'ADMIN');
|
||||
expect(cmd.role).toBe('ADMIN');
|
||||
});
|
||||
});
|
||||
|
||||
describe('RefreshTokenCommand', () => {
|
||||
it('stores refreshToken string', () => {
|
||||
const cmd = new RefreshTokenCommand('family.token-hex');
|
||||
expect(cmd.refreshToken).toBe('family.token-hex');
|
||||
});
|
||||
|
||||
it('handles long token values', () => {
|
||||
const longToken = 'a'.repeat(256);
|
||||
const cmd = new RefreshTokenCommand(longToken);
|
||||
expect(cmd.refreshToken).toBe(longToken);
|
||||
});
|
||||
});
|
||||
|
||||
describe('VerifyKycCommand', () => {
|
||||
it('stores userId and kycStatus', () => {
|
||||
const cmd = new VerifyKycCommand('user-1', 'APPROVED');
|
||||
expect(cmd.userId).toBe('user-1');
|
||||
expect(cmd.kycStatus).toBe('APPROVED');
|
||||
});
|
||||
|
||||
it('stores optional kycData', () => {
|
||||
const kycData = { idNumber: '123456789' };
|
||||
const cmd = new VerifyKycCommand('user-1', 'APPROVED', kycData);
|
||||
expect(cmd.kycData).toEqual(kycData);
|
||||
});
|
||||
|
||||
it('kycData is undefined when not provided', () => {
|
||||
const cmd = new VerifyKycCommand('user-1', 'REJECTED');
|
||||
expect(cmd.kycData).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('CancelUserDeletionCommand', () => {
|
||||
it('stores userId', () => {
|
||||
const cmd = new CancelUserDeletionCommand('user-1');
|
||||
expect(cmd.userId).toBe('user-1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ExportUserDataCommand', () => {
|
||||
it('stores userId', () => {
|
||||
const cmd = new ExportUserDataCommand('user-1');
|
||||
expect(cmd.userId).toBe('user-1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ForceDeleteUserCommand', () => {
|
||||
it('stores userId, adminId, and reason', () => {
|
||||
const cmd = new ForceDeleteUserCommand('user-1', 'admin-1', 'Violation of terms');
|
||||
expect(cmd.userId).toBe('user-1');
|
||||
expect(cmd.adminId).toBe('admin-1');
|
||||
expect(cmd.reason).toBe('Violation of terms');
|
||||
});
|
||||
|
||||
it('preserves Vietnamese text in reason', () => {
|
||||
const cmd = new ForceDeleteUserCommand('user-2', 'admin-1', 'Vi phạm điều khoản sử dụng');
|
||||
expect(cmd.reason).toBe('Vi phạm điều khoản sử dụng');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ProcessScheduledDeletionsCommand', () => {
|
||||
it('is instantiable with no arguments', () => {
|
||||
const cmd = new ProcessScheduledDeletionsCommand();
|
||||
expect(cmd).toBeDefined();
|
||||
expect(cmd).toBeInstanceOf(ProcessScheduledDeletionsCommand);
|
||||
});
|
||||
});
|
||||
|
||||
describe('RequestUserDeletionCommand', () => {
|
||||
it('stores userId', () => {
|
||||
const cmd = new RequestUserDeletionCommand('user-1');
|
||||
expect(cmd.userId).toBe('user-1');
|
||||
});
|
||||
|
||||
it('stores optional reason', () => {
|
||||
const cmd = new RequestUserDeletionCommand('user-1', 'No longer needed');
|
||||
expect(cmd.reason).toBe('No longer needed');
|
||||
});
|
||||
|
||||
it('reason is undefined when not provided', () => {
|
||||
const cmd = new RequestUserDeletionCommand('user-1');
|
||||
expect(cmd.reason).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetProfileQuery', () => {
|
||||
it('stores userId', () => {
|
||||
const query = new GetProfileQuery('user-1');
|
||||
expect(query.userId).toBe('user-1');
|
||||
});
|
||||
|
||||
it('is an instance of GetProfileQuery', () => {
|
||||
const query = new GetProfileQuery('user-2');
|
||||
expect(query).toBeInstanceOf(GetProfileQuery);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GetAgentByUserIdQuery', () => {
|
||||
it('stores userId', () => {
|
||||
const query = new GetAgentByUserIdQuery('user-1');
|
||||
expect(query.userId).toBe('user-1');
|
||||
});
|
||||
|
||||
it('is an instance of GetAgentByUserIdQuery', () => {
|
||||
const query = new GetAgentByUserIdQuery('user-2');
|
||||
expect(query).toBeInstanceOf(GetAgentByUserIdQuery);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user