From fc39ddc61cb86fa25036c4eeb1a871a0a98ab5ed Mon Sep 17 00:00:00 2001 From: janapc Date: Mon, 19 Feb 2024 12:47:17 -0300 Subject: [PATCH] fix product lambda test --- .../database/repositories/product.test.ts | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/lambda/infra/database/repositories/product.test.ts b/lambda/infra/database/repositories/product.test.ts index af644f6..2c314d7 100644 --- a/lambda/infra/database/repositories/product.test.ts +++ b/lambda/infra/database/repositories/product.test.ts @@ -1,21 +1,7 @@ import { MongoDbProductRepository } from './product' -import { type Category, type Product } from '../../../entities/entities' +import { type Category } from '../../../entities/entities' import { productModel } from '../schemas/product' -const mockData = (product: Product): any => ({ - id: product.id, - title: product.title, - description: product.description, - ownerId: product.ownerId, - price: product.price, - category: { - id: product.category.id, - title: product.category.title, - description: product.category.description, - ownerId: product.category.ownerId, - }, -}) - const mockCategory: Category = { id: 'test', title: 'test', @@ -38,11 +24,7 @@ describe('Product Repository', () => { } const spyFindById = jest .spyOn(productModel, 'findById') - .mockImplementation((): any => { - return { - populate: jest.fn().mockResolvedValue(mockData(product)), - } - }) + .mockResolvedValue({ ...product, category: mockCategory.id }) const repository = new MongoDbProductRepository(productModel) const result = await repository.findById(product.id) expect(result).not.toBeNull() @@ -52,11 +34,7 @@ describe('Product Repository', () => { it('Should return null if a product not found', async () => { const spyFindById = jest .spyOn(productModel, 'findById') - .mockImplementation((): any => { - return { - populate: jest.fn().mockResolvedValue(null), - } - }) + .mockResolvedValue(null) const repository = new MongoDbProductRepository(productModel) const result = await repository.findById('asd') expect(result).toBeNull()