@dizzlkheinz/ynab-mcpb 0.18.3 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/CLAUDE.md +87 -8
  3. package/bin/ynab-mcp-server.cjs +2 -2
  4. package/bin/ynab-mcp-server.js +3 -3
  5. package/biome.json +39 -0
  6. package/dist/bundle/index.cjs +67 -67
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +27 -27
  9. package/dist/server/YNABMCPServer.d.ts +3 -4
  10. package/dist/server/YNABMCPServer.js +111 -116
  11. package/dist/server/budgetResolver.d.ts +6 -5
  12. package/dist/server/budgetResolver.js +46 -36
  13. package/dist/server/cacheKeys.js +6 -6
  14. package/dist/server/cacheManager.js +14 -11
  15. package/dist/server/completions.d.ts +2 -2
  16. package/dist/server/completions.js +20 -15
  17. package/dist/server/config.d.ts +10 -5
  18. package/dist/server/config.js +24 -7
  19. package/dist/server/deltaCache.d.ts +2 -2
  20. package/dist/server/deltaCache.js +22 -16
  21. package/dist/server/deltaCache.merge.d.ts +2 -2
  22. package/dist/server/diagnostics.d.ts +4 -4
  23. package/dist/server/diagnostics.js +38 -32
  24. package/dist/server/errorHandler.d.ts +5 -12
  25. package/dist/server/errorHandler.js +219 -217
  26. package/dist/server/prompts.d.ts +2 -2
  27. package/dist/server/prompts.js +45 -45
  28. package/dist/server/rateLimiter.js +4 -4
  29. package/dist/server/requestLogger.d.ts +1 -1
  30. package/dist/server/requestLogger.js +40 -35
  31. package/dist/server/resources.d.ts +3 -3
  32. package/dist/server/resources.js +55 -52
  33. package/dist/server/responseFormatter.js +6 -6
  34. package/dist/server/securityMiddleware.d.ts +2 -2
  35. package/dist/server/securityMiddleware.js +22 -20
  36. package/dist/server/serverKnowledgeStore.js +1 -1
  37. package/dist/server/toolRegistry.d.ts +3 -3
  38. package/dist/server/toolRegistry.js +47 -40
  39. package/dist/tools/__tests__/deltaTestUtils.d.ts +3 -3
  40. package/dist/tools/__tests__/deltaTestUtils.js +2 -2
  41. package/dist/tools/accountTools.d.ts +9 -8
  42. package/dist/tools/accountTools.js +47 -47
  43. package/dist/tools/adapters.d.ts +13 -8
  44. package/dist/tools/adapters.js +21 -11
  45. package/dist/tools/budgetTools.d.ts +8 -7
  46. package/dist/tools/budgetTools.js +22 -22
  47. package/dist/tools/categoryTools.d.ts +9 -8
  48. package/dist/tools/categoryTools.js +68 -59
  49. package/dist/tools/compareTransactions/formatter.d.ts +3 -3
  50. package/dist/tools/compareTransactions/formatter.js +9 -9
  51. package/dist/tools/compareTransactions/index.d.ts +6 -6
  52. package/dist/tools/compareTransactions/index.js +58 -43
  53. package/dist/tools/compareTransactions/matcher.d.ts +1 -1
  54. package/dist/tools/compareTransactions/matcher.js +28 -15
  55. package/dist/tools/compareTransactions/parser.d.ts +2 -2
  56. package/dist/tools/compareTransactions/parser.js +144 -138
  57. package/dist/tools/compareTransactions/types.d.ts +4 -4
  58. package/dist/tools/compareTransactions.d.ts +1 -1
  59. package/dist/tools/compareTransactions.js +1 -1
  60. package/dist/tools/deltaFetcher.d.ts +2 -2
  61. package/dist/tools/deltaFetcher.js +16 -15
  62. package/dist/tools/deltaSupport.d.ts +4 -4
  63. package/dist/tools/deltaSupport.js +35 -41
  64. package/dist/tools/exportTransactions.d.ts +5 -4
  65. package/dist/tools/exportTransactions.js +61 -59
  66. package/dist/tools/monthTools.d.ts +7 -6
  67. package/dist/tools/monthTools.js +31 -29
  68. package/dist/tools/payeeTools.d.ts +7 -6
  69. package/dist/tools/payeeTools.js +28 -28
  70. package/dist/tools/reconcileAdapter.d.ts +2 -2
  71. package/dist/tools/reconcileAdapter.js +21 -11
  72. package/dist/tools/reconciliation/analyzer.d.ts +4 -4
  73. package/dist/tools/reconciliation/analyzer.js +136 -57
  74. package/dist/tools/reconciliation/csvParser.d.ts +3 -3
  75. package/dist/tools/reconciliation/csvParser.js +128 -104
  76. package/dist/tools/reconciliation/executor.d.ts +4 -4
  77. package/dist/tools/reconciliation/executor.js +148 -109
  78. package/dist/tools/reconciliation/index.d.ts +10 -10
  79. package/dist/tools/reconciliation/index.js +96 -83
  80. package/dist/tools/reconciliation/matcher.d.ts +3 -3
  81. package/dist/tools/reconciliation/matcher.js +17 -16
  82. package/dist/tools/reconciliation/payeeNormalizer.js +19 -8
  83. package/dist/tools/reconciliation/recommendationEngine.d.ts +1 -1
  84. package/dist/tools/reconciliation/recommendationEngine.js +40 -40
  85. package/dist/tools/reconciliation/reportFormatter.d.ts +2 -2
  86. package/dist/tools/reconciliation/reportFormatter.js +79 -54
  87. package/dist/tools/reconciliation/signDetector.d.ts +1 -1
  88. package/dist/tools/reconciliation/types.d.ts +19 -16
  89. package/dist/tools/reconciliation/ynabAdapter.d.ts +2 -2
  90. package/dist/tools/schemas/common.d.ts +1 -1
  91. package/dist/tools/schemas/common.js +1 -1
  92. package/dist/tools/schemas/outputs/accountOutputs.d.ts +1 -1
  93. package/dist/tools/schemas/outputs/accountOutputs.js +24 -18
  94. package/dist/tools/schemas/outputs/budgetOutputs.d.ts +1 -1
  95. package/dist/tools/schemas/outputs/budgetOutputs.js +14 -11
  96. package/dist/tools/schemas/outputs/categoryOutputs.d.ts +1 -1
  97. package/dist/tools/schemas/outputs/categoryOutputs.js +49 -29
  98. package/dist/tools/schemas/outputs/comparisonOutputs.d.ts +1 -1
  99. package/dist/tools/schemas/outputs/comparisonOutputs.js +12 -12
  100. package/dist/tools/schemas/outputs/index.d.ts +14 -14
  101. package/dist/tools/schemas/outputs/index.js +14 -14
  102. package/dist/tools/schemas/outputs/monthOutputs.d.ts +1 -1
  103. package/dist/tools/schemas/outputs/monthOutputs.js +56 -41
  104. package/dist/tools/schemas/outputs/payeeOutputs.d.ts +1 -1
  105. package/dist/tools/schemas/outputs/payeeOutputs.js +10 -10
  106. package/dist/tools/schemas/outputs/reconciliationOutputs.d.ts +2 -2
  107. package/dist/tools/schemas/outputs/reconciliationOutputs.js +45 -45
  108. package/dist/tools/schemas/outputs/transactionMutationOutputs.d.ts +1 -1
  109. package/dist/tools/schemas/outputs/transactionMutationOutputs.js +28 -22
  110. package/dist/tools/schemas/outputs/transactionOutputs.d.ts +1 -1
  111. package/dist/tools/schemas/outputs/transactionOutputs.js +43 -35
  112. package/dist/tools/schemas/outputs/utilityOutputs.d.ts +1 -1
  113. package/dist/tools/schemas/outputs/utilityOutputs.js +5 -3
  114. package/dist/tools/schemas/shared/commonOutputs.d.ts +1 -1
  115. package/dist/tools/schemas/shared/commonOutputs.js +15 -9
  116. package/dist/tools/transactionReadTools.d.ts +11 -0
  117. package/dist/tools/transactionReadTools.js +202 -0
  118. package/dist/tools/transactionSchemas.d.ts +309 -0
  119. package/dist/tools/transactionSchemas.js +235 -0
  120. package/dist/tools/transactionTools.d.ts +6 -302
  121. package/dist/tools/transactionTools.js +7 -2054
  122. package/dist/tools/transactionUtils.d.ts +31 -0
  123. package/dist/tools/transactionUtils.js +364 -0
  124. package/dist/tools/transactionWriteTools.d.ts +20 -0
  125. package/dist/tools/transactionWriteTools.js +1342 -0
  126. package/dist/tools/utilityTools.d.ts +5 -4
  127. package/dist/tools/utilityTools.js +11 -11
  128. package/dist/types/index.d.ts +7 -7
  129. package/dist/types/index.js +6 -6
  130. package/dist/types/reconciliation.d.ts +1 -1
  131. package/dist/types/toolRegistration.d.ts +14 -12
  132. package/dist/utils/amountUtils.js +1 -1
  133. package/dist/utils/dateUtils.js +4 -4
  134. package/dist/utils/errors.d.ts +3 -3
  135. package/dist/utils/errors.js +4 -4
  136. package/dist/utils/money.d.ts +2 -2
  137. package/dist/utils/money.js +8 -8
  138. package/dist/utils/validationError.d.ts +1 -1
  139. package/dist/utils/validationError.js +1 -1
  140. package/docs/assets/examples/reconciliation-with-recommendations.json +66 -66
  141. package/docs/assets/schemas/reconciliation-v2.json +360 -336
  142. package/docs/plans/2025-12-25-transaction-tools-refactor-design.md +211 -0
  143. package/docs/plans/2025-12-25-transaction-tools-refactor.md +905 -0
  144. package/esbuild.config.mjs +53 -50
  145. package/meta.json +12548 -12548
  146. package/package.json +98 -109
  147. package/scripts/analyze-bundle.mjs +33 -30
  148. package/scripts/create-pr-description.js +169 -120
  149. package/scripts/run-all-tests.js +205 -0
  150. package/scripts/run-domain-integration-tests.js +28 -18
  151. package/scripts/run-generate-mcpb.js +19 -17
  152. package/scripts/run-throttled-integration-tests.js +92 -83
  153. package/scripts/test-delta-params.mjs +149 -120
  154. package/scripts/test-recommendations.ts +36 -32
  155. package/scripts/tmpTransaction.ts +80 -43
  156. package/scripts/validate-env.js +98 -91
  157. package/scripts/verify-build.js +78 -76
  158. package/src/__tests__/comprehensive.integration.test.ts +1281 -1154
  159. package/src/__tests__/performance.test.ts +723 -671
  160. package/src/__tests__/setup.ts +442 -395
  161. package/src/__tests__/smoke.e2e.test.ts +41 -39
  162. package/src/__tests__/testRunner.ts +314 -295
  163. package/src/__tests__/testUtils.ts +456 -364
  164. package/src/__tests__/tools/reconciliation/csvParser.integration.test.ts +109 -107
  165. package/src/__tests__/tools/reconciliation/real-world.integration.test.ts +41 -41
  166. package/src/index.ts +68 -59
  167. package/src/server/CLAUDE.md +480 -0
  168. package/src/server/YNABMCPServer.ts +821 -794
  169. package/src/server/__tests__/YNABMCPServer.integration.test.ts +929 -893
  170. package/src/server/__tests__/YNABMCPServer.test.ts +903 -899
  171. package/src/server/__tests__/budgetResolver.test.ts +466 -423
  172. package/src/server/__tests__/cacheManager.test.ts +891 -874
  173. package/src/server/__tests__/completions.integration.test.ts +115 -106
  174. package/src/server/__tests__/completions.test.ts +334 -313
  175. package/src/server/__tests__/config.test.ts +98 -86
  176. package/src/server/__tests__/deltaCache.merge.test.ts +774 -703
  177. package/src/server/__tests__/deltaCache.swr.test.ts +198 -153
  178. package/src/server/__tests__/deltaCache.test.ts +946 -759
  179. package/src/server/__tests__/diagnostics.test.ts +825 -792
  180. package/src/server/__tests__/errorHandler.integration.test.ts +512 -462
  181. package/src/server/__tests__/errorHandler.test.ts +402 -397
  182. package/src/server/__tests__/prompts.test.ts +424 -347
  183. package/src/server/__tests__/rateLimiter.test.ts +313 -309
  184. package/src/server/__tests__/requestLogger.test.ts +443 -403
  185. package/src/server/__tests__/resources.template.test.ts +196 -185
  186. package/src/server/__tests__/resources.test.ts +294 -288
  187. package/src/server/__tests__/security.integration.test.ts +487 -421
  188. package/src/server/__tests__/securityMiddleware.test.ts +519 -444
  189. package/src/server/__tests__/server-startup.integration.test.ts +509 -490
  190. package/src/server/__tests__/serverKnowledgeStore.test.ts +174 -173
  191. package/src/server/__tests__/toolRegistration.test.ts +239 -210
  192. package/src/server/__tests__/toolRegistry.test.ts +907 -845
  193. package/src/server/budgetResolver.ts +221 -181
  194. package/src/server/cacheKeys.ts +6 -6
  195. package/src/server/cacheManager.ts +498 -484
  196. package/src/server/completions.ts +267 -243
  197. package/src/server/config.ts +35 -14
  198. package/src/server/deltaCache.merge.ts +146 -128
  199. package/src/server/deltaCache.ts +352 -309
  200. package/src/server/diagnostics.ts +257 -242
  201. package/src/server/errorHandler.ts +747 -744
  202. package/src/server/prompts.ts +181 -176
  203. package/src/server/rateLimiter.ts +131 -129
  204. package/src/server/requestLogger.ts +350 -322
  205. package/src/server/resources.ts +442 -374
  206. package/src/server/responseFormatter.ts +41 -37
  207. package/src/server/securityMiddleware.ts +223 -205
  208. package/src/server/serverKnowledgeStore.ts +67 -67
  209. package/src/server/toolRegistry.ts +508 -474
  210. package/src/tools/CLAUDE.md +604 -0
  211. package/src/tools/__tests__/accountTools.delta.integration.test.ts +128 -111
  212. package/src/tools/__tests__/accountTools.integration.test.ts +129 -111
  213. package/src/tools/__tests__/accountTools.test.ts +685 -638
  214. package/src/tools/__tests__/adapters.test.ts +142 -108
  215. package/src/tools/__tests__/budgetTools.delta.integration.test.ts +73 -73
  216. package/src/tools/__tests__/budgetTools.integration.test.ts +132 -124
  217. package/src/tools/__tests__/budgetTools.test.ts +442 -413
  218. package/src/tools/__tests__/categoryTools.delta.integration.test.ts +76 -68
  219. package/src/tools/__tests__/categoryTools.integration.test.ts +314 -288
  220. package/src/tools/__tests__/categoryTools.test.ts +656 -625
  221. package/src/tools/__tests__/compareTransactions/formatter.test.ts +535 -462
  222. package/src/tools/__tests__/compareTransactions/index.test.ts +378 -358
  223. package/src/tools/__tests__/compareTransactions/matcher.test.ts +497 -398
  224. package/src/tools/__tests__/compareTransactions/parser.test.ts +765 -747
  225. package/src/tools/__tests__/compareTransactions.test.ts +352 -332
  226. package/src/tools/__tests__/compareTransactions.window.test.ts +150 -146
  227. package/src/tools/__tests__/deltaFetcher.scheduled.integration.test.ts +69 -65
  228. package/src/tools/__tests__/deltaFetcher.test.ts +325 -265
  229. package/src/tools/__tests__/deltaSupport.test.ts +211 -184
  230. package/src/tools/__tests__/deltaTestUtils.ts +37 -33
  231. package/src/tools/__tests__/exportTransactions.test.ts +205 -200
  232. package/src/tools/__tests__/monthTools.delta.integration.test.ts +68 -68
  233. package/src/tools/__tests__/monthTools.integration.test.ts +178 -166
  234. package/src/tools/__tests__/monthTools.test.ts +561 -512
  235. package/src/tools/__tests__/payeeTools.delta.integration.test.ts +68 -68
  236. package/src/tools/__tests__/payeeTools.integration.test.ts +158 -142
  237. package/src/tools/__tests__/payeeTools.test.ts +486 -434
  238. package/src/tools/__tests__/transactionSchemas.test.ts +1204 -0
  239. package/src/tools/__tests__/transactionTools.integration.test.ts +875 -825
  240. package/src/tools/__tests__/transactionTools.test.ts +4923 -4366
  241. package/src/tools/__tests__/transactionUtils.test.ts +1016 -0
  242. package/src/tools/__tests__/utilityTools.integration.test.ts +32 -32
  243. package/src/tools/__tests__/utilityTools.test.ts +68 -58
  244. package/src/tools/accountTools.ts +293 -271
  245. package/src/tools/adapters.ts +120 -63
  246. package/src/tools/budgetTools.ts +121 -116
  247. package/src/tools/categoryTools.ts +379 -339
  248. package/src/tools/compareTransactions/formatter.ts +131 -119
  249. package/src/tools/compareTransactions/index.ts +249 -214
  250. package/src/tools/compareTransactions/matcher.ts +259 -209
  251. package/src/tools/compareTransactions/parser.ts +517 -487
  252. package/src/tools/compareTransactions/types.ts +38 -38
  253. package/src/tools/compareTransactions.ts +1 -1
  254. package/src/tools/deltaFetcher.ts +281 -260
  255. package/src/tools/deltaSupport.ts +264 -259
  256. package/src/tools/exportTransactions.ts +230 -218
  257. package/src/tools/monthTools.ts +180 -165
  258. package/src/tools/payeeTools.ts +152 -140
  259. package/src/tools/reconcileAdapter.ts +297 -246
  260. package/src/tools/reconciliation/CLAUDE.md +506 -0
  261. package/src/tools/reconciliation/__tests__/adapter.causes.test.ts +135 -112
  262. package/src/tools/reconciliation/__tests__/adapter.test.ts +249 -227
  263. package/src/tools/reconciliation/__tests__/analyzer.test.ts +408 -335
  264. package/src/tools/reconciliation/__tests__/csvParser.test.ts +71 -69
  265. package/src/tools/reconciliation/__tests__/executor.integration.test.ts +348 -323
  266. package/src/tools/reconciliation/__tests__/executor.progress.test.ts +503 -457
  267. package/src/tools/reconciliation/__tests__/executor.test.ts +898 -831
  268. package/src/tools/reconciliation/__tests__/matcher.test.ts +667 -663
  269. package/src/tools/reconciliation/__tests__/payeeNormalizer.test.ts +296 -276
  270. package/src/tools/reconciliation/__tests__/recommendationEngine.integration.test.ts +692 -624
  271. package/src/tools/reconciliation/__tests__/recommendationEngine.test.ts +1008 -986
  272. package/src/tools/reconciliation/__tests__/reconciliation.delta.integration.test.ts +187 -146
  273. package/src/tools/reconciliation/__tests__/reportFormatter.test.ts +583 -530
  274. package/src/tools/reconciliation/__tests__/scenarios/adapterCurrency.scenario.test.ts +75 -71
  275. package/src/tools/reconciliation/__tests__/scenarios/extremes.scenario.test.ts +70 -58
  276. package/src/tools/reconciliation/__tests__/scenarios/repeatAmount.scenario.test.ts +102 -88
  277. package/src/tools/reconciliation/__tests__/schemaUrl.test.ts +58 -43
  278. package/src/tools/reconciliation/__tests__/signDetector.test.ts +209 -206
  279. package/src/tools/reconciliation/__tests__/ynabAdapter.test.ts +66 -60
  280. package/src/tools/reconciliation/analyzer.ts +582 -406
  281. package/src/tools/reconciliation/csvParser.ts +656 -609
  282. package/src/tools/reconciliation/executor.ts +1290 -1128
  283. package/src/tools/reconciliation/index.ts +580 -528
  284. package/src/tools/reconciliation/matcher.ts +256 -240
  285. package/src/tools/reconciliation/payeeNormalizer.ts +92 -78
  286. package/src/tools/reconciliation/recommendationEngine.ts +357 -345
  287. package/src/tools/reconciliation/reportFormatter.ts +349 -276
  288. package/src/tools/reconciliation/signDetector.ts +89 -83
  289. package/src/tools/reconciliation/types.ts +164 -153
  290. package/src/tools/reconciliation/ynabAdapter.ts +17 -15
  291. package/src/tools/schemas/CLAUDE.md +546 -0
  292. package/src/tools/schemas/common.ts +1 -1
  293. package/src/tools/schemas/outputs/__tests__/accountOutputs.test.ts +410 -409
  294. package/src/tools/schemas/outputs/__tests__/budgetOutputs.test.ts +305 -299
  295. package/src/tools/schemas/outputs/__tests__/categoryOutputs.test.ts +431 -430
  296. package/src/tools/schemas/outputs/__tests__/comparisonOutputs.test.ts +510 -495
  297. package/src/tools/schemas/outputs/__tests__/dateValidation.test.ts +179 -153
  298. package/src/tools/schemas/outputs/__tests__/discrepancyDirection.test.ts +293 -254
  299. package/src/tools/schemas/outputs/__tests__/monthOutputs.test.ts +457 -457
  300. package/src/tools/schemas/outputs/__tests__/payeeOutputs.test.ts +362 -356
  301. package/src/tools/schemas/outputs/__tests__/reconciliationOutputs.test.ts +402 -399
  302. package/src/tools/schemas/outputs/__tests__/transactionMutationSchemas.test.ts +225 -211
  303. package/src/tools/schemas/outputs/__tests__/transactionOutputs.test.ts +457 -454
  304. package/src/tools/schemas/outputs/__tests__/utilityOutputs.test.ts +316 -315
  305. package/src/tools/schemas/outputs/accountOutputs.ts +40 -34
  306. package/src/tools/schemas/outputs/budgetOutputs.ts +24 -19
  307. package/src/tools/schemas/outputs/categoryOutputs.ts +76 -56
  308. package/src/tools/schemas/outputs/comparisonOutputs.ts +192 -169
  309. package/src/tools/schemas/outputs/index.ts +163 -163
  310. package/src/tools/schemas/outputs/monthOutputs.ts +95 -80
  311. package/src/tools/schemas/outputs/payeeOutputs.ts +18 -18
  312. package/src/tools/schemas/outputs/reconciliationOutputs.ts +386 -373
  313. package/src/tools/schemas/outputs/transactionMutationOutputs.ts +259 -231
  314. package/src/tools/schemas/outputs/transactionOutputs.ts +81 -71
  315. package/src/tools/schemas/outputs/utilityOutputs.ts +90 -84
  316. package/src/tools/schemas/shared/commonOutputs.ts +27 -19
  317. package/src/tools/toolCategories.ts +114 -114
  318. package/src/tools/transactionReadTools.ts +327 -0
  319. package/src/tools/transactionSchemas.ts +484 -0
  320. package/src/tools/transactionTools.ts +107 -2990
  321. package/src/tools/transactionUtils.ts +621 -0
  322. package/src/tools/transactionWriteTools.ts +2110 -0
  323. package/src/tools/utilityTools.ts +46 -41
  324. package/src/types/CLAUDE.md +477 -0
  325. package/src/types/__tests__/index.test.ts +51 -51
  326. package/src/types/index.ts +43 -39
  327. package/src/types/integration-tests.d.ts +26 -26
  328. package/src/types/reconciliation.ts +29 -29
  329. package/src/types/toolAnnotations.ts +30 -30
  330. package/src/types/toolRegistration.ts +43 -32
  331. package/src/utils/CLAUDE.md +508 -0
  332. package/src/utils/__tests__/dateUtils.test.ts +174 -168
  333. package/src/utils/__tests__/money.test.ts +193 -187
  334. package/src/utils/amountUtils.ts +5 -5
  335. package/src/utils/baseError.ts +5 -5
  336. package/src/utils/dateUtils.ts +29 -26
  337. package/src/utils/errors.ts +14 -14
  338. package/src/utils/money.ts +66 -52
  339. package/src/utils/validationError.ts +1 -1
  340. package/tsconfig.json +29 -29
  341. package/tsconfig.prod.json +16 -16
  342. package/vitest-reporters/split-json-reporter.ts +247 -204
  343. package/vitest.config.ts +99 -95
  344. package/.prettierignore +0 -10
  345. package/.prettierrc.json +0 -10
  346. package/eslint.config.js +0 -49
