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 { AuthModule } from "../auth/auth.module";
|
||||||
import { ContentsModule } from "../contents/contents.module";
|
import { ContentsModule } from "../contents/contents.module";
|
||||||
import { RealtimeModule } from "../realtime/realtime.module";
|
import { RealtimeModule } from "../realtime/realtime.module";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenException, NotFoundException } from "@nestjs/common";
|
import { ForbiddenException, NotFoundException } from "@nestjs/common";
|
||||||
import { Test, TestingModule } from "@nestjs/testing";
|
import { Test, TestingModule } from "@nestjs/testing";
|
||||||
|
import { ContentsRepository } from "../contents/repositories/contents.repository";
|
||||||
import { EventsGateway } from "../realtime/events.gateway";
|
import { EventsGateway } from "../realtime/events.gateway";
|
||||||
import { S3Service } from "../s3/s3.service";
|
import { S3Service } from "../s3/s3.service";
|
||||||
import { CommentsService } from "./comments.service";
|
import { CommentsService } from "./comments.service";
|
||||||
@@ -25,12 +26,17 @@ describe("CommentsService", () => {
|
|||||||
isLikedByUser: jest.fn(),
|
isLikedByUser: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mockContentsRepository = {
|
||||||
|
findOne: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
const mockS3Service = {
|
const mockS3Service = {
|
||||||
getPublicUrl: jest.fn(),
|
getPublicUrl: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockEventsGateway = {
|
const mockEventsGateway = {
|
||||||
sendToContent: jest.fn(),
|
sendToContent: jest.fn(),
|
||||||
|
sendToUser: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -40,6 +46,7 @@ describe("CommentsService", () => {
|
|||||||
CommentsService,
|
CommentsService,
|
||||||
{ provide: CommentsRepository, useValue: mockCommentsRepository },
|
{ provide: CommentsRepository, useValue: mockCommentsRepository },
|
||||||
{ provide: CommentLikesRepository, useValue: mockCommentLikesRepository },
|
{ provide: CommentLikesRepository, useValue: mockCommentLikesRepository },
|
||||||
|
{ provide: ContentsRepository, useValue: mockContentsRepository },
|
||||||
{ provide: S3Service, useValue: mockS3Service },
|
{ provide: S3Service, useValue: mockS3Service },
|
||||||
{ provide: EventsGateway, useValue: mockEventsGateway },
|
{ provide: EventsGateway, useValue: mockEventsGateway },
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
|
forwardRef,
|
||||||
Inject,
|
Inject,
|
||||||
Injectable,
|
Injectable,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
forwardRef,
|
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import { ContentsRepository } from "../contents/repositories/contents.repository";
|
import { ContentsRepository } from "../contents/repositories/contents.repository";
|
||||||
import { EventsGateway } from "../realtime/events.gateway";
|
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
|
// 2. Si c'est une réponse, notifier l'auteur du commentaire parent
|
||||||
if (dto.parentId) {
|
if (dto.parentId) {
|
||||||
const parentComment = await this.commentsRepository.findOne(
|
const parentComment = await this.commentsRepository.findOne(dto.parentId);
|
||||||
dto.parentId,
|
|
||||||
);
|
|
||||||
if (
|
if (
|
||||||
parentComment &&
|
parentComment &&
|
||||||
parentComment.userId !== userId &&
|
parentComment.userId !== userId &&
|
||||||
|
|||||||
Reference in New Issue
Block a user