From 41d1dd79fe5604c4bf413e5d1744b184256cdbbd Mon Sep 17 00:00:00 2001 From: blaxsior Date: Fri, 3 Nov 2023 22:23:04 +0900 Subject: [PATCH] =?UTF-8?q?test:=20search=20controller=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/search/search.controller.spec.ts | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/backend/server/src/search/search.controller.spec.ts b/backend/server/src/search/search.controller.spec.ts index 6d6bad5..8725b6e 100644 --- a/backend/server/src/search/search.controller.spec.ts +++ b/backend/server/src/search/search.controller.spec.ts @@ -1,18 +1,79 @@ import { Test, TestingModule } from '@nestjs/testing'; import { SearchController } from './search.controller'; +import { SearchService } from './search.service'; +import { PopularKeywordsReqQueryDto } from './dtos/popular-keyword.dto'; +import { Keyword } from '../keyword/keyword.entity'; + +jest.mock('./search.service'); describe('SearchController', () => { let controller: SearchController; + let service: SearchService; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [SearchController], + providers: [SearchService], }).compile(); controller = module.get(SearchController); + service = module.get(SearchService); }); it('should be defined', () => { expect(controller).toBeDefined(); }); + + describe('getPopularKeywords()', () => { + it('should return {id, description, name}[]', async () => { + const dummy_query: PopularKeywordsReqQueryDto = { + count: 1, + }; + const expected = [{ id: 0, description: 'test', name: 'test' }]; + + jest + .spyOn(service, 'getManyPopularKeywords') + .mockImplementationOnce(() => { + return Promise.resolve([ + { + id: 0, + name: 'test', + createdAt: new Date(), + deletedAt: new Date(), + updatedAt: new Date(), + isActive: true, + description: 'test', + }, + ]); + }); + + const result = await controller.getPopularKeywords(dummy_query); + expect(service.getManyPopularKeywords).toBeCalled(); + expect(result).toEqual(expected); + }); + }); + + describe('getKeywordWithTopComments()', () => { + it('should call service.getKeywordWithTopCommentsForEmotion', async () => { + const dummy_input = { + name: 'test', + from: '0000-00-00', + to: '0000-00-00', + }; + + await controller.getKeywordWithTopComments(dummy_input); + + expect(service.getKeywordWithTopCommentsForEmotion).toBeCalled(); + }); + }); + + describe('getKeywordWithTopComments()', () => { + it('should call service.getCommentWithSentences', async () => { + const dummy_id = 0; + + await controller.getCommentWithSentences(dummy_id); + + expect(service.getCommentWithSentences).toBeCalled(); + }); + }); });