| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /* @vitest-environment node */
- import { describe, it, expect } from "vitest";
- import {
- isValidBranchParam,
- isValidYearParam,
- isValidMonthParam,
- isValidDayParam,
- } from "./params.js";
- describe("lib/frontend/params", () => {
- describe("isValidBranchParam", () => {
- it("accepts strict NLxx codes", () => {
- expect(isValidBranchParam("NL01")).toBe(true);
- expect(isValidBranchParam("NL99")).toBe(true);
- });
- it("rejects invalid branch values", () => {
- expect(isValidBranchParam("FOO")).toBe(false);
- expect(isValidBranchParam("nl01")).toBe(false);
- expect(isValidBranchParam("NL1")).toBe(false);
- expect(isValidBranchParam("NL001")).toBe(false);
- expect(isValidBranchParam("")).toBe(false);
- expect(isValidBranchParam(null)).toBe(false);
- expect(isValidBranchParam(undefined)).toBe(false);
- });
- });
- describe("isValidYearParam", () => {
- it("accepts 4-digit years", () => {
- expect(isValidYearParam("2024")).toBe(true);
- expect(isValidYearParam("1999")).toBe(true);
- });
- it("rejects invalid years", () => {
- expect(isValidYearParam("24")).toBe(false);
- expect(isValidYearParam("abcd")).toBe(false);
- expect(isValidYearParam("20245")).toBe(false);
- expect(isValidYearParam("")).toBe(false);
- expect(isValidYearParam(null)).toBe(false);
- });
- });
- describe("isValidMonthParam", () => {
- it("accepts MM 01-12", () => {
- expect(isValidMonthParam("01")).toBe(true);
- expect(isValidMonthParam("12")).toBe(true);
- expect(isValidMonthParam("10")).toBe(true);
- });
- it("rejects invalid months", () => {
- expect(isValidMonthParam("00")).toBe(false);
- expect(isValidMonthParam("13")).toBe(false);
- expect(isValidMonthParam("1")).toBe(false);
- expect(isValidMonthParam("99")).toBe(false);
- expect(isValidMonthParam("ab")).toBe(false);
- expect(isValidMonthParam(null)).toBe(false);
- });
- });
- describe("isValidDayParam", () => {
- it("accepts DD 01-31", () => {
- expect(isValidDayParam("01")).toBe(true);
- expect(isValidDayParam("31")).toBe(true);
- expect(isValidDayParam("09")).toBe(true);
- });
- it("rejects invalid days", () => {
- expect(isValidDayParam("00")).toBe(false);
- expect(isValidDayParam("32")).toBe(false);
- expect(isValidDayParam("1")).toBe(false);
- expect(isValidDayParam("99")).toBe(false);
- expect(isValidDayParam("ab")).toBe(false);
- expect(isValidDayParam(undefined)).toBe(false);
- });
- });
- });
|