diff --git a/src/__test__/wishList.test.ts b/src/__test__/wishList.test.ts index 23f2609..5cdcacf 100644 --- a/src/__test__/wishList.test.ts +++ b/src/__test__/wishList.test.ts @@ -146,10 +146,10 @@ describe('Wish list management tests', () => { }); describe('Get products in wishList', () => { - it('Returns 404 when buyer has no product in wish list', async () => { + it('Returns No products in wish list when buyer has no product in wish list', async () => { const token = jwt.sign(data2, jwtSecretKey); const response = await request(app).get('/wish-list').set('Authorization', `Bearer ${token}`); - expect(response.status).toBe(404); + expect(response.status).toBe(200); expect(response.body.message).toBe('No products in wish list'); }); diff --git a/src/services/wishListServices/getProducts.ts b/src/services/wishListServices/getProducts.ts index a419134..2c2adb3 100644 --- a/src/services/wishListServices/getProducts.ts +++ b/src/services/wishListServices/getProducts.ts @@ -11,22 +11,16 @@ export const getProductsService = async (req: Request, res: Response) => { const productsForBuyer = await wishListRepository.find({ where: { buyer: { id: req.user?.id } } }); if (productsForBuyer.length === 0) { - return res.status(404).json({ message: 'No products in wish list', products: productsForBuyer }); + return res.status(200).json({ message: 'No products in wish list', products: productsForBuyer }); } const buyerWishProducts = await Promise.all( productsForBuyer.map(async product => { - const productDetails = await productRepository.findOne({ where: { id: product.productId } }); + const productDetails = await productRepository.findOne({ where: { id: product.productId }, relations: ['vendor', 'categories'] }); if (productDetails) { return { wishListDetails: product, - productInfo: { - productId: productDetails.id, - name: productDetails.name, - image: productDetails.images, - newPrice: productDetails.newPrice, - vendorId: productDetails.vendor, - }, + productInfo: productDetails, }; } })