mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 22:50:51 +00:00
The home location of the environment module was rounded to 2 decimals, about 1 km, which places a home in a neighbourhood rather than the town the schema comment promised. The weather archive it feeds is gridded at 9 to 25 km, so the extra precision bought nothing. Every stored coordinate of the module now goes through the same 1-decimal rounding (about 11 km north-south, 7 km east-west at 50° N): the home, the travel periods, the geocoder's results, the per-day weather rows, and a restore of a file written with finer values. Migration 0361 rounds the existing users, travel periods and per-day rows; running it twice changes nothing more. The answers keep their shape, plain numbers. The API descriptions and the schema comment say 1 decimal now.
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
/**
|
|
* v1.39.4 — the environment module stores coordinates at 1 decimal (about
|
|
* 11 km), not 2 (about 1 km). The geocoder is where a picked city's
|
|
* coordinates enter, so its results must already be coarse.
|
|
*/
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe("coarse location", () => {
|
|
it("rounds a coordinate to one decimal", async () => {
|
|
const { roundCoarse } = await import("../open-meteo");
|
|
expect(roundCoarse(52.5163)).toBe(52.5);
|
|
expect(roundCoarse(13.3777)).toBe(13.4);
|
|
expect(roundCoarse(-33.8688)).toBe(-33.9);
|
|
// Already coarse values pass through unchanged.
|
|
expect(roundCoarse(48.1)).toBe(48.1);
|
|
});
|
|
|
|
it("hands back geocoding results at one decimal", async () => {
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn().mockResolvedValue(
|
|
Response.json(
|
|
{
|
|
results: [
|
|
{
|
|
name: "Berlin",
|
|
latitude: 52.52437,
|
|
longitude: 13.41053,
|
|
country: "Germany",
|
|
timezone: "Europe/Berlin",
|
|
},
|
|
],
|
|
},
|
|
{ status: 200 },
|
|
),
|
|
),
|
|
);
|
|
const { geocodeLocation } = await import("../open-meteo");
|
|
const [hit] = await geocodeLocation("Berlin");
|
|
expect(hit).toMatchObject({ lat: 52.5, lon: 13.4 });
|
|
});
|
|
});
|