test: add unit tests for Analytics, Search, and Notifications modules

Add 15 test files with 45 test cases covering all untested handlers:
- Analytics: track-event, generate-report, update-market-index, get-heatmap, get-price-trend, get-market-report, get-district-stats
- Search: reindex-all, sync-listing, search-properties, geo-search, listing-approved event handler
- Notifications: send-notification, agent-verified listener, user-registered listener

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 04:08:48 +07:00
parent 8e7672694b
commit 09034a5f9b
15 changed files with 1010 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
import { ListingApprovedEventHandler } from '../event-handlers/listing-approved.handler';
describe('ListingApprovedEventHandler', () => {
let handler: ListingApprovedEventHandler;
let mockIndexer: { indexListing: ReturnType<typeof vi.fn>; removeListing: ReturnType<typeof vi.fn> };
let mockLogger: { log: ReturnType<typeof vi.fn>; warn: ReturnType<typeof vi.fn>; error: ReturnType<typeof vi.fn> };
beforeEach(() => {
mockIndexer = {
indexListing: vi.fn(),
removeListing: vi.fn(),
};
mockLogger = {
log: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};
handler = new ListingApprovedEventHandler(mockIndexer as any, mockLogger as any);
});
it('indexes listing on listing.approved event', async () => {
mockIndexer.indexListing.mockResolvedValue(undefined);
await handler.handle({ listingId: 'listing-1' });
expect(mockIndexer.indexListing).toHaveBeenCalledWith('listing-1');
expect(mockLogger.log).toHaveBeenCalled();
});
it('indexes listing on listing.updated event', async () => {
mockIndexer.indexListing.mockResolvedValue(undefined);
await handler.handleUpdate({ listingId: 'listing-2' });
expect(mockIndexer.indexListing).toHaveBeenCalledWith('listing-2');
});
it('removes listing on listing.deactivated event', async () => {
mockIndexer.removeListing.mockResolvedValue(undefined);
await handler.handleDeactivation({ listingId: 'listing-3' });
expect(mockIndexer.removeListing).toHaveBeenCalledWith('listing-3');
});
});