-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from LocalMingle/dev
[작업완료]: events, search, data 테스트 코드 작성
- Loading branch information
Showing
15 changed files
with
249 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,62 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { DataController } from './data.controller'; | ||
import { DataService } from './data.service'; | ||
import { DataController } from './data.controller'; | ||
import { PrismaModule } from 'src/prisma/prisma.module'; | ||
|
||
describe('DataController', () => { | ||
describe('CityController', () => { | ||
let controller: DataController; | ||
let dataService: DataService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [DataController], | ||
providers: [DataService], | ||
imports: [PrismaModule] | ||
}).compile(); | ||
|
||
controller = module.get<DataController>(DataController); | ||
dataService = module.get<DataService>(DataService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
describe('cityData', () => { | ||
it('should return city data for a valid language', async () => { | ||
const mockQuery = { lang: 'en' }; | ||
|
||
const mockCityData = { | ||
lang: 'en', | ||
items: [ | ||
{ doName: 'City / Province'}, | ||
{ doName: 'Seoul' }, | ||
{ doName: 'Busan' }, | ||
{ doName: 'Daegu' }, | ||
{ doName: 'Incheon' }, | ||
{ doName: 'Gwangju' }, | ||
{ doName: 'Daejeon' }, | ||
{ doName: 'Ulsan' }, | ||
{ doName: 'Sejong' }, | ||
{ doName: 'Gyeonggi-do' }, | ||
{ doName: 'Gangwon-do' }, | ||
{ doName: 'Chungcheongbuk-do' }, | ||
{ doName: 'Chungcheongnam-do' }, | ||
{ doName: 'Jeollabuk-do' }, | ||
{ doName: 'Jeollanam-do' }, | ||
{ doName: 'Gyeongsangbuk-do' }, | ||
{ doName: 'Gyeongsangnam-do' }, | ||
{ doName: 'Jeju-do' }, | ||
], | ||
} | ||
|
||
const result = await controller.cityData(mockQuery); | ||
|
||
expect(result).toEqual(mockCityData); | ||
}); | ||
|
||
it('should return an error message for an invalid language', async () => { | ||
const mockQuery = { lang: 'fr' }; | ||
|
||
const result = await controller.cityData(mockQuery); | ||
|
||
expect(result).toEqual({ message: '[ko, en, jp] 중 하나를 입력하세요' }); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { DataService } from './data.service'; | ||
|
||
describe('DataService', () => { | ||
let service: DataService; | ||
let dataService; | ||
let mockPrisma; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [DataService], | ||
}).compile(); | ||
|
||
service = module.get<DataService>(DataService); | ||
mockPrisma = { | ||
region: { | ||
findMany: jest.fn(), | ||
}, | ||
}; | ||
dataService = new DataService(mockPrisma); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
test('guNameData Method', async () => { | ||
const query = { doName: 'exampleDoName' }; | ||
await dataService.guNameData(query); | ||
|
||
expect(mockPrisma.region.findMany).toHaveBeenCalledWith({ | ||
where: { doName: query.doName }, | ||
select: { guName: true }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.