diff --git a/apps/api/src/modules/listings/presentation/__tests__/listings.controller.spec.ts b/apps/api/src/modules/listings/presentation/__tests__/listings.controller.spec.ts index 8362996..39cd2b2 100644 --- a/apps/api/src/modules/listings/presentation/__tests__/listings.controller.spec.ts +++ b/apps/api/src/modules/listings/presentation/__tests__/listings.controller.spec.ts @@ -96,6 +96,55 @@ describe('ListingsController', () => { }); }); + describe('updateListing', () => { + it('should execute UpdateListingCommand via command bus', async () => { + const mockResult = { + listingId: 'listing-1', + status: 'DRAFT', + updatedFields: ['title', 'priceVND'], + resubmittedForModeration: false, + }; + mockCommandBus.execute.mockResolvedValue(mockResult); + + const dto = { + title: 'Căn hộ 3PN view sông mới', + priceVND: 6_000_000_000n, + }; + const user = { sub: 'seller-1', email: 'seller@example.com', role: 'SELLER' }; + + const result = await controller.updateListing('listing-1', dto as any, user as any); + + expect(result).toEqual(mockResult); + expect(mockCommandBus.execute).toHaveBeenCalledTimes(1); + }); + + it('should pass all optional fields to the command', async () => { + const mockResult = { + listingId: 'listing-1', + status: 'PENDING_REVIEW', + updatedFields: ['title', 'description', 'priceVND', 'rentPriceMonthly', 'amenities', 'mediaOrder'], + resubmittedForModeration: true, + }; + mockCommandBus.execute.mockResolvedValue(mockResult); + + const dto = { + title: 'Tiêu đề cập nhật', + description: 'Mô tả chi tiết hơn cho căn hộ', + priceVND: 5_500_000_000n, + rentPriceMonthly: 25_000_000n, + amenities: ['Hồ bơi', 'Gym'], + mediaOrder: [{ mediaId: 'media-1', order: 0 }], + }; + const user = { sub: 'seller-1', email: 'seller@example.com', role: 'SELLER' }; + + const result = await controller.updateListing('listing-1', dto as any, user as any); + + expect(result.resubmittedForModeration).toBe(true); + expect(result.status).toBe('PENDING_REVIEW'); + expect(mockCommandBus.execute).toHaveBeenCalledTimes(1); + }); + }); + describe('updateStatus', () => { it('should execute UpdateListingStatusCommand via command bus', async () => { mockCommandBus.execute.mockResolvedValue({ status: 'ACTIVE' });