params.test.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* @vitest-environment node */
  2. import { describe, it, expect } from "vitest";
  3. import {
  4. isValidBranchParam,
  5. isValidYearParam,
  6. isValidMonthParam,
  7. isValidDayParam,
  8. } from "./params.js";
  9. describe("lib/frontend/params", () => {
  10. describe("isValidBranchParam", () => {
  11. it("accepts strict NLxx codes", () => {
  12. expect(isValidBranchParam("NL01")).toBe(true);
  13. expect(isValidBranchParam("NL99")).toBe(true);
  14. });
  15. it("rejects invalid branch values", () => {
  16. expect(isValidBranchParam("FOO")).toBe(false);
  17. expect(isValidBranchParam("nl01")).toBe(false);
  18. expect(isValidBranchParam("NL1")).toBe(false);
  19. expect(isValidBranchParam("NL001")).toBe(false);
  20. expect(isValidBranchParam("")).toBe(false);
  21. expect(isValidBranchParam(null)).toBe(false);
  22. expect(isValidBranchParam(undefined)).toBe(false);
  23. });
  24. });
  25. describe("isValidYearParam", () => {
  26. it("accepts 4-digit years", () => {
  27. expect(isValidYearParam("2024")).toBe(true);
  28. expect(isValidYearParam("1999")).toBe(true);
  29. });
  30. it("rejects invalid years", () => {
  31. expect(isValidYearParam("24")).toBe(false);
  32. expect(isValidYearParam("abcd")).toBe(false);
  33. expect(isValidYearParam("20245")).toBe(false);
  34. expect(isValidYearParam("")).toBe(false);
  35. expect(isValidYearParam(null)).toBe(false);
  36. });
  37. });
  38. describe("isValidMonthParam", () => {
  39. it("accepts MM 01-12", () => {
  40. expect(isValidMonthParam("01")).toBe(true);
  41. expect(isValidMonthParam("12")).toBe(true);
  42. expect(isValidMonthParam("10")).toBe(true);
  43. });
  44. it("rejects invalid months", () => {
  45. expect(isValidMonthParam("00")).toBe(false);
  46. expect(isValidMonthParam("13")).toBe(false);
  47. expect(isValidMonthParam("1")).toBe(false);
  48. expect(isValidMonthParam("99")).toBe(false);
  49. expect(isValidMonthParam("ab")).toBe(false);
  50. expect(isValidMonthParam(null)).toBe(false);
  51. });
  52. });
  53. describe("isValidDayParam", () => {
  54. it("accepts DD 01-31", () => {
  55. expect(isValidDayParam("01")).toBe(true);
  56. expect(isValidDayParam("31")).toBe(true);
  57. expect(isValidDayParam("09")).toBe(true);
  58. });
  59. it("rejects invalid days", () => {
  60. expect(isValidDayParam("00")).toBe(false);
  61. expect(isValidDayParam("32")).toBe(false);
  62. expect(isValidDayParam("1")).toBe(false);
  63. expect(isValidDayParam("99")).toBe(false);
  64. expect(isValidDayParam("ab")).toBe(false);
  65. expect(isValidDayParam(undefined)).toBe(false);
  66. });
  67. });
  68. });