mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-07 04:12:04 +00:00
test(medications): generate BYSETPOS rules that always have an occurrence
A rule with no occurrence (BYSETPOS=2 over one weekday) makes rrule walk to its year 9999 on every call, seconds per case, which no schedule the app accepts can produce. The reviewed counterexample is a fixed case. Also formats the locale settings file.
This commit is contained in:
1 parent
1bbd2d97c7
commit
65dc9751e0
2 files changed
+15
-17
No files matched your search
@@ -1,18 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://inlang.com/schema/project-settings",
|
"$schema": "https://inlang.com/schema/project-settings",
|
||||||
"baseLocale": "en",
|
"baseLocale": "en",
|
||||||
"locales": [
|
"locales": ["en", "de", "fr", "es", "it", "pl", "ko", "nl", "pt-BR", "ru"],
|
||||||
"en",
|
|
||||||
"de",
|
|
||||||
"fr",
|
|
||||||
"es",
|
|
||||||
"it",
|
|
||||||
"pl",
|
|
||||||
"ko",
|
|
||||||
"nl",
|
|
||||||
"pt-BR",
|
|
||||||
"ru"
|
|
||||||
],
|
|
||||||
"modules": [
|
"modules": [
|
||||||
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4.5.5/dist/index.js"
|
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4.5.5/dist/index.js"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ import { describe, expect, it } from "vitest";
|
|||||||
|
|
||||||
import { alignedRruleStart } from "@/lib/medications/scheduling/aligned-rrule-start";
|
import { alignedRruleStart } from "@/lib/medications/scheduling/aligned-rrule-start";
|
||||||
|
|
||||||
import {
|
import { assertProperty } from "../../../../../tests/property/fast-check";
|
||||||
assertProperty,
|
|
||||||
propertyTimeout,
|
|
||||||
} from "../../../../../tests/property/fast-check";
|
|
||||||
|
|
||||||
const DAY_MS = 24 * 60 * 60 * 1000;
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||||
const BYDAY = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"] as const;
|
const BYDAY = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"] as const;
|
||||||
@@ -36,7 +33,7 @@ const ruleArb = fc
|
|||||||
),
|
),
|
||||||
wkst: fc.option(fc.constantFrom("MO", "SU")),
|
wkst: fc.option(fc.constantFrom("MO", "SU")),
|
||||||
count: fc.option(fc.integer({ min: 1, max: 40 })),
|
count: fc.option(fc.integer({ min: 1, max: 40 })),
|
||||||
bysetpos: fc.option(fc.constantFrom(1, 2, -1)),
|
bysetpos: fc.option(fc.constantFrom(1, -1)),
|
||||||
})
|
})
|
||||||
.map(({ freq, interval, byday, byhour, wkst, count, bysetpos }) =>
|
.map(({ freq, interval, byday, byhour, wkst, count, bysetpos }) =>
|
||||||
[
|
[
|
||||||
@@ -93,6 +90,18 @@ describe("alignedRruleStart", () => {
|
|||||||
propertyTimeout(30_000),
|
propertyTimeout(30_000),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it("keeps the anchor for BYSETPOS, which picks among a whole week", () => {
|
||||||
|
// Moving the start to a Friday left Monday out of the first week, so
|
||||||
|
// BYSETPOS=1 chose the Friday, the window's first day.
|
||||||
|
const rule = "FREQ=WEEKLY;INTERVAL=1;BYSETPOS=1;BYDAY=MO,FR";
|
||||||
|
const anchor = new Date(Date.UTC(2023, 7, 15));
|
||||||
|
const after = new Date(Date.UTC(2025, 6, 11));
|
||||||
|
const before = new Date(after.getTime() + 21 * DAY_MS);
|
||||||
|
expect(
|
||||||
|
occurrences(rule, alignedRruleStart(rule, anchor, after), after, before),
|
||||||
|
).toEqual(occurrences(rule, anchor, after, before));
|
||||||
|
});
|
||||||
|
|
||||||
it("moves a daily or weekly start close to the window", () => {
|
it("moves a daily or weekly start close to the window", () => {
|
||||||
const anchor = new Date(Date.UTC(2024, 5, 1));
|
const anchor = new Date(Date.UTC(2024, 5, 1));
|
||||||
const after = new Date(Date.UTC(2026, 2, 1));
|
const after = new Date(Date.UTC(2026, 2, 1));
|
||||||
|
|||||||
Reference in new issue
Block a user