@@ -50,56 +50,33 @@ describe('fetchForecast', () => {
5050 jest . clearAllMocks ( ) ;
5151 } ) ;
5252
53- it ( 'fetches from OpenMeteo' , async ( ) => {
53+ it ( 'fetches from OpenMeteo with default hour offset ' , async ( ) => {
5454 const mockWinds = new Winds ( [ new WindRow ( 0 , 90 , 10 ) ] ) ;
5555 ( fetchOpenMeteo as jest . Mock ) . mockResolvedValue ( mockWinds ) ;
5656
57- const result = await fetchForecast ( mockCenter , undefined ) ;
57+ const result = await fetchForecast ( mockCenter ) ;
5858
5959 expect ( fetchOpenMeteo ) . toHaveBeenCalledWith ( mockCenter , 0 , undefined ) ;
6060 expect ( result ) . toBe ( mockWinds ) ;
6161 } ) ;
6262
63- it ( 'fetches ground wind when fetchDzGroundWind is provided' , async ( ) => {
64- const mockWinds = new Winds ( [ new WindRow ( 0 , 90 , 10 ) , new WindRow ( 1000 , 180 , 20 ) ] ) ;
65- const mockGroundWind = new WindRow ( 0 , 270 , 5 ) ;
66- const mockFetchGroundWind = jest . fn ( ) . mockResolvedValue ( mockGroundWind ) ;
67-
68- ( fetchOpenMeteo as jest . Mock ) . mockResolvedValue ( mockWinds ) ;
69-
70- const result = await fetchForecast ( mockCenter , mockFetchGroundWind ) ;
71-
72- expect ( mockFetchGroundWind ) . toHaveBeenCalled ( ) ;
73- expect ( result . winds [ 0 ] . direction ) . toBe ( 270 ) ;
74- expect ( result . winds [ 0 ] . speedKts ) . toBe ( 5 ) ;
75- expect ( result . groundSource ) . toBe ( SOURCE_DZ ) ;
76- } ) ;
77-
78- it ( 'continues without ground wind if fetch fails' , async ( ) => {
63+ it ( 'passes hour offset to OpenMeteo' , async ( ) => {
7964 const mockWinds = new Winds ( [ new WindRow ( 0 , 90 , 10 ) ] ) ;
80- const mockFetchGroundWind = jest . fn ( ) . mockRejectedValue ( new Error ( 'Network error' ) ) ;
81-
8265 ( fetchOpenMeteo as jest . Mock ) . mockResolvedValue ( mockWinds ) ;
8366
84- // Spy on console.log to verify error is logged
85- const consoleSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { /* noop */ } ) ;
86-
87- const result = await fetchForecast ( mockCenter , mockFetchGroundWind ) ;
67+ const result = await fetchForecast ( mockCenter , 6 ) ;
8868
69+ expect ( fetchOpenMeteo ) . toHaveBeenCalledWith ( mockCenter , 6 , undefined ) ;
8970 expect ( result ) . toBe ( mockWinds ) ;
90- expect ( consoleSpy ) . toHaveBeenCalledWith ( 'Failed to fetch DZ winds, continue without.' ) ;
91-
92- consoleSpy . mockRestore ( ) ;
9371 } ) ;
9472
95- it ( 'does not set ground source when ground wind fetch returns null ' , async ( ) => {
73+ it ( 'passes abort signal to OpenMeteo ' , async ( ) => {
9674 const mockWinds = new Winds ( [ new WindRow ( 0 , 90 , 10 ) ] ) ;
97- const mockFetchGroundWind = jest . fn ( ) . mockResolvedValue ( null ) ;
98-
75+ const controller = new AbortController ( ) ;
9976 ( fetchOpenMeteo as jest . Mock ) . mockResolvedValue ( mockWinds ) ;
10077
101- const result = await fetchForecast ( mockCenter , mockFetchGroundWind ) ;
78+ await fetchForecast ( mockCenter , 0 , controller . signal ) ;
10279
103- expect ( result . groundSource ) . toBe ( SOURCE_MANUAL ) ;
80+ expect ( fetchOpenMeteo ) . toHaveBeenCalledWith ( mockCenter , 0 , controller . signal ) ;
10481 } ) ;
10582} ) ;
0 commit comments