test(listings): add updateListing controller tests for PATCH /api/v1/listings/:id
Cover the updateListing controller method: basic command dispatch and full-field update with re-moderation flag. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -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', () => {
|
describe('updateStatus', () => {
|
||||||
it('should execute UpdateListingStatusCommand via command bus', async () => {
|
it('should execute UpdateListingStatusCommand via command bus', async () => {
|
||||||
mockCommandBus.execute.mockResolvedValue({ status: 'ACTIVE' });
|
mockCommandBus.execute.mockResolvedValue({ status: 'ACTIVE' });
|
||||||
|
|||||||
Reference in New Issue
Block a user