const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const { fetchWeatherLocationForecast } = require('../src/data/weather'); test('Open-Meteo hourly forecast starts at the current hour and spans 24 hours', async () => { const originalFetch = global.fetch; const originalDateNow = Date.now; let requestUrl; global.fetch = async function (url) { requestUrl = new URL(url); return { ok: true, json: async function () { return { hourly: { time: [] } }; } }; }; Date.now = function () { return new Date('2026-08-28T12:34:00Z').getTime(); }; try { await fetchWeatherLocationForecast({ query: async function () { return [[]]; } }, { latitude: 51.5, longitude: -0.1, timezone: 'Europe/London', provider: 'open-meteo' }); } finally { global.fetch = originalFetch; Date.now = originalDateNow; } assert.equal(requestUrl.searchParams.get('forecast_hours'), '24'); assert.equal(requestUrl.searchParams.get('forecast_days'), '7'); }); test('weather forecast preview only shows the fetch hint without a snapshot', () => { const template = fs.readFileSync(path.join(__dirname, '..', 'src', 'web', 'views', 'data-sources', 'weather', 'forecast-preview.hbs'), 'utf8'); assert.match(template, /\{\{#if weatherPreview\.hasSnapshot\}\}[\s\S]*weather-daily-forecast[\s\S]*weather-hourly-forecast[\s\S]*\{\{\/if\}\}/); assert.match(template, /Daily and hourly forecasts will appear here after the first successful fetch\./); });