feat(planning): ship holiday-aware planning and assistant upgrades
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { buildHolidayCalendarSeedDefinitions } from "./holiday-calendar-seed-data.js";
|
||||
|
||||
function getDefinition(
|
||||
definitions: ReturnType<typeof buildHolidayCalendarSeedDefinitions>,
|
||||
predicate: (definition: ReturnType<typeof buildHolidayCalendarSeedDefinitions>[number]) => boolean,
|
||||
) {
|
||||
const definition = definitions.find(predicate);
|
||||
assert.ok(definition, "expected holiday seed definition to exist");
|
||||
return definition;
|
||||
}
|
||||
|
||||
test("builds country, state, and city holiday seeds for available profiles", () => {
|
||||
const definitions = buildHolidayCalendarSeedDefinitions({
|
||||
availableCountryCodes: ["DE", "ES", "IN", "US"],
|
||||
availableCitiesByCountry: {
|
||||
DE: ["Augsburg", "Berlin", "Hamburg", "Muenchen", "Stuttgart"],
|
||||
ES: ["Barcelona", "Madrid"],
|
||||
IN: ["Bangalore", "Mumbai"],
|
||||
US: ["Los Angeles", "New York"],
|
||||
},
|
||||
activeGermanStates: ["BW", "BY", "HH"],
|
||||
years: [2026, 2027],
|
||||
});
|
||||
|
||||
const byCalendar = getDefinition(
|
||||
definitions,
|
||||
(definition) => definition.scopeType === "STATE" && definition.countryCode === "DE" && definition.stateCode === "BY",
|
||||
);
|
||||
const nwCalendar = getDefinition(
|
||||
definitions,
|
||||
(definition) => definition.scopeType === "STATE" && definition.countryCode === "DE" && definition.stateCode === "NW",
|
||||
);
|
||||
const madridCalendar = getDefinition(
|
||||
definitions,
|
||||
(definition) => definition.scopeType === "CITY" && definition.countryCode === "ES" && definition.cityName === "Madrid",
|
||||
);
|
||||
const augsburgCalendar = getDefinition(
|
||||
definitions,
|
||||
(definition) => definition.scopeType === "CITY" && definition.countryCode === "DE" && definition.cityName === "Augsburg",
|
||||
);
|
||||
const usCalendar = getDefinition(
|
||||
definitions,
|
||||
(definition) => definition.scopeType === "COUNTRY" && definition.countryCode === "US",
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
byCalendar.entries.some((entry) => entry.date === "2026-01-06" && entry.name === "Heilige Drei Könige"),
|
||||
);
|
||||
assert.ok(
|
||||
byCalendar.entries.some((entry) => entry.date === "2027-08-15" && entry.name === "Mariä Himmelfahrt"),
|
||||
);
|
||||
assert.ok(
|
||||
nwCalendar.entries.some((entry) => entry.date === "2026-06-04" && entry.name === "Fronleichnam"),
|
||||
);
|
||||
assert.ok(
|
||||
!nwCalendar.entries.some((entry) => entry.date === "2026-01-06"),
|
||||
);
|
||||
assert.ok(
|
||||
madridCalendar.entries.some((entry) => entry.date === "2026-05-15" && entry.name === "San Isidro"),
|
||||
);
|
||||
assert.ok(
|
||||
augsburgCalendar.entries.some((entry) => entry.date === "2027-08-08" && entry.name === "Augsburger Friedensfest"),
|
||||
);
|
||||
assert.ok(
|
||||
usCalendar.entries.some((entry) => entry.date === "2026-07-03" && entry.name === "Independence Day"),
|
||||
);
|
||||
assert.ok(
|
||||
usCalendar.entries.some((entry) => entry.date === "2027-12-24" && entry.name === "Christmas Day"),
|
||||
);
|
||||
});
|
||||
|
||||
test("only includes city calendars for cities that exist in the database", () => {
|
||||
const definitions = buildHolidayCalendarSeedDefinitions({
|
||||
availableCountryCodes: ["DE", "ES"],
|
||||
availableCitiesByCountry: {
|
||||
DE: ["Berlin"],
|
||||
ES: ["Madrid"],
|
||||
},
|
||||
activeGermanStates: ["BY"],
|
||||
years: [2026, 2027],
|
||||
});
|
||||
|
||||
assert.ok(definitions.some((definition) => definition.countryCode === "DE" && definition.scopeType === "STATE"));
|
||||
assert.ok(definitions.some((definition) => definition.countryCode === "ES" && definition.scopeType === "CITY" && definition.cityName === "Madrid"));
|
||||
assert.ok(!definitions.some((definition) => definition.countryCode === "ES" && definition.scopeType === "CITY" && definition.cityName === "Barcelona"));
|
||||
assert.ok(!definitions.some((definition) => definition.countryCode === "US"));
|
||||
});
|
||||
Reference in New Issue
Block a user