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,68 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { GeoFilter } from '../value-objects/geo-filter.vo';
|
||||
|
||||
describe('GeoFilter', () => {
|
||||
it('creates filter with all properties', () => {
|
||||
const filter = GeoFilter.create({
|
||||
lat: 10.7769,
|
||||
lng: 106.7009,
|
||||
radiusKm: 5,
|
||||
propertyType: 'APARTMENT',
|
||||
transactionType: 'RENT',
|
||||
priceMin: 5_000_000,
|
||||
priceMax: 20_000_000,
|
||||
sortBy: 'price_asc',
|
||||
page: 3,
|
||||
perPage: 25,
|
||||
});
|
||||
|
||||
expect(filter.lat).toBe(10.7769);
|
||||
expect(filter.lng).toBe(106.7009);
|
||||
expect(filter.radiusKm).toBe(5);
|
||||
expect(filter.propertyType).toBe('APARTMENT');
|
||||
expect(filter.transactionType).toBe('RENT');
|
||||
expect(filter.priceMin).toBe(5_000_000);
|
||||
expect(filter.priceMax).toBe(20_000_000);
|
||||
expect(filter.sortBy).toBe('price_asc');
|
||||
expect(filter.page).toBe(3);
|
||||
expect(filter.perPage).toBe(25);
|
||||
});
|
||||
|
||||
it('applies default sortBy as distance', () => {
|
||||
const filter = GeoFilter.create({ lat: 10.7, lng: 106.7, radiusKm: 5 });
|
||||
expect(filter.sortBy).toBe('distance');
|
||||
});
|
||||
|
||||
it('applies default page as 1', () => {
|
||||
const filter = GeoFilter.create({ lat: 10.7, lng: 106.7, radiusKm: 5 });
|
||||
expect(filter.page).toBe(1);
|
||||
});
|
||||
|
||||
it('applies default perPage as 20', () => {
|
||||
const filter = GeoFilter.create({ lat: 10.7, lng: 106.7, radiusKm: 5 });
|
||||
expect(filter.perPage).toBe(20);
|
||||
});
|
||||
|
||||
it('caps radiusKm at 100', () => {
|
||||
const filter = GeoFilter.create({ lat: 10.7, lng: 106.7, radiusKm: 200 });
|
||||
expect(filter.radiusKm).toBe(100);
|
||||
});
|
||||
|
||||
it('does not cap radiusKm when under 100', () => {
|
||||
const filter = GeoFilter.create({ lat: 10.7, lng: 106.7, radiusKm: 50 });
|
||||
expect(filter.radiusKm).toBe(50);
|
||||
});
|
||||
|
||||
it('caps perPage at 100', () => {
|
||||
const filter = GeoFilter.create({ lat: 10.7, lng: 106.7, radiusKm: 5, perPage: 500 });
|
||||
expect(filter.perPage).toBe(100);
|
||||
});
|
||||
|
||||
it('returns undefined for unset optional properties', () => {
|
||||
const filter = GeoFilter.create({ lat: 10.7, lng: 106.7, radiusKm: 5 });
|
||||
expect(filter.propertyType).toBeUndefined();
|
||||
expect(filter.transactionType).toBeUndefined();
|
||||
expect(filter.priceMin).toBeUndefined();
|
||||
expect(filter.priceMax).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { SearchFilter } from '../value-objects/search-filter.vo';
|
||||
|
||||
describe('SearchFilter', () => {
|
||||
it('creates filter with all properties', () => {
|
||||
const filter = SearchFilter.create({
|
||||
query: 'căn hộ quận 7',
|
||||
propertyType: 'APARTMENT',
|
||||
transactionType: 'SALE',
|
||||
priceMin: 2_000_000_000,
|
||||
priceMax: 8_000_000_000,
|
||||
areaMin: 60,
|
||||
areaMax: 150,
|
||||
bedrooms: 2,
|
||||
district: 'Quận 7',
|
||||
city: 'Hồ Chí Minh',
|
||||
sortBy: 'price_desc',
|
||||
page: 4,
|
||||
perPage: 30,
|
||||
});
|
||||
|
||||
expect(filter.query).toBe('căn hộ quận 7');
|
||||
expect(filter.propertyType).toBe('APARTMENT');
|
||||
expect(filter.transactionType).toBe('SALE');
|
||||
expect(filter.priceMin).toBe(2_000_000_000);
|
||||
expect(filter.priceMax).toBe(8_000_000_000);
|
||||
expect(filter.areaMin).toBe(60);
|
||||
expect(filter.areaMax).toBe(150);
|
||||
expect(filter.bedrooms).toBe(2);
|
||||
expect(filter.district).toBe('Quận 7');
|
||||
expect(filter.city).toBe('Hồ Chí Minh');
|
||||
expect(filter.sortBy).toBe('price_desc');
|
||||
expect(filter.page).toBe(4);
|
||||
expect(filter.perPage).toBe(30);
|
||||
});
|
||||
|
||||
it('applies default sortBy as relevance', () => {
|
||||
const filter = SearchFilter.create({});
|
||||
expect(filter.sortBy).toBe('relevance');
|
||||
});
|
||||
|
||||
it('applies default page as 1', () => {
|
||||
const filter = SearchFilter.create({});
|
||||
expect(filter.page).toBe(1);
|
||||
});
|
||||
|
||||
it('applies default perPage as 20', () => {
|
||||
const filter = SearchFilter.create({});
|
||||
expect(filter.perPage).toBe(20);
|
||||
});
|
||||
|
||||
it('caps perPage at 100', () => {
|
||||
const filter = SearchFilter.create({ perPage: 250 });
|
||||
expect(filter.perPage).toBe(100);
|
||||
});
|
||||
|
||||
it('returns undefined for unset optional properties', () => {
|
||||
const filter = SearchFilter.create({});
|
||||
expect(filter.query).toBeUndefined();
|
||||
expect(filter.propertyType).toBeUndefined();
|
||||
expect(filter.transactionType).toBeUndefined();
|
||||
expect(filter.priceMin).toBeUndefined();
|
||||
expect(filter.priceMax).toBeUndefined();
|
||||
expect(filter.areaMin).toBeUndefined();
|
||||
expect(filter.areaMax).toBeUndefined();
|
||||
expect(filter.bedrooms).toBeUndefined();
|
||||
expect(filter.district).toBeUndefined();
|
||||
expect(filter.city).toBeUndefined();
|
||||
});
|
||||
|
||||
it('handles empty query string', () => {
|
||||
const filter = SearchFilter.create({ query: '' });
|
||||
expect(filter.query).toBe('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user