Files
miti99bot/tests/modules/loldle/daily.test.js
T
dependabot[bot] 6de35d3e4f chore(deps): bump vite and vitest (#1)
* build(deps): bump vite and vitest

Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) to 8.0.8 and updates ancestor dependency [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest). These dependencies need to be updated together.


Updates `vite` from 5.4.21 to 8.0.8
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v8.0.8/packages/vite)

Updates `vitest` from 2.1.9 to 4.1.4
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v4.1.4/packages/vitest)

---
updated-dependencies:
- dependency-name: vite
  dependency-version: 8.0.8
  dependency-type: indirect
- dependency-name: vitest
  dependency-version: 4.1.4
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

* feat(loldle): share game state per-chat in groups

Groups and supergroups now share one daily puzzle + one stats counter
across all members. Private chats remain per-user.

- state.js: renamed key arg from userId to subject (user|chat id)
- handlers.js: getSubject(ctx) picks user id in DM, chat id in groups
- /loldle_stats labels scope as "your" vs "group" accordingly

* feat(loldle): add /loldle_new + switch to self-paced rounds

- /loldle_new starts a new random round. If the previous round is not
  solved/given-up, it's recorded as a loss (auto-giveup) before rerolling.
- Drop daily-seeded targets: each round picks a uniformly-random champion
  (pickRandom in daily.js; pickDaily kept for future use).
- state.js: one active round per subject (no date in key). TTL raised to
  7 days; streak = consecutive wins (round-based, not date-based).
- Register /loldle_new in module index; now 8 public loldle commands.
- Tests: add pickRandom cases; bump expected command count to 12.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: tiennm99 <tiennm99@outlook.com>
2026-04-20 17:55:40 +07:00

41 lines
1.4 KiB
JavaScript

import { describe, expect, it } from "vitest";
import { pickDaily, pickRandom, todayUtc } from "../../../src/modules/loldle/daily.js";
describe("picker", () => {
it("todayUtc returns YYYY-MM-DD", () => {
expect(todayUtc(new Date("2026-04-20T23:30:00Z"))).toBe("2026-04-20");
expect(todayUtc(new Date("2026-01-01T00:00:00Z"))).toBe("2026-01-01");
});
it("pickDaily is deterministic for same seed", () => {
const champions = [{ id: "A" }, { id: "B" }, { id: "C" }, { id: "D" }];
const a = pickDaily(champions, "2026-04-20");
const b = pickDaily(champions, "2026-04-20");
expect(a).toBe(b);
});
it("pickDaily produces different picks over time", () => {
const champions = Array.from({ length: 100 }, (_, i) => ({ id: `C${i}` }));
const picks = new Set();
for (let d = 1; d <= 30; d++) {
picks.add(pickDaily(champions, `2026-04-${String(d).padStart(2, "0")}`).id);
}
expect(picks.size).toBeGreaterThan(5);
});
it("pickDaily throws on empty list", () => {
expect(() => pickDaily([], "x")).toThrow();
});
it("pickRandom honors injected rng", () => {
const champions = [{ id: "A" }, { id: "B" }, { id: "C" }, { id: "D" }];
expect(pickRandom(champions, () => 0).id).toBe("A");
expect(pickRandom(champions, () => 0.999).id).toBe("D");
expect(pickRandom(champions, () => 0.5).id).toBe("C");
});
it("pickRandom throws on empty list", () => {
expect(() => pickRandom([])).toThrow();
});
});