Skip to content

Commit 5ec13c2

Browse files
bgrozevclaude
andcommitted
Update forecast tests to match current fetchForecast signature
The old tests covered a fetchDzGroundWind callback that was removed when ground wind injection was moved to useObservedWind/App.tsx. Replaced with tests for the current API: default hour offset, custom offset, abort signal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 61d815c commit 5ec13c2

1 file changed

Lines changed: 9 additions & 32 deletions

File tree

src/forecast/forecast.test.ts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)