test: add weather logic test suite
All checks were successful
CI / Lint, test, typecheck and build (push) Successful in 9m58s
All checks were successful
CI / Lint, test, typecheck and build (push) Successful in 9m58s
This commit is contained in:
67
tests/warning-regions.test.ts
Normal file
67
tests/warning-regions.test.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getCountyTerytForLocation, warningMatchesCounty, warningMatchesLocalSelection } from "@/lib/warning-regions";
|
||||
import type { WeatherWarning } from "@/types/imgw";
|
||||
import type { SelectedLocation } from "@/types/location";
|
||||
|
||||
function warning(overrides: Partial<WeatherWarning> = {}): WeatherWarning {
|
||||
return {
|
||||
id: "meteo-1",
|
||||
kind: "meteo",
|
||||
level: 1,
|
||||
title: "Storm",
|
||||
description: null,
|
||||
comment: null,
|
||||
validFrom: null,
|
||||
validTo: null,
|
||||
publishedAt: null,
|
||||
probability: null,
|
||||
areas: [],
|
||||
terytCodes: [],
|
||||
provinces: ["mazowieckie"],
|
||||
office: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function location(overrides: Partial<SelectedLocation> = {}): SelectedLocation {
|
||||
return {
|
||||
name: "Warszawa",
|
||||
province: "mazowieckie",
|
||||
district: "Warszawa",
|
||||
country: "Poland",
|
||||
countryCode: "PL",
|
||||
admin1: "Mazowieckie",
|
||||
admin2: "Warszawa",
|
||||
timezone: "Europe/Warsaw",
|
||||
region: "PL",
|
||||
countyTeryt: "1465",
|
||||
latitude: 52.23,
|
||||
longitude: 21.01,
|
||||
stationId: null,
|
||||
stationName: null,
|
||||
distanceKm: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("warning region matching", () => {
|
||||
it("resolves Mazowieckie county codes from district names", () => {
|
||||
expect(getCountyTerytForLocation("mazowieckie", "Warszawa", null)).toBe("1465");
|
||||
expect(getCountyTerytForLocation("mazowieckie", "radomski", null)).toBe("1425");
|
||||
});
|
||||
|
||||
it("matches meteorological warnings by county TERYT prefix", () => {
|
||||
const warsawWarning = warning({ terytCodes: ["146501"] });
|
||||
|
||||
expect(warningMatchesCounty(warsawWarning, "1465")).toBe(true);
|
||||
expect(warningMatchesCounty(warsawWarning, "1425")).toBe(false);
|
||||
});
|
||||
|
||||
it("uses county filtering before province fallback for selected locations", () => {
|
||||
const radomWarning = warning({ terytCodes: ["142501"] });
|
||||
|
||||
expect(warningMatchesLocalSelection(radomWarning, "mazowieckie", location())).toBe(false);
|
||||
expect(warningMatchesLocalSelection(radomWarning, "mazowieckie", location({ countyTeryt: null }))).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user