From 7c065a2fb934bfe1cfdf2a88149988fde5ff78a2 Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:49:13 +0100 Subject: [PATCH] feat: inject `ContentsRepository` into `CommentsService` for better integration - Added `ContentsRepository` as a dependency to `CommentsService` and updated tests for mock setup. - Adjusted import order in relevant files to align with project standards. --- backend/src/comments/comments.module.ts | 2 +- backend/src/comments/comments.service.spec.ts | 7 +++++++ backend/src/comments/comments.service.ts | 6 ++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/src/comments/comments.module.ts b/backend/src/comments/comments.module.ts index 5a76d47..249802c 100644 --- a/backend/src/comments/comments.module.ts +++ b/backend/src/comments/comments.module.ts @@ -1,4 +1,4 @@ -import { Module, forwardRef } from "@nestjs/common"; +import { forwardRef, Module } from "@nestjs/common"; import { AuthModule } from "../auth/auth.module"; import { ContentsModule } from "../contents/contents.module"; import { RealtimeModule } from "../realtime/realtime.module"; diff --git a/backend/src/comments/comments.service.spec.ts b/backend/src/comments/comments.service.spec.ts index 7c9b3a6..b277070 100644 --- a/backend/src/comments/comments.service.spec.ts +++ b/backend/src/comments/comments.service.spec.ts @@ -1,5 +1,6 @@ import { ForbiddenException, NotFoundException } from "@nestjs/common"; import { Test, TestingModule } from "@nestjs/testing"; +import { ContentsRepository } from "../contents/repositories/contents.repository"; import { EventsGateway } from "../realtime/events.gateway"; import { S3Service } from "../s3/s3.service"; import { CommentsService } from "./comments.service"; @@ -25,12 +26,17 @@ describe("CommentsService", () => { isLikedByUser: jest.fn(), }; + const mockContentsRepository = { + findOne: jest.fn(), + }; + const mockS3Service = { getPublicUrl: jest.fn(), }; const mockEventsGateway = { sendToContent: jest.fn(), + sendToUser: jest.fn(), }; beforeEach(async () => { @@ -40,6 +46,7 @@ describe("CommentsService", () => { CommentsService, { provide: CommentsRepository, useValue: mockCommentsRepository }, { provide: CommentLikesRepository, useValue: mockCommentLikesRepository }, + { provide: ContentsRepository, useValue: mockContentsRepository }, { provide: S3Service, useValue: mockS3Service }, { provide: EventsGateway, useValue: mockEventsGateway }, ], diff --git a/backend/src/comments/comments.service.ts b/backend/src/comments/comments.service.ts index 3a65e90..df7c91e 100644 --- a/backend/src/comments/comments.service.ts +++ b/backend/src/comments/comments.service.ts @@ -1,9 +1,9 @@ import { ForbiddenException, + forwardRef, Inject, Injectable, NotFoundException, - forwardRef, } from "@nestjs/common"; import { ContentsRepository } from "../contents/repositories/contents.repository"; import { EventsGateway } from "../realtime/events.gateway"; @@ -54,9 +54,7 @@ export class CommentsService { // 2. Si c'est une réponse, notifier l'auteur du commentaire parent if (dto.parentId) { - const parentComment = await this.commentsRepository.findOne( - dto.parentId, - ); + const parentComment = await this.commentsRepository.findOne(dto.parentId); if ( parentComment && parentComment.userId !== userId &&