Skip to content

Commit

Permalink
Test: 북마크 테스트 코드 추가
Browse files Browse the repository at this point in the history
- 북마크 테스트에서 모듈 불러오기

Related to #42
  • Loading branch information
Zamoca42 committed Feb 26, 2024
1 parent 7dd63d4 commit 1eada8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
15 changes: 14 additions & 1 deletion packages/backend/src/bookmark/bookmark.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { Test, TestingModule } from '@nestjs/testing';
import { BookmarkController } from './bookmark.controller';
import { BookmarkService } from './bookmark.service';
import { AuthService } from '../auth/auth.service';

class MockBookmarkService {}
class MockAuthService {}

describe('BookmarkController', () => {
let controller: BookmarkController;
let bookmarkService: BookmarkService;
let authService: AuthService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [BookmarkController],
providers: [BookmarkService],
providers: [
{ provide: BookmarkService, useClass: MockBookmarkService },
{ provide: AuthService, useClass: MockAuthService },
],
}).compile();

bookmarkService = module.get<BookmarkService>(BookmarkService);
authService = module.get<AuthService>(AuthService);
controller = module.get<BookmarkController>(BookmarkController);
});

it('should be defined', () => {
expect(bookmarkService).toBeDefined();
expect(authService).toBeDefined();
expect(controller).toBeDefined();
});
});
2 changes: 1 addition & 1 deletion packages/backend/src/bookmark/bookmark.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { BookmarkService } from './bookmark.service';
import { BookmarkController } from './bookmark.controller';
import { AuthModule } from '../auth/auth.module';
import { PrismaModule } from '../prisma/prisma.module';
import { AuthModule } from '../auth/auth.module';

@Module({
imports: [AuthModule, PrismaModule],
Expand Down
11 changes: 10 additions & 1 deletion packages/backend/src/bookmark/bookmark.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import { Test, TestingModule } from '@nestjs/testing';
import { BookmarkService } from './bookmark.service';
import { PrismaService } from '../prisma/prisma.service';

class MockPrisma {}

describe('BookmarkService', () => {
let service: BookmarkService;
let prisma: PrismaService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [BookmarkService],
providers: [
BookmarkService,
{ provide: PrismaService, useClass: MockPrisma },
],
}).compile();

service = module.get<BookmarkService>(BookmarkService);
prisma = module.get<PrismaService>(PrismaService);
});

it('should be defined', () => {
expect(service).toBeDefined();
expect(prisma).toBeDefined();
});
});

0 comments on commit 1eada8a

Please sign in to comment.