diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index ab87514..afa9ecd 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -1,10 +1,9 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; -import { PostsModule } from './posts/posts.module'; +import { PostModule } from './post/post.module'; import { DatabaseModule } from './database/database.module'; import { ConfigModule } from '@nestjs/config'; -import { PostModule } from './post/post.module'; import configuration from './config/configuration'; @Module({ @@ -13,7 +12,6 @@ import configuration from './config/configuration'; load: [configuration] }), DatabaseModule, - PostsModule, PostModule ], controllers: [AppController], diff --git a/backend/src/comment/comment.entity.ts b/backend/src/comment/comment.entity.ts index 7c29d32..530c9a6 100644 --- a/backend/src/comment/comment.entity.ts +++ b/backend/src/comment/comment.entity.ts @@ -1,5 +1,5 @@ import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm'; -import { Post } from './post.entity'; +import { Post } from '../post/post.entity'; @Entity() export class Comment { diff --git a/backend/src/post/post.controller.spec.ts b/backend/src/post/post.controller.spec.ts index f66eb7d..a0311f2 100644 --- a/backend/src/post/post.controller.spec.ts +++ b/backend/src/post/post.controller.spec.ts @@ -1,5 +1,12 @@ import { Test, TestingModule } from '@nestjs/testing'; import { PostController } from './post.controller'; +import { PostService } from './post.service'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { Post } from './post.entity'; +import { Comment } from '../comment/comment.entity'; + +const mockPost = new Post(); +const mockComment = new Comment(); describe('PostController', () => { let controller: PostController; @@ -7,6 +14,23 @@ describe('PostController', () => { beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [PostController], + providers: [ + PostService, + { + provide: getRepositoryToken(Post), + useValue: { + save: jest.fn().mockResolvedValue(mockPost), + find: jest.fn().mockResolvedValue([mockPost]), + }, + }, + { + provide: getRepositoryToken(Comment), + useValue: { + save: jest.fn().mockResolvedValue(mockComment), + find: jest.fn().mockResolvedValue([mockComment]), + }, + }, + ], }).compile(); controller = module.get(PostController); diff --git a/backend/src/post/post.entity.spec.ts b/backend/src/post/post.entity.spec.ts index a91e8c3..a53e694 100644 --- a/backend/src/post/post.entity.spec.ts +++ b/backend/src/post/post.entity.spec.ts @@ -1,4 +1,4 @@ -import { Post } from './post'; +import { Post } from './post.entity'; describe('Post', () => { it('should be defined', () => { diff --git a/backend/src/post/post.entity.ts b/backend/src/post/post.entity.ts index c252c3b..4e91111 100644 --- a/backend/src/post/post.entity.ts +++ b/backend/src/post/post.entity.ts @@ -1,5 +1,5 @@ -import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from ‘typeorm’; -import { Comment } from ‘./comment.entity’; +import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; +import { Comment } from '../comment/comment.entity'; @Entity() export class Post { diff --git a/backend/src/post/post.service.spec.ts b/backend/src/post/post.service.spec.ts index 7769284..6e35eb2 100644 --- a/backend/src/post/post.service.spec.ts +++ b/backend/src/post/post.service.spec.ts @@ -1,12 +1,36 @@ import { Test, TestingModule } from '@nestjs/testing'; import { PostService } from './post.service'; +import { PostController } from './post.controller'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { Post } from './post.entity'; +import { Comment } from '../comment/comment.entity'; + +const mockPost = new Post(); +const mockComment = new Comment(); describe('PostService', () => { let service: PostService; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ - providers: [PostService], + controllers: [PostController], + providers: [ + PostService, + { + provide: getRepositoryToken(Post), + useValue: { + save: jest.fn().mockResolvedValue(mockPost), + find: jest.fn().mockResolvedValue([mockPost]), + }, + }, + { + provide: getRepositoryToken(Comment), + useValue: { + save: jest.fn().mockResolvedValue(mockComment), + find: jest.fn().mockResolvedValue([mockComment]), + }, + }, + ], }).compile(); service = module.get(PostService);