Skip to content

Commit f1bf1b0

Browse files
committed
test: new schedule generator
1 parent 6da2b2c commit f1bf1b0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/lib/schedule.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, test } from "vitest";
2+
import dayjs from "dayjs";
3+
import { generate } from "./schedule.ts";
4+
5+
const LIMIT_TO_PREVENT_INIFINITE_LOOPS = 1000;
6+
7+
test("generates first date closed to the start", () => {
8+
const today = dayjs();
9+
for (const date of generate({ start: today })) {
10+
expect(today <= date).toBe(true);
11+
expect(
12+
date < today.add(3, "d"),
13+
`expect ${date.format("YYYY-MM-DD")} is less than three days later (${today.add(3, "d").format("YYYY-MM-DD")})`,
14+
).toBe(true);
15+
break;
16+
}
17+
});
18+
19+
test("generates days only on Monday, Wednesday or Friday", () => {
20+
let count = 0; // to prevent infinite loops
21+
for (const date of generate({})) {
22+
expect([1, 3, 5]).contain(date.day());
23+
if (count++ > LIMIT_TO_PREVENT_INIFINITE_LOOPS) {
24+
break;
25+
}
26+
}
27+
});

0 commit comments

Comments
 (0)