Skip to content

Commit

Permalink
fix product lambda test
Browse files Browse the repository at this point in the history
  • Loading branch information
janapc committed Feb 19, 2024
1 parent d30be2f commit fc39ddc
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions lambda/infra/database/repositories/product.test.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit fc39ddc

Please sign in to comment.