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