|
| 1 | +import { afterEach, describe, expect, it, vi } from 'vitest'; |
| 2 | +import { EventLevels } from '@/modules/events/domain/event.enums'; |
| 3 | +import { LandslideForecastSource } from './landslide-forecast.source'; |
| 4 | + |
| 5 | +describe('LandslideForecastSource', () => { |
| 6 | + afterEach(() => { |
| 7 | + vi.useRealTimers(); |
| 8 | + vi.unstubAllGlobals(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should parse forecast table and emit issued alerts only', async () => { |
| 12 | + vi.useFakeTimers(); |
| 13 | + vi.setSystemTime(new Date('2025-10-25T06:30:00.000Z')); |
| 14 | + |
| 15 | + const html = ` |
| 16 | + <table id="fctTbl"> |
| 17 | + <tbody> |
| 18 | + <tr> |
| 19 | + <td> |
| 20 | + <a href="javascript:fn_moveAlertView('47940', '', '12310');">경상북도 울릉군</a> |
| 21 | + </td> |
| 22 | + <td> |
| 23 | + <a href="javascript:fn_moveAlertView('47940','','12310');" title="주의보">주의보</a> |
| 24 | + </td> |
| 25 | + <td> |
| 26 | + <a href="javascript:fn_moveAlertView('47940','','12310');" title="2025-10-25 13:19">2025-10-25<br>13:19</a> |
| 27 | + </td> |
| 28 | + <td> |
| 29 | + <a href="javascript:fn_moveAlertView('47940','','12310');" title="2025-10-25 14:10">2025-10-25<br>14:10</a> |
| 30 | + </td> |
| 31 | + <td> |
| 32 | + <a href="javascript:fn_moveAlertView('47940','','12310');" title="-">-</a> |
| 33 | + </td> |
| 34 | + <td> |
| 35 | + <a href="javascript:fn_moveAlertView('47940','','12310');" title="작성자">작성자</a> |
| 36 | + </td> |
| 37 | + <td>발령</td> |
| 38 | + </tr> |
| 39 | + <tr> |
| 40 | + <td> |
| 41 | + <a href="javascript:fn_moveAlertView('11110', '', '99999');">서울특별시 종로구</a> |
| 42 | + </td> |
| 43 | + <td> |
| 44 | + <a href="javascript:fn_moveAlertView('11110','','99999');" title="경보">경보</a> |
| 45 | + </td> |
| 46 | + <td> |
| 47 | + <a href="javascript:fn_moveAlertView('11110','','99999');" title="2025-10-25 11:00">2025-10-25<br>11:00</a> |
| 48 | + </td> |
| 49 | + <td> |
| 50 | + <a href="javascript:fn_moveAlertView('11110','','99999');" title="2025-10-25 11:10">2025-10-25<br>11:10</a> |
| 51 | + </td> |
| 52 | + <td> |
| 53 | + <a href="javascript:fn_moveAlertView('11110','','99999');" title="2025-10-25 12:00">2025-10-25<br>12:00</a> |
| 54 | + </td> |
| 55 | + <td> |
| 56 | + <a href="javascript:fn_moveAlertView('11110','','99999');" title="작성자">작성자</a> |
| 57 | + </td> |
| 58 | + <td>해제</td> |
| 59 | + </tr> |
| 60 | + </tbody> |
| 61 | + </table> |
| 62 | + `; |
| 63 | + |
| 64 | + const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(new Response(html, { status: 200 }))); |
| 65 | + vi.stubGlobal('fetch', fetchMock); |
| 66 | + |
| 67 | + const source = new LandslideForecastSource(); |
| 68 | + const result = await source.run(null); |
| 69 | + |
| 70 | + expect(result.events).toHaveLength(1); |
| 71 | + expect(result.events[0].title).toBe('경상북도 울릉군 산사태 주의보 발령'); |
| 72 | + expect(result.events[0].level).toBe(EventLevels.Minor); |
| 73 | + expect(result.events[0].regionCodes).toEqual(['4794000000']); |
| 74 | + expect(result.events[0].occurredAt).toBe('2025-10-25T04:19:00.000Z'); |
| 75 | + }); |
| 76 | +}); |
0 commit comments