system-settings-quota-lease.test.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /**
  2. * System Settings Quota Lease Validation Tests
  3. *
  4. * TDD: RED phase - tests for quota lease settings fields
  5. */
  6. import { describe, expect, test } from "vitest";
  7. import { UpdateSystemSettingsSchema } from "@/lib/validation/schemas";
  8. describe("UpdateSystemSettingsSchema: quota lease settings", () => {
  9. describe("quotaDbRefreshIntervalSeconds", () => {
  10. test("accepts valid refresh interval (10)", () => {
  11. const parsed = UpdateSystemSettingsSchema.parse({
  12. quotaDbRefreshIntervalSeconds: 10,
  13. });
  14. expect(parsed.quotaDbRefreshIntervalSeconds).toBe(10);
  15. });
  16. test("accepts minimum value (1)", () => {
  17. const parsed = UpdateSystemSettingsSchema.parse({
  18. quotaDbRefreshIntervalSeconds: 1,
  19. });
  20. expect(parsed.quotaDbRefreshIntervalSeconds).toBe(1);
  21. });
  22. test("accepts maximum value (300)", () => {
  23. const parsed = UpdateSystemSettingsSchema.parse({
  24. quotaDbRefreshIntervalSeconds: 300,
  25. });
  26. expect(parsed.quotaDbRefreshIntervalSeconds).toBe(300);
  27. });
  28. test("rejects value below minimum (0)", () => {
  29. expect(() =>
  30. UpdateSystemSettingsSchema.parse({
  31. quotaDbRefreshIntervalSeconds: 0,
  32. })
  33. ).toThrow();
  34. });
  35. test("rejects value above maximum (301)", () => {
  36. expect(() =>
  37. UpdateSystemSettingsSchema.parse({
  38. quotaDbRefreshIntervalSeconds: 301,
  39. })
  40. ).toThrow();
  41. });
  42. test("rejects non-integer value", () => {
  43. expect(() =>
  44. UpdateSystemSettingsSchema.parse({
  45. quotaDbRefreshIntervalSeconds: 10.5,
  46. })
  47. ).toThrow();
  48. });
  49. });
  50. describe("quotaLeasePercent5h", () => {
  51. test("accepts valid percent (0.05)", () => {
  52. const parsed = UpdateSystemSettingsSchema.parse({
  53. quotaLeasePercent5h: 0.05,
  54. });
  55. expect(parsed.quotaLeasePercent5h).toBe(0.05);
  56. });
  57. test("accepts minimum value (0)", () => {
  58. const parsed = UpdateSystemSettingsSchema.parse({
  59. quotaLeasePercent5h: 0,
  60. });
  61. expect(parsed.quotaLeasePercent5h).toBe(0);
  62. });
  63. test("accepts maximum value (1)", () => {
  64. const parsed = UpdateSystemSettingsSchema.parse({
  65. quotaLeasePercent5h: 1,
  66. });
  67. expect(parsed.quotaLeasePercent5h).toBe(1);
  68. });
  69. test("rejects value below minimum (-0.01)", () => {
  70. expect(() =>
  71. UpdateSystemSettingsSchema.parse({
  72. quotaLeasePercent5h: -0.01,
  73. })
  74. ).toThrow();
  75. });
  76. test("rejects value above maximum (1.01)", () => {
  77. expect(() =>
  78. UpdateSystemSettingsSchema.parse({
  79. quotaLeasePercent5h: 1.01,
  80. })
  81. ).toThrow();
  82. });
  83. });
  84. describe("quotaLeasePercentDaily", () => {
  85. test("accepts valid percent (0.05)", () => {
  86. const parsed = UpdateSystemSettingsSchema.parse({
  87. quotaLeasePercentDaily: 0.05,
  88. });
  89. expect(parsed.quotaLeasePercentDaily).toBe(0.05);
  90. });
  91. test("accepts edge values (0 and 1)", () => {
  92. expect(
  93. UpdateSystemSettingsSchema.parse({ quotaLeasePercentDaily: 0 }).quotaLeasePercentDaily
  94. ).toBe(0);
  95. expect(
  96. UpdateSystemSettingsSchema.parse({ quotaLeasePercentDaily: 1 }).quotaLeasePercentDaily
  97. ).toBe(1);
  98. });
  99. test("rejects out of range values", () => {
  100. expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentDaily: -0.01 })).toThrow();
  101. expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentDaily: 1.01 })).toThrow();
  102. });
  103. });
  104. describe("quotaLeasePercentWeekly", () => {
  105. test("accepts valid percent (0.02)", () => {
  106. const parsed = UpdateSystemSettingsSchema.parse({
  107. quotaLeasePercentWeekly: 0.02,
  108. });
  109. expect(parsed.quotaLeasePercentWeekly).toBe(0.02);
  110. });
  111. test("accepts edge values (0 and 1)", () => {
  112. expect(
  113. UpdateSystemSettingsSchema.parse({ quotaLeasePercentWeekly: 0 }).quotaLeasePercentWeekly
  114. ).toBe(0);
  115. expect(
  116. UpdateSystemSettingsSchema.parse({ quotaLeasePercentWeekly: 1 }).quotaLeasePercentWeekly
  117. ).toBe(1);
  118. });
  119. test("rejects out of range values", () => {
  120. expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentWeekly: -0.01 })).toThrow();
  121. expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentWeekly: 1.01 })).toThrow();
  122. });
  123. });
  124. describe("quotaLeasePercentMonthly", () => {
  125. test("accepts valid percent (0.01)", () => {
  126. const parsed = UpdateSystemSettingsSchema.parse({
  127. quotaLeasePercentMonthly: 0.01,
  128. });
  129. expect(parsed.quotaLeasePercentMonthly).toBe(0.01);
  130. });
  131. test("accepts edge values (0 and 1)", () => {
  132. expect(
  133. UpdateSystemSettingsSchema.parse({ quotaLeasePercentMonthly: 0 }).quotaLeasePercentMonthly
  134. ).toBe(0);
  135. expect(
  136. UpdateSystemSettingsSchema.parse({ quotaLeasePercentMonthly: 1 }).quotaLeasePercentMonthly
  137. ).toBe(1);
  138. });
  139. test("rejects out of range values", () => {
  140. expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentMonthly: -0.01 })).toThrow();
  141. expect(() => UpdateSystemSettingsSchema.parse({ quotaLeasePercentMonthly: 1.01 })).toThrow();
  142. });
  143. });
  144. describe("quotaLeaseCapUsd", () => {
  145. test("accepts valid cap (3.0)", () => {
  146. const parsed = UpdateSystemSettingsSchema.parse({
  147. quotaLeaseCapUsd: 3.0,
  148. });
  149. expect(parsed.quotaLeaseCapUsd).toBe(3.0);
  150. });
  151. test("accepts null (no cap)", () => {
  152. const parsed = UpdateSystemSettingsSchema.parse({
  153. quotaLeaseCapUsd: null,
  154. });
  155. expect(parsed.quotaLeaseCapUsd).toBeNull();
  156. });
  157. test("accepts zero (disabled)", () => {
  158. const parsed = UpdateSystemSettingsSchema.parse({
  159. quotaLeaseCapUsd: 0,
  160. });
  161. expect(parsed.quotaLeaseCapUsd).toBe(0);
  162. });
  163. test("accepts high value (1000)", () => {
  164. const parsed = UpdateSystemSettingsSchema.parse({
  165. quotaLeaseCapUsd: 1000,
  166. });
  167. expect(parsed.quotaLeaseCapUsd).toBe(1000);
  168. });
  169. test("rejects negative value", () => {
  170. expect(() =>
  171. UpdateSystemSettingsSchema.parse({
  172. quotaLeaseCapUsd: -1,
  173. })
  174. ).toThrow();
  175. });
  176. });
  177. describe("combined fields", () => {
  178. test("accepts all quota lease fields together", () => {
  179. const parsed = UpdateSystemSettingsSchema.parse({
  180. quotaDbRefreshIntervalSeconds: 60,
  181. quotaLeasePercent5h: 0.1,
  182. quotaLeasePercentDaily: 0.05,
  183. quotaLeasePercentWeekly: 0.02,
  184. quotaLeasePercentMonthly: 0.01,
  185. quotaLeaseCapUsd: 3.0,
  186. });
  187. expect(parsed.quotaDbRefreshIntervalSeconds).toBe(60);
  188. expect(parsed.quotaLeasePercent5h).toBe(0.1);
  189. expect(parsed.quotaLeasePercentDaily).toBe(0.05);
  190. expect(parsed.quotaLeasePercentWeekly).toBe(0.02);
  191. expect(parsed.quotaLeasePercentMonthly).toBe(0.01);
  192. expect(parsed.quotaLeaseCapUsd).toBe(3.0);
  193. });
  194. test("all fields are optional", () => {
  195. const parsed = UpdateSystemSettingsSchema.parse({});
  196. expect(parsed.quotaDbRefreshIntervalSeconds).toBeUndefined();
  197. expect(parsed.quotaLeasePercent5h).toBeUndefined();
  198. expect(parsed.quotaLeasePercentDaily).toBeUndefined();
  199. expect(parsed.quotaLeasePercentWeekly).toBeUndefined();
  200. expect(parsed.quotaLeasePercentMonthly).toBeUndefined();
  201. expect(parsed.quotaLeaseCapUsd).toBeUndefined();
  202. });
  203. });
  204. });