Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Istiopaxx committed Nov 13, 2023
1 parent 9cc9d2a commit 66e7e12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
16 changes: 8 additions & 8 deletions api/libs/recipe/src/dto/recipe/filter-recipe.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ export class RecipeListViewResponseDto extends OmitType(Recipe, [
'ingredient_requirements',
] as const) {
constructor(
id: Schema.Types.ObjectId,
owner: User,
name: string,
thumbnail: string,
description: string,
view_count: number,
created_at: Date,
updated_at: Date,
id: Schema.Types.ObjectId = null,
owner: User = null,
name: string = null,
thumbnail: string = null,
description: string = null,
view_count: number = null,
created_at: Date = null,
updated_at: Date = null,
) {
super();
this.id = id;
Expand Down
16 changes: 15 additions & 1 deletion api/libs/recipe/src/services/recipe.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,23 @@ describe('RecipeService', () => {
it('should return a recipe', async () => {
const recipe = new Recipe();
recipeRepository.findOne.mockResolvedValue(recipe);
recipeRepository.increaseViewCount.mockResolvedValue(new Recipe());
recipeViewLogRepository.create.mockResolvedValue(new RecipeViewLog());

const result = await service.findOne('1');
const result = await service.findOne('1', {
ip: '::1',
user: {
...new User(),
id: '1' as any,
},
});

expect(recipeRepository.increaseViewCount).toHaveBeenCalledWith('1');
expect(recipeViewLogRepository.create).toHaveBeenCalledWith({
recipe_id: '1',
user_id: '1',
user_ip: '::1',
});
expect(recipeRepository.findOne).toHaveBeenCalledWith('1');
expect(result).toEqual(recipe);
});
Expand Down
4 changes: 2 additions & 2 deletions api/libs/user/src/controllers/user.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { UserService } from '../services/user.service';
import { UserController } from './user.controller';
import { UserRepository } from '../repositories/user.repository';
import { AuthRepository } from '@app/auth/repositories/auth.repository';
import { AuthService } from '@app/auth/services/auth.service';

describe('UserController', () => {
let controller: UserController;
Expand All @@ -14,7 +14,7 @@ describe('UserController', () => {
UserService,
{ provide: UserRepository, useValue: {} },
{ provide: 'UserModel', useValue: {} },
{ provide: AuthRepository, useValue: {} },
{ provide: AuthService, useValue: {} },
],
}).compile();

Expand Down

0 comments on commit 66e7e12

Please sign in to comment.