| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- /**
- * System Settings Quota Lease Validation Tests
- *
- * TDD: RED phase - tests for quota lease settings fields
- */
- import { describe, expect, test } from "vitest";
- import { UpdateSystemSettingsSchema } from "@/lib/validation/schemas";
- describe("UpdateSystemSettingsSchema: quota lease settings", () => {
- describe("quotaDbRefreshIntervalSeconds", () => {
- test("accepts valid refresh interval (10)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaDbRefreshIntervalSeconds: 10,
- });
- expect(parsed.quotaDbRefreshIntervalSeconds).toBe(10);
- });
- test("accepts minimum value (1)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaDbRefreshIntervalSeconds: 1,
- });
- expect(parsed.quotaDbRefreshIntervalSeconds).toBe(1);
- });
- test("accepts maximum value (300)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaDbRefreshIntervalSeconds: 300,
- });
- expect(parsed.quotaDbRefreshIntervalSeconds).toBe(300);
- });
- test("rejects value below minimum (0)", () => {
- expect(() =>
- UpdateSystemSettingsSchema.parse({
- quotaDbRefreshIntervalSeconds: 0,
- })
- ).toThrow();
- });
- test("rejects value above maximum (301)", () => {
- expect(() =>
- UpdateSystemSettingsSchema.parse({
- quotaDbRefreshIntervalSeconds: 301,
- })
- ).toThrow();
- });
- test("rejects non-integer value", () => {
- expect(() =>
- UpdateSystemSettingsSchema.parse({
- quotaDbRefreshIntervalSeconds: 10.5,
- })
- ).toThrow();
- });
- });
- describe("quotaLeasePercent5h", () => {
- test("accepts valid percent (0.05)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeasePercent5h: 0.05,
- });
- expect(parsed.quotaLeasePercent5h).toBe(0.05);
- });
- test("accepts minimum value (0)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeasePercent5h: 0,
- });
- expect(parsed.quotaLeasePercent5h).toBe(0);
- });
- test("accepts maximum value (1)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeasePercent5h: 1,
- });
- expect(parsed.quotaLeasePercent5h).toBe(1);
- });
- test("rejects value below minimum (-0.01)", () => {
- expect(() =>
- UpdateSystemSettingsSchema.parse({
- quotaLeasePercent5h: -0.01,
- })
- ).toThrow();
- });
- test("rejects value above maximum (1.01)", () => {
- expect(() =>
- UpdateSystemSettingsSchema.parse({
- quotaLeasePercent5h: 1.01,
- })
- ).toThrow();
- });
- });
- describe("quotaLeasePercentDaily", () => {
- test("accepts valid percent (0.05)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeasePercentDaily: 0.05,
- });
- expect(parsed.quotaLeasePercentDaily).toBe(0.05);
- });
- test("accepts edge values (0 and 1)", () => {
- expect(
- UpdateSystemSettingsSchema.parse({ quotaLeasePercentDaily: 0 }).quotaLeasePercentDaily
- ).toBe(0);
- expect(
- UpdateSystemSettingsSchema.parse({ quotaLeasePercentDaily: 1 }).quotaLeasePercentDaily
- ).toBe(1);
- });
- test("rejects out of range values", () => {
- expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentDaily: -0.01 })).toThrow();
- expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentDaily: 1.01 })).toThrow();
- });
- });
- describe("quotaLeasePercentWeekly", () => {
- test("accepts valid percent (0.02)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeasePercentWeekly: 0.02,
- });
- expect(parsed.quotaLeasePercentWeekly).toBe(0.02);
- });
- test("accepts edge values (0 and 1)", () => {
- expect(
- UpdateSystemSettingsSchema.parse({ quotaLeasePercentWeekly: 0 }).quotaLeasePercentWeekly
- ).toBe(0);
- expect(
- UpdateSystemSettingsSchema.parse({ quotaLeasePercentWeekly: 1 }).quotaLeasePercentWeekly
- ).toBe(1);
- });
- test("rejects out of range values", () => {
- expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentWeekly: -0.01 })).toThrow();
- expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentWeekly: 1.01 })).toThrow();
- });
- });
- describe("quotaLeasePercentMonthly", () => {
- test("accepts valid percent (0.01)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeasePercentMonthly: 0.01,
- });
- expect(parsed.quotaLeasePercentMonthly).toBe(0.01);
- });
- test("accepts edge values (0 and 1)", () => {
- expect(
- UpdateSystemSettingsSchema.parse({ quotaLeasePercentMonthly: 0 }).quotaLeasePercentMonthly
- ).toBe(0);
- expect(
- UpdateSystemSettingsSchema.parse({ quotaLeasePercentMonthly: 1 }).quotaLeasePercentMonthly
- ).toBe(1);
- });
- test("rejects out of range values", () => {
- expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentMonthly: -0.01 })).toThrow();
- expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentMonthly: 1.01 })).toThrow();
- });
- });
- describe("quotaLeaseCapUsd", () => {
- test("accepts valid cap (3.0)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeaseCapUsd: 3.0,
- });
- expect(parsed.quotaLeaseCapUsd).toBe(3.0);
- });
- test("accepts null (no cap)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeaseCapUsd: null,
- });
- expect(parsed.quotaLeaseCapUsd).toBeNull();
- });
- test("accepts zero (disabled)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeaseCapUsd: 0,
- });
- expect(parsed.quotaLeaseCapUsd).toBe(0);
- });
- test("accepts high value (1000)", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaLeaseCapUsd: 1000,
- });
- expect(parsed.quotaLeaseCapUsd).toBe(1000);
- });
- test("rejects negative value", () => {
- expect(() =>
- UpdateSystemSettingsSchema.parse({
- quotaLeaseCapUsd: -1,
- })
- ).toThrow();
- });
- });
- describe("combined fields", () => {
- test("accepts all quota lease fields together", () => {
- const parsed = UpdateSystemSettingsSchema.parse({
- quotaDbRefreshIntervalSeconds: 60,
- quotaLeasePercent5h: 0.1,
- quotaLeasePercentDaily: 0.05,
- quotaLeasePercentWeekly: 0.02,
- quotaLeasePercentMonthly: 0.01,
- quotaLeaseCapUsd: 3.0,
- });
- expect(parsed.quotaDbRefreshIntervalSeconds).toBe(60);
- expect(parsed.quotaLeasePercent5h).toBe(0.1);
- expect(parsed.quotaLeasePercentDaily).toBe(0.05);
- expect(parsed.quotaLeasePercentWeekly).toBe(0.02);
- expect(parsed.quotaLeasePercentMonthly).toBe(0.01);
- expect(parsed.quotaLeaseCapUsd).toBe(3.0);
- });
- test("all fields are optional", () => {
- const parsed = UpdateSystemSettingsSchema.parse({});
- expect(parsed.quotaDbRefreshIntervalSeconds).toBeUndefined();
- expect(parsed.quotaLeasePercent5h).toBeUndefined();
- expect(parsed.quotaLeasePercentDaily).toBeUndefined();
- expect(parsed.quotaLeasePercentWeekly).toBeUndefined();
- expect(parsed.quotaLeasePercentMonthly).toBeUndefined();
- expect(parsed.quotaLeaseCapUsd).toBeUndefined();
- });
- });
- });
|