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.
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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 },
|
||||
],
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user