|
| 1 | +import { describe, it, expect, vi } from 'vitest'; |
| 2 | +import { getNationalAssemblySchedule } from './getNationalAssemblySchedule'; |
| 3 | +import { callOpenApi } from '../functional'; |
| 4 | +import { translatedVariableDictionary } from '../constant'; |
| 5 | + |
| 6 | +vi.mock('../functional', () => ({ |
| 7 | + callOpenApi: vi.fn(), |
| 8 | +})); |
| 9 | + |
| 10 | +describe('getNationalAssemblySchedule', () => { |
| 11 | + it('should return a list of national assembly schedules', async () => { |
| 12 | + const mockResponse = { |
| 13 | + ALLSCHEDULE: [ |
| 14 | + null, |
| 15 | + { |
| 16 | + row: [ |
| 17 | + { |
| 18 | + SCH_KIND: 'Meeting', |
| 19 | + SCH_CN: 'Committee Meeting', |
| 20 | + SCH_DT: '2023-05-01', |
| 21 | + SCH_TM: '09:00', |
| 22 | + CONF_DIV: 'Regular', |
| 23 | + CMIT_NM: 'Committee A', |
| 24 | + CONF_SESS: '1', |
| 25 | + CONF_DGR: '1', |
| 26 | + EV_INST_NM: 'National Assembly', |
| 27 | + EV_PLC: 'Room 123', |
| 28 | + }, |
| 29 | + ], |
| 30 | + }, |
| 31 | + ], |
| 32 | + }; |
| 33 | + |
| 34 | + (callOpenApi as any).mockResolvedValueOnce(mockResponse); |
| 35 | + |
| 36 | + const schedules = await getNationalAssemblySchedule({ page: 1, take: 10 }); |
| 37 | + |
| 38 | + expect(schedules).toHaveLength(1); |
| 39 | + expect(schedules[0]).toEqual({ |
| 40 | + [translatedVariableDictionary['일정_종류']]: 'Meeting', |
| 41 | + [translatedVariableDictionary['일정_내용']]: 'Committee Meeting', |
| 42 | + [translatedVariableDictionary['일정_일자']]: '2023-05-01', |
| 43 | + [translatedVariableDictionary['일정_시간']]: '09:00', |
| 44 | + [translatedVariableDictionary['회의_구분']]: 'Regular', |
| 45 | + [translatedVariableDictionary['위원회명']]: 'Committee A', |
| 46 | + [translatedVariableDictionary['회의_회기']]: '1', |
| 47 | + [translatedVariableDictionary['회의_차수']]: '1', |
| 48 | + [translatedVariableDictionary['행사_주체자']]: 'National Assembly', |
| 49 | + [translatedVariableDictionary['행사_장소']]: 'Room 123', |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should return an empty list when no schedules are found', async () => { |
| 54 | + const mockResponse = { |
| 55 | + ALLSCHEDULE: [null, { row: [] }], |
| 56 | + }; |
| 57 | + |
| 58 | + (callOpenApi as any).mockResolvedValueOnce(mockResponse); |
| 59 | + |
| 60 | + const schedules = await getNationalAssemblySchedule({ page: 1, take: 10 }); |
| 61 | + |
| 62 | + expect(schedules).toHaveLength(0); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should throw an error when callOpenApi fails', async () => { |
| 66 | + const mockError = new Error('Failed to fetch schedules'); |
| 67 | + (callOpenApi as any).mockRejectedValueOnce(mockError); |
| 68 | + |
| 69 | + await expect(getNationalAssemblySchedule({ page: 1, take: 10 })).rejects.toThrow('Failed to fetch schedules'); |
| 70 | + }); |
| 71 | +}); |
0 commit comments