@@ -0,0 +1,1204 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ CreateReceiptSplitTransactionSchema,
4
+ CreateTransactionSchema,
5
+ CreateTransactionsSchema,
6
+ DeleteTransactionSchema,
7
+ GetTransactionSchema,
8
+ ListTransactionsSchema,
9
+ UpdateTransactionSchema,
10
+ UpdateTransactionsSchema,
11
+ } from "../transactionSchemas.js";
12
+
13
+ describe("Transaction Schemas", () => {
14
+ describe("ListTransactionsSchema", () => {
15
+ it("should validate with only budget_id", () => {
16
+ const result = ListTransactionsSchema.parse({ budget_id: "budget-1" });
17
+ expect(result.budget_id).toBe("budget-1");
18
+ expect(result.account_id).toBeUndefined();
19
+ expect(result.category_id).toBeUndefined();
20
+ expect(result.since_date).toBeUndefined();
21
+ expect(result.type).toBeUndefined();
22
+ });
23
+
24
+ it("should validate with all optional fields", () => {
25
+ const result = ListTransactionsSchema.parse({
26
+ budget_id: "budget-1",
27
+ account_id: "account-1",
28
+ category_id: "category-1",
29
+ since_date: "2024-01-01",
30
+ type: "uncategorized",
31
+ });
32
+ expect(result.budget_id).toBe("budget-1");
33
+ expect(result.account_id).toBe("account-1");
34
+ expect(result.category_id).toBe("category-1");
35
+ expect(result.since_date).toBe("2024-01-01");
36
+ expect(result.type).toBe("uncategorized");
37
+ });
38
+
39
+ it("should validate type as unapproved", () => {
40
+ const result = ListTransactionsSchema.parse({
41
+ budget_id: "budget-1",
42
+ type: "unapproved",
43
+ });
44
+ expect(result.type).toBe("unapproved");
45
+ });
46
+
47
+ it("should reject empty budget_id", () => {
48
+ expect(() => ListTransactionsSchema.parse({ budget_id: "" })).toThrow(
49
+ "Budget ID is required",
50
+ );
51
+ });
52
+
53
+ it("should reject missing budget_id", () => {
54
+ expect(() => ListTransactionsSchema.parse({})).toThrow();
55
+ });
56
+
57
+ it("should reject invalid date format (missing dashes)", () => {
58
+ expect(() =>
59
+ ListTransactionsSchema.parse({
60
+ budget_id: "budget-1",
61
+ since_date: "20240101",
62
+ }),
63
+ ).toThrow("Date must be in ISO format (YYYY-MM-DD)");
64
+ });
65
+
66
+ it("should reject invalid date format (wrong separator)", () => {
67
+ expect(() =>
68
+ ListTransactionsSchema.parse({
69
+ budget_id: "budget-1",
70
+ since_date: "2024/01/01",
71
+ }),
72
+ ).toThrow("Date must be in ISO format (YYYY-MM-DD)");
73
+ });
74
+
75
+ it("should reject invalid type value", () => {
76
+ expect(() =>
77
+ ListTransactionsSchema.parse({
78
+ budget_id: "budget-1",
79
+ type: "invalid",
80
+ }),
81
+ ).toThrow();
82
+ });
83
+
84
+ it("should reject extra fields (strict mode)", () => {
85
+ expect(() =>
86
+ ListTransactionsSchema.parse({
87
+ budget_id: "budget-1",
88
+ extra_field: "value",
89
+ }),
90
+ ).toThrow();
91
+ });
92
+ });
93
+
94
+ describe("GetTransactionSchema", () => {
95
+ it("should validate with required fields", () => {
96
+ const result = GetTransactionSchema.parse({
97
+ budget_id: "budget-1",
98
+ transaction_id: "transaction-1",
99
+ });
100
+ expect(result.budget_id).toBe("budget-1");
101
+ expect(result.transaction_id).toBe("transaction-1");
102
+ });
103
+
104
+ it("should reject empty budget_id", () => {
105
+ expect(() =>
106
+ GetTransactionSchema.parse({
107
+ budget_id: "",
108
+ transaction_id: "transaction-1",
109
+ }),
110
+ ).toThrow("Budget ID is required");
111
+ });
112
+
113
+ it("should reject empty transaction_id", () => {
114
+ expect(() =>
115
+ GetTransactionSchema.parse({
116
+ budget_id: "budget-1",
117
+ transaction_id: "",
118
+ }),
119
+ ).toThrow("Transaction ID is required");
120
+ });
121
+
122
+ it("should reject missing transaction_id", () => {
123
+ expect(() =>
124
+ GetTransactionSchema.parse({ budget_id: "budget-1" }),
125
+ ).toThrow();
126
+ });
127
+
128
+ it("should reject extra fields (strict mode)", () => {
129
+ expect(() =>
130
+ GetTransactionSchema.parse({
131
+ budget_id: "budget-1",
132
+ transaction_id: "transaction-1",
133
+ extra_field: "value",
134
+ }),
135
+ ).toThrow();
136
+ });
137
+ });
138
+
139
+ describe("CreateTransactionSchema", () => {
140
+ const validBase = {
141
+ budget_id: "budget-1",
142
+ account_id: "account-1",
143
+ amount: 25500,
144
+ date: "2024-01-15",
145
+ };
146
+
147
+ it("should validate with required fields only", () => {
148
+ const result = CreateTransactionSchema.parse(validBase);
149
+ expect(result.budget_id).toBe("budget-1");
150
+ expect(result.account_id).toBe("account-1");
151
+ expect(result.amount).toBe(25500);
152
+ expect(result.date).toBe("2024-01-15");
153
+ });
154
+
155
+ it("should validate with all optional fields", () => {
156
+ const result = CreateTransactionSchema.parse({
157
+ ...validBase,
158
+ payee_name: "Grocery Store",
159
+ payee_id: "payee-1",
160
+ category_id: "category-1",
161
+ memo: "Weekly groceries",
162
+ cleared: "cleared",
163
+ approved: true,
164
+ flag_color: "red",
165
+ import_id: "YNAB:12345:2024-01-15:1",
166
+ dry_run: true,
167
+ });
168
+ expect(result.payee_name).toBe("Grocery Store");
169
+ expect(result.payee_id).toBe("payee-1");
170
+ expect(result.category_id).toBe("category-1");
171
+ expect(result.memo).toBe("Weekly groceries");
172
+ expect(result.cleared).toBe("cleared");
173
+ expect(result.approved).toBe(true);
174
+ expect(result.flag_color).toBe("red");
175
+ expect(result.import_id).toBe("YNAB:12345:2024-01-15:1");
176
+ expect(result.dry_run).toBe(true);
177
+ });
178
+
179
+ it("should validate all cleared status values", () => {
180
+ ["cleared", "uncleared", "reconciled"].forEach((status) => {
181
+ const result = CreateTransactionSchema.parse({
182
+ ...validBase,
183
+ cleared: status,
184
+ });
185
+ expect(result.cleared).toBe(status);
186
+ });
187
+ });
188
+
189
+ it("should validate all flag colors", () => {
190
+ ["red", "orange", "yellow", "green", "blue", "purple"].forEach(
191
+ (color) => {
192
+ const result = CreateTransactionSchema.parse({
193
+ ...validBase,
194
+ flag_color: color,
195
+ });
196
+ expect(result.flag_color).toBe(color);
197
+ },
198
+ );
199
+ });
200
+
201
+ it("should validate negative amounts", () => {
202
+ const result = CreateTransactionSchema.parse({
203
+ ...validBase,
204
+ amount: -25500,
205
+ });
206
+ expect(result.amount).toBe(-25500);
207
+ });
208
+
209
+ it("should validate zero amount", () => {
210
+ const result = CreateTransactionSchema.parse({
211
+ ...validBase,
212
+ amount: 0,
213
+ });
214
+ expect(result.amount).toBe(0);
215
+ });
216
+
217
+ it("should reject non-integer amount", () => {
218
+ expect(() =>
219
+ CreateTransactionSchema.parse({
220
+ ...validBase,
221
+ amount: 25.5,
222
+ }),
223
+ ).toThrow("Amount must be an integer in milliunits");
224
+ });
225
+
226
+ it("should reject invalid date format", () => {
227
+ expect(() =>
228
+ CreateTransactionSchema.parse({
229
+ ...validBase,
230
+ date: "2024/01/15",
231
+ }),
232
+ ).toThrow("Date must be in ISO format (YYYY-MM-DD)");
233
+ });
234
+
235
+ it("should reject invalid cleared status", () => {
236
+ expect(() =>
237
+ CreateTransactionSchema.parse({
238
+ ...validBase,
239
+ cleared: "invalid",
240
+ }),
241
+ ).toThrow();
242
+ });
243
+
244
+ it("should reject invalid flag color", () => {
245
+ expect(() =>
246
+ CreateTransactionSchema.parse({
247
+ ...validBase,
248
+ flag_color: "pink",
249
+ }),
250
+ ).toThrow();
251
+ });
252
+
253
+ it("should reject empty import_id", () => {
254
+ expect(() =>
255
+ CreateTransactionSchema.parse({
256
+ ...validBase,
257
+ import_id: "",
258
+ }),
259
+ ).toThrow("Import ID cannot be empty");
260
+ });
261
+
262
+ it("should validate subtransactions with matching total", () => {
263
+ const result = CreateTransactionSchema.parse({
264
+ ...validBase,
265
+ amount: 30000,
266
+ subtransactions: [
267
+ { amount: 15000, category_id: "cat-1" },
268
+ { amount: 10000, category_id: "cat-2" },
269
+ { amount: 5000, category_id: "cat-3" },
270
+ ],
271
+ });
272
+ expect(result.subtransactions).toHaveLength(3);
273
+ expect(result.subtransactions?.[0].amount).toBe(15000);
274
+ });
275
+
276
+ it("should validate subtransactions with all optional fields", () => {
277
+ const result = CreateTransactionSchema.parse({
278
+ ...validBase,
279
+ amount: 10000,
280
+ subtransactions: [
281
+ {
282
+ amount: 10000,
283
+ payee_name: "Sub Payee",
284
+ payee_id: "payee-sub",
285
+ category_id: "cat-1",
286
+ memo: "Subtransaction memo",
287
+ },
288
+ ],
289
+ });
290
+ expect(result.subtransactions?.[0].payee_name).toBe("Sub Payee");
291
+ expect(result.subtransactions?.[0].payee_id).toBe("payee-sub");
292
+ expect(result.subtransactions?.[0].memo).toBe("Subtransaction memo");
293
+ });
294
+
295
+ it("should reject subtransactions with non-matching total", () => {
296
+ expect(() =>
297
+ CreateTransactionSchema.parse({
298
+ ...validBase,
299
+ amount: 30000,
300
+ subtransactions: [
301
+ { amount: 15000, category_id: "cat-1" },
302
+ { amount: 10000, category_id: "cat-2" },
303
+ ],
304
+ }),
305
+ ).toThrow("Amount must equal the sum of subtransaction amounts");
306
+ });
307
+
308
+ it("should reject subtransactions with total exceeding parent", () => {
309
+ expect(() =>
310
+ CreateTransactionSchema.parse({
311
+ ...validBase,
312
+ amount: 20000,
313
+ subtransactions: [
314
+ { amount: 15000, category_id: "cat-1" },
315
+ { amount: 10000, category_id: "cat-2" },
316
+ ],
317
+ }),
318
+ ).toThrow("Amount must equal the sum of subtransaction amounts");
319
+ });
320
+
321
+ it("should reject empty subtransactions array", () => {
322
+ expect(() =>
323
+ CreateTransactionSchema.parse({
324
+ ...validBase,
325
+ subtransactions: [],
326
+ }),
327
+ ).toThrow("At least one subtransaction is required when provided");
328
+ });
329
+
330
+ it("should reject subtransaction with non-integer amount", () => {
331
+ expect(() =>
332
+ CreateTransactionSchema.parse({
333
+ ...validBase,
334
+ amount: 10000,
335
+ subtransactions: [{ amount: 10000.5, category_id: "cat-1" }],
336
+ }),
337
+ ).toThrow("Subtransaction amount must be an integer in milliunits");
338
+ });
339
+
340
+ it("should reject extra fields in subtransaction", () => {
341
+ expect(() =>
342
+ CreateTransactionSchema.parse({
343
+ ...validBase,
344
+ amount: 10000,
345
+ subtransactions: [
346
+ {
347
+ amount: 10000,
348
+ category_id: "cat-1",
349
+ extra_field: "value",
350
+ },
351
+ ],
352
+ }),
353
+ ).toThrow();
354
+ });
355
+ });
356
+
357
+ describe("CreateTransactionsSchema", () => {
358
+ const validTransaction = {
359
+ account_id: "account-1",
360
+ amount: 10000,
361
+ date: "2024-01-15",
362
+ };
363
+
364
+ it("should validate with single transaction", () => {
365
+ const result = CreateTransactionsSchema.parse({
366
+ budget_id: "budget-1",
367
+ transactions: [validTransaction],
368
+ });
369
+ expect(result.budget_id).toBe("budget-1");
370
+ expect(result.transactions).toHaveLength(1);
371
+ expect(result.transactions[0].account_id).toBe("account-1");
372
+ });
373
+
374
+ it("should validate with multiple transactions", () => {
375
+ const result = CreateTransactionsSchema.parse({
376
+ budget_id: "budget-1",
377
+ transactions: [
378
+ validTransaction,
379
+ { ...validTransaction, account_id: "account-2" },
380
+ { ...validTransaction, account_id: "account-3" },
381
+ ],
382
+ });
383
+ expect(result.transactions).toHaveLength(3);
384
+ });
385
+
386
+ it("should validate with dry_run flag", () => {
387
+ const result = CreateTransactionsSchema.parse({
388
+ budget_id: "budget-1",
389
+ transactions: [validTransaction],
390
+ dry_run: true,
391
+ });
392
+ expect(result.dry_run).toBe(true);
393
+ });
394
+
395
+ it("should validate transaction with all optional fields", () => {
396
+ const result = CreateTransactionsSchema.parse({
397
+ budget_id: "budget-1",
398
+ transactions: [
399
+ {
400
+ ...validTransaction,
401
+ payee_name: "Store",
402
+ payee_id: "payee-1",
403
+ category_id: "cat-1",
404
+ memo: "Test memo",
405
+ cleared: "cleared",
406
+ approved: true,
407
+ flag_color: "blue",
408
+ import_id: "YNAB:123:2024-01-15:1",
409
+ },
410
+ ],
411
+ });
412
+ expect(result.transactions[0].payee_name).toBe("Store");
413
+ expect(result.transactions[0].memo).toBe("Test memo");
414
+ });
415
+
416
+ it("should reject empty transactions array", () => {
417
+ expect(() =>
418
+ CreateTransactionsSchema.parse({
419
+ budget_id: "budget-1",
420
+ transactions: [],
421
+ }),
422
+ ).toThrow("At least one transaction is required");
423
+ });
424
+
425
+ it("should reject more than 100 transactions", () => {
426
+ const transactions = Array(101)
427
+ .fill(null)
428
+ .map((_, i) => ({
429
+ ...validTransaction,
430
+ account_id: `account-${i}`,
431
+ }));
432
+
433
+ expect(() =>
434
+ CreateTransactionsSchema.parse({
435
+ budget_id: "budget-1",
436
+ transactions,
437
+ }),
438
+ ).toThrow("A maximum of 100 transactions may be created at once");
439
+ });
440
+
441
+ it("should accept exactly 100 transactions", () => {
442
+ const transactions = Array(100)
443
+ .fill(null)
444
+ .map((_, i) => ({
445
+ ...validTransaction,
446
+ account_id: `account-${i}`,
447
+ }));
448
+
449
+ const result = CreateTransactionsSchema.parse({
450
+ budget_id: "budget-1",
451
+ transactions,
452
+ });
453
+ expect(result.transactions).toHaveLength(100);
454
+ });
455
+
456
+ it("should reject transaction with subtransactions field (not supported in bulk)", () => {
457
+ expect(() =>
458
+ CreateTransactionsSchema.parse({
459
+ budget_id: "budget-1",
460
+ transactions: [
461
+ {
462
+ ...validTransaction,
463
+ subtransactions: [{ amount: 10000, category_id: "cat-1" }],
464
+ },
465
+ ],
466
+ }),
467
+ ).toThrow();
468
+ });
469
+
470
+ it("should reject empty budget_id", () => {
471
+ expect(() =>
472
+ CreateTransactionsSchema.parse({
473
+ budget_id: "",
474
+ transactions: [validTransaction],
475
+ }),
476
+ ).toThrow("Budget ID is required");
477
+ });
478
+ });
479
+
480
+ describe("CreateReceiptSplitTransactionSchema", () => {
481
+ const validReceipt = {
482
+ budget_id: "budget-1",
483
+ account_id: "account-1",
484
+ payee_name: "Grocery Store",
485
+ receipt_tax: 2.5,
486
+ receipt_total: 27.5,
487
+ categories: [
488
+ {
489
+ category_id: "cat-1",
490
+ items: [
491
+ { name: "Milk", amount: 5.0 },
492
+ { name: "Bread", amount: 3.0 },
493
+ ],
494
+ },
495
+ {
496
+ category_id: "cat-2",
497
+ items: [{ name: "Apples", amount: 7.0 }],
498
+ },
499
+ {
500
+ category_id: "cat-3",
501
+ items: [{ name: "Chicken", amount: 10.0 }],
502
+ },
503
+ ],
504
+ };
505
+
506
+ it("should validate with required fields only", () => {
507
+ const result = CreateReceiptSplitTransactionSchema.parse(validReceipt);
508
+ expect(result.budget_id).toBe("budget-1");
509
+ expect(result.account_id).toBe("account-1");
510
+ expect(result.payee_name).toBe("Grocery Store");
511
+ expect(result.receipt_tax).toBe(2.5);
512
+ expect(result.receipt_total).toBe(27.5);
513
+ expect(result.categories).toHaveLength(3);
514
+ });
515
+
516
+ it("should validate with all optional fields", () => {
517
+ const result = CreateReceiptSplitTransactionSchema.parse({
518
+ ...validReceipt,
519
+ date: "2024-01-15",
520
+ memo: "Weekly shopping",
521
+ receipt_subtotal: 25.0,
522
+ cleared: "cleared",
523
+ approved: true,
524
+ flag_color: "green",
525
+ dry_run: true,
526
+ });
527
+ expect(result.date).toBe("2024-01-15");
528
+ expect(result.memo).toBe("Weekly shopping");
529
+ expect(result.receipt_subtotal).toBe(25.0);
530
+ expect(result.cleared).toBe("cleared");
531
+ expect(result.approved).toBe(true);
532
+ expect(result.flag_color).toBe("green");
533
+ expect(result.dry_run).toBe(true);
534
+ });
535
+
536
+ it("should validate items with quantity", () => {
537
+ const result = CreateReceiptSplitTransactionSchema.parse({
538
+ ...validReceipt,
539
+ categories: [
540
+ {
541
+ category_id: "cat-1",
542
+ items: [
543
+ {
544
+ name: "Apples",
545
+ amount: 10.0,
546
+ quantity: 2.5,
547
+ memo: "2.5 lbs @ $4/lb",
548
+ },
549
+ ],
550
+ },
551
+ ],
552
+ receipt_total: 12.5,
553
+ });
554
+ expect(result.categories[0].items[0].quantity).toBe(2.5);
555
+ expect(result.categories[0].items[0].memo).toBe("2.5 lbs @ $4/lb");
556
+ });
557
+
558
+ it("should validate items with category_name", () => {
559
+ const result = CreateReceiptSplitTransactionSchema.parse({
560
+ ...validReceipt,
561
+ categories: [
562
+ {
563
+ category_id: "cat-1",
564
+ category_name: "Groceries",
565
+ items: [{ name: "Item", amount: 25.0 }],
566
+ },
567
+ ],
568
+ });
569
+ expect(result.categories[0].category_name).toBe("Groceries");
570
+ });
571
+
572
+ it("should validate when subtotal + tax = total (exact match)", () => {
573
+ const result = CreateReceiptSplitTransactionSchema.parse({
574
+ ...validReceipt,
575
+ receipt_subtotal: 25.0,
576
+ receipt_tax: 2.5,
577
+ receipt_total: 27.5,
578
+ });
579
+ expect(result.receipt_subtotal).toBe(25.0);
580
+ });
581
+
582
+ it("should validate when items total matches receipt_subtotal", () => {
583
+ const result = CreateReceiptSplitTransactionSchema.parse({
584
+ budget_id: "budget-1",
585
+ account_id: "account-1",
586
+ payee_name: "Store",
587
+ receipt_subtotal: 50.0,
588
+ receipt_tax: 5.0,
589
+ receipt_total: 55.0,
590
+ categories: [
591
+ {
592
+ category_id: "cat-1",
593
+ items: [
594
+ { name: "Item 1", amount: 30.0 },
595
+ { name: "Item 2", amount: 20.0 },
596
+ ],
597
+ },
598
+ ],
599
+ });
600
+ expect(result.categories[0].items).toHaveLength(2);
601
+ });
602
+
603
+ it("should reject when items total does not match receipt_subtotal", () => {
604
+ expect(() =>
605
+ CreateReceiptSplitTransactionSchema.parse({
606
+ ...validReceipt,
607
+ receipt_subtotal: 30.0, // Items sum to 25.0
608
+ }),
609
+ ).toThrow(
610
+ "Receipt subtotal (30.00) does not match categorized items total (25.00)",
611
+ );
612
+ });
613
+
614
+ it("should reject when subtotal + tax does not match total", () => {
615
+ expect(() =>
616
+ CreateReceiptSplitTransactionSchema.parse({
617
+ ...validReceipt,
618
+ receipt_total: 30.0, // Should be 27.5
619
+ }),
620
+ ).toThrow(
621
+ "Receipt total (30.00) does not match subtotal plus tax (27.50)",
622
+ );
623
+ });
624
+
625
+ it("should allow small rounding differences (within tolerance)", () => {
626
+ // This should NOT throw because difference is less than 0.01 (0.001)
627
+ const result = CreateReceiptSplitTransactionSchema.parse({
628
+ budget_id: "budget-1",
629
+ account_id: "account-1",
630
+ payee_name: "Store",
631
+ receipt_subtotal: 25.001,
632
+ receipt_tax: 2.5,
633
+ receipt_total: 27.5,
634
+ categories: [
635
+ {
636
+ category_id: "cat-1",
637
+ items: [{ name: "Item", amount: 25.0 }],
638
+ },
639
+ ],
640
+ });
641
+ expect(result.receipt_subtotal).toBe(25.001);
642
+ });
643
+
644
+ it("should reject rounding differences exceeding 0.01", () => {
645
+ expect(() =>
646
+ CreateReceiptSplitTransactionSchema.parse({
647
+ budget_id: "budget-1",
648
+ account_id: "account-1",
649
+ payee_name: "Store",
650
+ receipt_subtotal: 25.02,
651
+ receipt_tax: 2.5,
652
+ receipt_total: 27.5,
653
+ categories: [
654
+ {
655
+ category_id: "cat-1",
656
+ items: [{ name: "Item", amount: 25.0 }],
657
+ },
658
+ ],
659
+ }),
660
+ ).toThrow(
661
+ "Receipt subtotal (25.02) does not match categorized items total (25.00)",
662
+ );
663
+ });
664
+
665
+ it("should reject negative receipt_subtotal", () => {
666
+ expect(() =>
667
+ CreateReceiptSplitTransactionSchema.parse({
668
+ ...validReceipt,
669
+ receipt_subtotal: -10.0,
670
+ }),
671
+ ).toThrow("Receipt subtotal must be zero or greater");
672
+ });
673
+
674
+ it("should accept zero receipt_subtotal with positive total", () => {
675
+ // receipt_total must be > 0, even if subtotal is 0 (e.g., all tax)
676
+ const result = CreateReceiptSplitTransactionSchema.parse({
677
+ budget_id: "budget-1",
678
+ account_id: "account-1",
679
+ payee_name: "Store",
680
+ receipt_subtotal: 0.0,
681
+ receipt_tax: 1.0,
682
+ receipt_total: 1.0,
683
+ categories: [
684
+ {
685
+ category_id: "cat-1",
686
+ items: [{ name: "Free item", amount: 0.0 }],
687
+ },
688
+ ],
689
+ });
690
+ expect(result.receipt_subtotal).toBe(0.0);
691
+ expect(result.receipt_total).toBe(1.0);
692
+ });
693
+
694
+ it("should reject zero or negative receipt_total", () => {
695
+ expect(() =>
696
+ CreateReceiptSplitTransactionSchema.parse({
697
+ ...validReceipt,
698
+ receipt_total: 0,
699
+ }),
700
+ ).toThrow("Receipt total must be greater than zero");
701
+
702
+ expect(() =>
703
+ CreateReceiptSplitTransactionSchema.parse({
704
+ ...validReceipt,
705
+ receipt_total: -10.0,
706
+ }),
707
+ ).toThrow("Receipt total must be greater than zero");
708
+ });
709
+
710
+ it("should reject Infinity values", () => {
711
+ expect(() =>
712
+ CreateReceiptSplitTransactionSchema.parse({
713
+ ...validReceipt,
714
+ receipt_tax: Number.POSITIVE_INFINITY,
715
+ }),
716
+ ).toThrow();
717
+
718
+ expect(() =>
719
+ CreateReceiptSplitTransactionSchema.parse({
720
+ ...validReceipt,
721
+ receipt_total: Number.POSITIVE_INFINITY,
722
+ }),
723
+ ).toThrow();
724
+ });
725
+
726
+ it("should reject NaN values", () => {
727
+ expect(() =>
728
+ CreateReceiptSplitTransactionSchema.parse({
729
+ ...validReceipt,
730
+ receipt_tax: Number.NaN,
731
+ }),
732
+ ).toThrow();
733
+ });
734
+
735
+ it("should reject empty categories array", () => {
736
+ expect(() =>
737
+ CreateReceiptSplitTransactionSchema.parse({
738
+ ...validReceipt,
739
+ categories: [],
740
+ }),
741
+ ).toThrow(
742
+ "At least one categorized group is required to create a split transaction",
743
+ );
744
+ });
745
+
746
+ it("should reject category with empty items array", () => {
747
+ expect(() =>
748
+ CreateReceiptSplitTransactionSchema.parse({
749
+ ...validReceipt,
750
+ categories: [
751
+ {
752
+ category_id: "cat-1",
753
+ items: [],
754
+ },
755
+ ],
756
+ }),
757
+ ).toThrow("Each category must include at least one item");
758
+ });
759
+
760
+ it("should reject item with empty name", () => {
761
+ expect(() =>
762
+ CreateReceiptSplitTransactionSchema.parse({
763
+ ...validReceipt,
764
+ categories: [
765
+ {
766
+ category_id: "cat-1",
767
+ items: [{ name: "", amount: 10.0 }],
768
+ },
769
+ ],
770
+ }),
771
+ ).toThrow("Item name is required");
772
+ });
773
+
774
+ it("should reject item with zero or negative quantity", () => {
775
+ expect(() =>
776
+ CreateReceiptSplitTransactionSchema.parse({
777
+ ...validReceipt,
778
+ categories: [
779
+ {
780
+ category_id: "cat-1",
781
+ items: [{ name: "Item", amount: 10.0, quantity: 0 }],
782
+ },
783
+ ],
784
+ }),
785
+ ).toThrow("Quantity must be greater than zero");
786
+
787
+ expect(() =>
788
+ CreateReceiptSplitTransactionSchema.parse({
789
+ ...validReceipt,
790
+ categories: [
791
+ {
792
+ category_id: "cat-1",
793
+ items: [{ name: "Item", amount: 10.0, quantity: -1 }],
794
+ },
795
+ ],
796
+ }),
797
+ ).toThrow("Quantity must be greater than zero");
798
+ });
799
+
800
+ it("should reject empty payee_name", () => {
801
+ expect(() =>
802
+ CreateReceiptSplitTransactionSchema.parse({
803
+ ...validReceipt,
804
+ payee_name: "",
805
+ }),
806
+ ).toThrow("Payee name is required");
807
+ });
808
+
809
+ it("should reject empty category_id", () => {
810
+ expect(() =>
811
+ CreateReceiptSplitTransactionSchema.parse({
812
+ ...validReceipt,
813
+ categories: [
814
+ {
815
+ category_id: "",
816
+ items: [{ name: "Item", amount: 25.0 }],
817
+ },
818
+ ],
819
+ }),
820
+ ).toThrow("Category ID is required");
821
+ });
822
+ });
823
+
824
+ describe("UpdateTransactionSchema", () => {
825
+ const validBase = {
826
+ budget_id: "budget-1",
827
+ transaction_id: "trans-1",
828
+ };
829
+
830
+ it("should validate with only required fields", () => {
831
+ const result = UpdateTransactionSchema.parse(validBase);
832
+ expect(result.budget_id).toBe("budget-1");
833
+ expect(result.transaction_id).toBe("trans-1");
834
+ });
835
+
836
+ it("should validate with all optional fields", () => {
837
+ const result = UpdateTransactionSchema.parse({
838
+ ...validBase,
839
+ account_id: "account-1",
840
+ amount: 15000,
841
+ date: "2024-01-20",
842
+ payee_name: "New Payee",
843
+ payee_id: "payee-2",
844
+ category_id: "cat-2",
845
+ memo: "Updated memo",
846
+ cleared: "reconciled",
847
+ approved: false,
848
+ flag_color: "purple",
849
+ dry_run: true,
850
+ });
851
+ expect(result.account_id).toBe("account-1");
852
+ expect(result.amount).toBe(15000);
853
+ expect(result.date).toBe("2024-01-20");
854
+ expect(result.memo).toBe("Updated memo");
855
+ expect(result.cleared).toBe("reconciled");
856
+ expect(result.approved).toBe(false);
857
+ expect(result.flag_color).toBe("purple");
858
+ expect(result.dry_run).toBe(true);
859
+ });
860
+
861
+ it("should reject non-integer amount", () => {
862
+ expect(() =>
863
+ UpdateTransactionSchema.parse({
864
+ ...validBase,
865
+ amount: 15.5,
866
+ }),
867
+ ).toThrow("Amount must be an integer in milliunits");
868
+ });
869
+
870
+ it("should reject invalid date format", () => {
871
+ expect(() =>
872
+ UpdateTransactionSchema.parse({
873
+ ...validBase,
874
+ date: "01/20/2024",
875
+ }),
876
+ ).toThrow("Date must be in ISO format (YYYY-MM-DD)");
877
+ });
878
+
879
+ it("should reject empty transaction_id", () => {
880
+ expect(() =>
881
+ UpdateTransactionSchema.parse({
882
+ budget_id: "budget-1",
883
+ transaction_id: "",
884
+ }),
885
+ ).toThrow("Transaction ID is required");
886
+ });
887
+
888
+ it("should reject extra fields", () => {
889
+ expect(() =>
890
+ UpdateTransactionSchema.parse({
891
+ ...validBase,
892
+ extra_field: "value",
893
+ }),
894
+ ).toThrow();
895
+ });
896
+ });
897
+
898
+ describe("UpdateTransactionsSchema", () => {
899
+ const validUpdate = {
900
+ id: "trans-1",
901
+ amount: 10000,
902
+ };
903
+
904
+ it("should validate with single update", () => {
905
+ const result = UpdateTransactionsSchema.parse({
906
+ budget_id: "budget-1",
907
+ transactions: [validUpdate],
908
+ });
909
+ expect(result.transactions).toHaveLength(1);
910
+ expect(result.transactions[0].id).toBe("trans-1");
911
+ });
912
+
913
+ it("should validate with multiple updates", () => {
914
+ const result = UpdateTransactionsSchema.parse({
915
+ budget_id: "budget-1",
916
+ transactions: [
917
+ validUpdate,
918
+ { id: "trans-2", memo: "Updated" },
919
+ { id: "trans-3", cleared: "cleared" },
920
+ ],
921
+ });
922
+ expect(result.transactions).toHaveLength(3);
923
+ });
924
+
925
+ it("should validate with all updatable fields", () => {
926
+ const result = UpdateTransactionsSchema.parse({
927
+ budget_id: "budget-1",
928
+ transactions: [
929
+ {
930
+ id: "trans-1",
931
+ amount: 20000,
932
+ date: "2024-02-01",
933
+ payee_name: "Updated Payee",
934
+ payee_id: "payee-3",
935
+ category_id: "cat-3",
936
+ memo: "Updated",
937
+ cleared: "uncleared",
938
+ approved: true,
939
+ flag_color: "yellow",
940
+ original_account_id: "account-1",
941
+ original_date: "2024-01-01",
942
+ },
943
+ ],
944
+ });
945
+ expect(result.transactions[0].amount).toBe(20000);
946
+ expect(result.transactions[0].original_account_id).toBe("account-1");
947
+ expect(result.transactions[0].original_date).toBe("2024-01-01");
948
+ });
949
+
950
+ it("should reject empty transactions array", () => {
951
+ expect(() =>
952
+ UpdateTransactionsSchema.parse({
953
+ budget_id: "budget-1",
954
+ transactions: [],
955
+ }),
956
+ ).toThrow("At least one transaction is required");
957
+ });
958
+
959
+ it("should reject more than 100 transactions", () => {
960
+ const updates = Array(101)
961
+ .fill(null)
962
+ .map((_, i) => ({
963
+ id: `trans-${i}`,
964
+ amount: 10000,
965
+ }));
966
+
967
+ expect(() =>
968
+ UpdateTransactionsSchema.parse({
969
+ budget_id: "budget-1",
970
+ transactions: updates,
971
+ }),
972
+ ).toThrow("A maximum of 100 transactions may be updated at once");
973
+ });
974
+
975
+ it("should accept exactly 100 transactions", () => {
976
+ const updates = Array(100)
977
+ .fill(null)
978
+ .map((_, i) => ({
979
+ id: `trans-${i}`,
980
+ amount: 10000,
981
+ }));
982
+
983
+ const result = UpdateTransactionsSchema.parse({
984
+ budget_id: "budget-1",
985
+ transactions: updates,
986
+ });
987
+ expect(result.transactions).toHaveLength(100);
988
+ });
989
+
990
+ it("should reject update with missing id", () => {
991
+ expect(() =>
992
+ UpdateTransactionsSchema.parse({
993
+ budget_id: "budget-1",
994
+ transactions: [{ amount: 10000 }],
995
+ }),
996
+ ).toThrow();
997
+ });
998
+
999
+ it("should reject update with empty id", () => {
1000
+ expect(() =>
1001
+ UpdateTransactionsSchema.parse({
1002
+ budget_id: "budget-1",
1003
+ transactions: [{ id: "", amount: 10000 }],
1004
+ }),
1005
+ ).toThrow("Transaction ID is required");
1006
+ });
1007
+
1008
+ it("should reject invalid original_date format", () => {
1009
+ expect(() =>
1010
+ UpdateTransactionsSchema.parse({
1011
+ budget_id: "budget-1",
1012
+ transactions: [
1013
+ {
1014
+ id: "trans-1",
1015
+ amount: 10000,
1016
+ original_date: "2024/01/01",
1017
+ },
1018
+ ],
1019
+ }),
1020
+ ).toThrow("Date must be in ISO format (YYYY-MM-DD)");
1021
+ });
1022
+
1023
+ it("should reject extra fields in update", () => {
1024
+ expect(() =>
1025
+ UpdateTransactionsSchema.parse({
1026
+ budget_id: "budget-1",
1027
+ transactions: [
1028
+ {
1029
+ id: "trans-1",
1030
+ extra_field: "value",
1031
+ },
1032
+ ],
1033
+ }),
1034
+ ).toThrow();
1035
+ });
1036
+ });
1037
+
1038
+ describe("DeleteTransactionSchema", () => {
1039
+ it("should validate with required fields", () => {
1040
+ const result = DeleteTransactionSchema.parse({
1041
+ budget_id: "budget-1",
1042
+ transaction_id: "trans-1",
1043
+ });
1044
+ expect(result.budget_id).toBe("budget-1");
1045
+ expect(result.transaction_id).toBe("trans-1");
1046
+ });
1047
+
1048
+ it("should validate with dry_run flag", () => {
1049
+ const result = DeleteTransactionSchema.parse({
1050
+ budget_id: "budget-1",
1051
+ transaction_id: "trans-1",
1052
+ dry_run: true,
1053
+ });
1054
+ expect(result.dry_run).toBe(true);
1055
+ });
1056
+
1057
+ it("should reject empty budget_id", () => {
1058
+ expect(() =>
1059
+ DeleteTransactionSchema.parse({
1060
+ budget_id: "",
1061
+ transaction_id: "trans-1",
1062
+ }),
1063
+ ).toThrow("Budget ID is required");
1064
+ });
1065
+
1066
+ it("should reject empty transaction_id", () => {
1067
+ expect(() =>
1068
+ DeleteTransactionSchema.parse({
1069
+ budget_id: "budget-1",
1070
+ transaction_id: "",
1071
+ }),
1072
+ ).toThrow("Transaction ID is required");
1073
+ });
1074
+
1075
+ it("should reject missing fields", () => {
1076
+ expect(() =>
1077
+ DeleteTransactionSchema.parse({ budget_id: "budget-1" }),
1078
+ ).toThrow();
1079
+ expect(() =>
1080
+ DeleteTransactionSchema.parse({ transaction_id: "trans-1" }),
1081
+ ).toThrow();
1082
+ });
1083
+
1084
+ it("should reject extra fields", () => {
1085
+ expect(() =>
1086
+ DeleteTransactionSchema.parse({
1087
+ budget_id: "budget-1",
1088
+ transaction_id: "trans-1",
1089
+ extra_field: "value",
1090
+ }),
1091
+ ).toThrow();
1092
+ });
1093
+ });
1094
+
1095
+ describe("Edge Cases", () => {
1096
+ it("should handle very large integer amounts", () => {
1097
+ const result = CreateTransactionSchema.parse({
1098
+ budget_id: "budget-1",
1099
+ account_id: "account-1",
1100
+ amount: 999999999999,
1101
+ date: "2024-01-15",
1102
+ });
1103
+ expect(result.amount).toBe(999999999999);
1104
+ });
1105
+
1106
+ it("should handle very large negative amounts", () => {
1107
+ const result = CreateTransactionSchema.parse({
1108
+ budget_id: "budget-1",
1109
+ account_id: "account-1",
1110
+ amount: -999999999999,
1111
+ date: "2024-01-15",
1112
+ });
1113
+ expect(result.amount).toBe(-999999999999);
1114
+ });
1115
+
1116
+ it("should handle boundary date values", () => {
1117
+ const dates = ["2024-01-01", "2024-12-31", "2000-01-01", "2099-12-31"];
1118
+
1119
+ dates.forEach((date) => {
1120
+ const result = CreateTransactionSchema.parse({
1121
+ budget_id: "budget-1",
1122
+ account_id: "account-1",
1123
+ amount: 1000,
1124
+ date,
1125
+ });
1126
+ expect(result.date).toBe(date);
1127
+ });
1128
+ });
1129
+
1130
+ it("should reject null values for required fields", () => {
1131
+ expect(() =>
1132
+ CreateTransactionSchema.parse({
1133
+ budget_id: "budget-1",
1134
+ account_id: "account-1",
1135
+ amount: null,
1136
+ date: "2024-01-15",
1137
+ }),
1138
+ ).toThrow();
1139
+ });
1140
+
1141
+ it("should reject undefined for required fields", () => {
1142
+ expect(() =>
1143
+ CreateTransactionSchema.parse({
1144
+ budget_id: "budget-1",
1145
+ account_id: "account-1",
1146
+ amount: undefined,
1147
+ date: "2024-01-15",
1148
+ }),
1149
+ ).toThrow();
1150
+ });
1151
+
1152
+ it("should handle very long string values", () => {
1153
+ const longString = "a".repeat(1000);
1154
+ const result = CreateTransactionSchema.parse({
1155
+ budget_id: "budget-1",
1156
+ account_id: "account-1",
1157
+ amount: 1000,
1158
+ date: "2024-01-15",
1159
+ memo: longString,
1160
+ });
1161
+ expect(result.memo).toBe(longString);
1162
+ });
1163
+
1164
+ it("should handle special characters in string fields", () => {
1165
+ const specialChars = "!@#$%^&*()_+-={}[]|\\:\";'<>?,./";
1166
+ const result = CreateTransactionSchema.parse({
1167
+ budget_id: "budget-1",
1168
+ account_id: "account-1",
1169
+ amount: 1000,
1170
+ date: "2024-01-15",
1171
+ payee_name: specialChars,
1172
+ memo: specialChars,
1173
+ });
1174
+ expect(result.payee_name).toBe(specialChars);
1175
+ expect(result.memo).toBe(specialChars);
1176
+ });
1177
+
1178
+ it("should handle unicode characters", () => {
1179
+ const unicode = "🏪 Café München 日本語";
1180
+ const result = CreateTransactionSchema.parse({
1181
+ budget_id: "budget-1",
1182
+ account_id: "account-1",
1183
+ amount: 1000,
1184
+ date: "2024-01-15",
1185
+ payee_name: unicode,
1186
+ });
1187
+ expect(result.payee_name).toBe(unicode);
1188
+ });
1189
+
1190
+ it("should handle empty strings for optional fields", () => {
1191
+ // Empty strings are allowed for optional string fields (they're just strings)
1192
+ const result = CreateTransactionSchema.parse({
1193
+ budget_id: "budget-1",
1194
+ account_id: "account-1",
1195
+ amount: 1000,
1196
+ date: "2024-01-15",
1197
+ memo: "",
1198
+ payee_name: "",
1199
+ });
1200
+ expect(result.memo).toBe("");
1201
+ expect(result.payee_name).toBe("");
1202
+ });
1203
+ });
1204
+ });