@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.
- package/CHANGELOG.md +17 -0
- package/CLAUDE.md +87 -8
- package/bin/ynab-mcp-server.cjs +2 -2
- package/bin/ynab-mcp-server.js +3 -3
- package/biome.json +39 -0
- package/dist/bundle/index.cjs +67 -67
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -27
- package/dist/server/YNABMCPServer.d.ts +3 -4
- package/dist/server/YNABMCPServer.js +111 -116
- package/dist/server/budgetResolver.d.ts +6 -5
- package/dist/server/budgetResolver.js +46 -36
- package/dist/server/cacheKeys.js +6 -6
- package/dist/server/cacheManager.js +14 -11
- package/dist/server/completions.d.ts +2 -2
- package/dist/server/completions.js +20 -15
- package/dist/server/config.d.ts +10 -5
- package/dist/server/config.js +24 -7
- package/dist/server/deltaCache.d.ts +2 -2
- package/dist/server/deltaCache.js +22 -16
- package/dist/server/deltaCache.merge.d.ts +2 -2
- package/dist/server/diagnostics.d.ts +4 -4
- package/dist/server/diagnostics.js +38 -32
- package/dist/server/errorHandler.d.ts +5 -12
- package/dist/server/errorHandler.js +219 -217
- package/dist/server/prompts.d.ts +2 -2
- package/dist/server/prompts.js +45 -45
- package/dist/server/rateLimiter.js +4 -4
- package/dist/server/requestLogger.d.ts +1 -1
- package/dist/server/requestLogger.js +40 -35
- package/dist/server/resources.d.ts +3 -3
- package/dist/server/resources.js +55 -52
- package/dist/server/responseFormatter.js +6 -6
- package/dist/server/securityMiddleware.d.ts +2 -2
- package/dist/server/securityMiddleware.js +22 -20
- package/dist/server/serverKnowledgeStore.js +1 -1
- package/dist/server/toolRegistry.d.ts +3 -3
- package/dist/server/toolRegistry.js +47 -40
- package/dist/tools/__tests__/deltaTestUtils.d.ts +3 -3
- package/dist/tools/__tests__/deltaTestUtils.js +2 -2
- package/dist/tools/accountTools.d.ts +9 -8
- package/dist/tools/accountTools.js +47 -47
- package/dist/tools/adapters.d.ts +13 -8
- package/dist/tools/adapters.js +21 -11
- package/dist/tools/budgetTools.d.ts +8 -7
- package/dist/tools/budgetTools.js +22 -22
- package/dist/tools/categoryTools.d.ts +9 -8
- package/dist/tools/categoryTools.js +68 -59
- package/dist/tools/compareTransactions/formatter.d.ts +3 -3
- package/dist/tools/compareTransactions/formatter.js +9 -9
- package/dist/tools/compareTransactions/index.d.ts +6 -6
- package/dist/tools/compareTransactions/index.js +58 -43
- package/dist/tools/compareTransactions/matcher.d.ts +1 -1
- package/dist/tools/compareTransactions/matcher.js +28 -15
- package/dist/tools/compareTransactions/parser.d.ts +2 -2
- package/dist/tools/compareTransactions/parser.js +144 -138
- package/dist/tools/compareTransactions/types.d.ts +4 -4
- package/dist/tools/compareTransactions.d.ts +1 -1
- package/dist/tools/compareTransactions.js +1 -1
- package/dist/tools/deltaFetcher.d.ts +2 -2
- package/dist/tools/deltaFetcher.js +16 -15
- package/dist/tools/deltaSupport.d.ts +4 -4
- package/dist/tools/deltaSupport.js +35 -41
- package/dist/tools/exportTransactions.d.ts +5 -4
- package/dist/tools/exportTransactions.js +61 -59
- package/dist/tools/monthTools.d.ts +7 -6
- package/dist/tools/monthTools.js +31 -29
- package/dist/tools/payeeTools.d.ts +7 -6
- package/dist/tools/payeeTools.js +28 -28
- package/dist/tools/reconcileAdapter.d.ts +2 -2
- package/dist/tools/reconcileAdapter.js +21 -11
- package/dist/tools/reconciliation/analyzer.d.ts +4 -4
- package/dist/tools/reconciliation/analyzer.js +136 -57
- package/dist/tools/reconciliation/csvParser.d.ts +3 -3
- package/dist/tools/reconciliation/csvParser.js +128 -104
- package/dist/tools/reconciliation/executor.d.ts +4 -4
- package/dist/tools/reconciliation/executor.js +148 -109
- package/dist/tools/reconciliation/index.d.ts +10 -10
- package/dist/tools/reconciliation/index.js +96 -83
- package/dist/tools/reconciliation/matcher.d.ts +3 -3
- package/dist/tools/reconciliation/matcher.js +17 -16
- package/dist/tools/reconciliation/payeeNormalizer.js +19 -8
- package/dist/tools/reconciliation/recommendationEngine.d.ts +1 -1
- package/dist/tools/reconciliation/recommendationEngine.js +40 -40
- package/dist/tools/reconciliation/reportFormatter.d.ts +2 -2
- package/dist/tools/reconciliation/reportFormatter.js +79 -54
- package/dist/tools/reconciliation/signDetector.d.ts +1 -1
- package/dist/tools/reconciliation/types.d.ts +19 -16
- package/dist/tools/reconciliation/ynabAdapter.d.ts +2 -2
- package/dist/tools/schemas/common.d.ts +1 -1
- package/dist/tools/schemas/common.js +1 -1
- package/dist/tools/schemas/outputs/accountOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/accountOutputs.js +24 -18
- package/dist/tools/schemas/outputs/budgetOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/budgetOutputs.js +14 -11
- package/dist/tools/schemas/outputs/categoryOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/categoryOutputs.js +49 -29
- package/dist/tools/schemas/outputs/comparisonOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/comparisonOutputs.js +12 -12
- package/dist/tools/schemas/outputs/index.d.ts +14 -14
- package/dist/tools/schemas/outputs/index.js +14 -14
- package/dist/tools/schemas/outputs/monthOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/monthOutputs.js +56 -41
- package/dist/tools/schemas/outputs/payeeOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/payeeOutputs.js +10 -10
- package/dist/tools/schemas/outputs/reconciliationOutputs.d.ts +2 -2
- package/dist/tools/schemas/outputs/reconciliationOutputs.js +45 -45
- package/dist/tools/schemas/outputs/transactionMutationOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/transactionMutationOutputs.js +28 -22
- package/dist/tools/schemas/outputs/transactionOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/transactionOutputs.js +43 -35
- package/dist/tools/schemas/outputs/utilityOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/utilityOutputs.js +5 -3
- package/dist/tools/schemas/shared/commonOutputs.d.ts +1 -1
- package/dist/tools/schemas/shared/commonOutputs.js +15 -9
- package/dist/tools/transactionReadTools.d.ts +11 -0
- package/dist/tools/transactionReadTools.js +202 -0
- package/dist/tools/transactionSchemas.d.ts +309 -0
- package/dist/tools/transactionSchemas.js +235 -0
- package/dist/tools/transactionTools.d.ts +6 -302
- package/dist/tools/transactionTools.js +7 -2054
- package/dist/tools/transactionUtils.d.ts +31 -0
- package/dist/tools/transactionUtils.js +364 -0
- package/dist/tools/transactionWriteTools.d.ts +20 -0
- package/dist/tools/transactionWriteTools.js +1342 -0
- package/dist/tools/utilityTools.d.ts +5 -4
- package/dist/tools/utilityTools.js +11 -11
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.js +6 -6
- package/dist/types/reconciliation.d.ts +1 -1
- package/dist/types/toolRegistration.d.ts +14 -12
- package/dist/utils/amountUtils.js +1 -1
- package/dist/utils/dateUtils.js +4 -4
- package/dist/utils/errors.d.ts +3 -3
- package/dist/utils/errors.js +4 -4
- package/dist/utils/money.d.ts +2 -2
- package/dist/utils/money.js +8 -8
- package/dist/utils/validationError.d.ts +1 -1
- package/dist/utils/validationError.js +1 -1
- package/docs/assets/examples/reconciliation-with-recommendations.json +66 -66
- package/docs/assets/schemas/reconciliation-v2.json +360 -336
- package/docs/plans/2025-12-25-transaction-tools-refactor-design.md +211 -0
- package/docs/plans/2025-12-25-transaction-tools-refactor.md +905 -0
- package/esbuild.config.mjs +53 -50
- package/meta.json +12548 -12548
- package/package.json +98 -109
- package/scripts/analyze-bundle.mjs +33 -30
- package/scripts/create-pr-description.js +169 -120
- package/scripts/run-all-tests.js +205 -0
- package/scripts/run-domain-integration-tests.js +28 -18
- package/scripts/run-generate-mcpb.js +19 -17
- package/scripts/run-throttled-integration-tests.js +92 -83
- package/scripts/test-delta-params.mjs +149 -120
- package/scripts/test-recommendations.ts +36 -32
- package/scripts/tmpTransaction.ts +80 -43
- package/scripts/validate-env.js +98 -91
- package/scripts/verify-build.js +78 -76
- package/src/__tests__/comprehensive.integration.test.ts +1281 -1154
- package/src/__tests__/performance.test.ts +723 -671
- package/src/__tests__/setup.ts +442 -395
- package/src/__tests__/smoke.e2e.test.ts +41 -39
- package/src/__tests__/testRunner.ts +314 -295
- package/src/__tests__/testUtils.ts +456 -364
- package/src/__tests__/tools/reconciliation/csvParser.integration.test.ts +109 -107
- package/src/__tests__/tools/reconciliation/real-world.integration.test.ts +41 -41
- package/src/index.ts +68 -59
- package/src/server/CLAUDE.md +480 -0
- package/src/server/YNABMCPServer.ts +821 -794
- package/src/server/__tests__/YNABMCPServer.integration.test.ts +929 -893
- package/src/server/__tests__/YNABMCPServer.test.ts +903 -899
- package/src/server/__tests__/budgetResolver.test.ts +466 -423
- package/src/server/__tests__/cacheManager.test.ts +891 -874
- package/src/server/__tests__/completions.integration.test.ts +115 -106
- package/src/server/__tests__/completions.test.ts +334 -313
- package/src/server/__tests__/config.test.ts +98 -86
- package/src/server/__tests__/deltaCache.merge.test.ts +774 -703
- package/src/server/__tests__/deltaCache.swr.test.ts +198 -153
- package/src/server/__tests__/deltaCache.test.ts +946 -759
- package/src/server/__tests__/diagnostics.test.ts +825 -792
- package/src/server/__tests__/errorHandler.integration.test.ts +512 -462
- package/src/server/__tests__/errorHandler.test.ts +402 -397
- package/src/server/__tests__/prompts.test.ts +424 -347
- package/src/server/__tests__/rateLimiter.test.ts +313 -309
- package/src/server/__tests__/requestLogger.test.ts +443 -403
- package/src/server/__tests__/resources.template.test.ts +196 -185
- package/src/server/__tests__/resources.test.ts +294 -288
- package/src/server/__tests__/security.integration.test.ts +487 -421
- package/src/server/__tests__/securityMiddleware.test.ts +519 -444
- package/src/server/__tests__/server-startup.integration.test.ts +509 -490
- package/src/server/__tests__/serverKnowledgeStore.test.ts +174 -173
- package/src/server/__tests__/toolRegistration.test.ts +239 -210
- package/src/server/__tests__/toolRegistry.test.ts +907 -845
- package/src/server/budgetResolver.ts +221 -181
- package/src/server/cacheKeys.ts +6 -6
- package/src/server/cacheManager.ts +498 -484
- package/src/server/completions.ts +267 -243
- package/src/server/config.ts +35 -14
- package/src/server/deltaCache.merge.ts +146 -128
- package/src/server/deltaCache.ts +352 -309
- package/src/server/diagnostics.ts +257 -242
- package/src/server/errorHandler.ts +747 -744
- package/src/server/prompts.ts +181 -176
- package/src/server/rateLimiter.ts +131 -129
- package/src/server/requestLogger.ts +350 -322
- package/src/server/resources.ts +442 -374
- package/src/server/responseFormatter.ts +41 -37
- package/src/server/securityMiddleware.ts +223 -205
- package/src/server/serverKnowledgeStore.ts +67 -67
- package/src/server/toolRegistry.ts +508 -474
- package/src/tools/CLAUDE.md +604 -0
- package/src/tools/__tests__/accountTools.delta.integration.test.ts +128 -111
- package/src/tools/__tests__/accountTools.integration.test.ts +129 -111
- package/src/tools/__tests__/accountTools.test.ts +685 -638
- package/src/tools/__tests__/adapters.test.ts +142 -108
- package/src/tools/__tests__/budgetTools.delta.integration.test.ts +73 -73
- package/src/tools/__tests__/budgetTools.integration.test.ts +132 -124
- package/src/tools/__tests__/budgetTools.test.ts +442 -413
- package/src/tools/__tests__/categoryTools.delta.integration.test.ts +76 -68
- package/src/tools/__tests__/categoryTools.integration.test.ts +314 -288
- package/src/tools/__tests__/categoryTools.test.ts +656 -625
- package/src/tools/__tests__/compareTransactions/formatter.test.ts +535 -462
- package/src/tools/__tests__/compareTransactions/index.test.ts +378 -358
- package/src/tools/__tests__/compareTransactions/matcher.test.ts +497 -398
- package/src/tools/__tests__/compareTransactions/parser.test.ts +765 -747
- package/src/tools/__tests__/compareTransactions.test.ts +352 -332
- package/src/tools/__tests__/compareTransactions.window.test.ts +150 -146
- package/src/tools/__tests__/deltaFetcher.scheduled.integration.test.ts +69 -65
- package/src/tools/__tests__/deltaFetcher.test.ts +325 -265
- package/src/tools/__tests__/deltaSupport.test.ts +211 -184
- package/src/tools/__tests__/deltaTestUtils.ts +37 -33
- package/src/tools/__tests__/exportTransactions.test.ts +205 -200
- package/src/tools/__tests__/monthTools.delta.integration.test.ts +68 -68
- package/src/tools/__tests__/monthTools.integration.test.ts +178 -166
- package/src/tools/__tests__/monthTools.test.ts +561 -512
- package/src/tools/__tests__/payeeTools.delta.integration.test.ts +68 -68
- package/src/tools/__tests__/payeeTools.integration.test.ts +158 -142
- package/src/tools/__tests__/payeeTools.test.ts +486 -434
- package/src/tools/__tests__/transactionSchemas.test.ts +1204 -0
- package/src/tools/__tests__/transactionTools.integration.test.ts +875 -825
- package/src/tools/__tests__/transactionTools.test.ts +4923 -4366
- package/src/tools/__tests__/transactionUtils.test.ts +1016 -0
- package/src/tools/__tests__/utilityTools.integration.test.ts +32 -32
- package/src/tools/__tests__/utilityTools.test.ts +68 -58
- package/src/tools/accountTools.ts +293 -271
- package/src/tools/adapters.ts +120 -63
- package/src/tools/budgetTools.ts +121 -116
- package/src/tools/categoryTools.ts +379 -339
- package/src/tools/compareTransactions/formatter.ts +131 -119
- package/src/tools/compareTransactions/index.ts +249 -214
- package/src/tools/compareTransactions/matcher.ts +259 -209
- package/src/tools/compareTransactions/parser.ts +517 -487
- package/src/tools/compareTransactions/types.ts +38 -38
- package/src/tools/compareTransactions.ts +1 -1
- package/src/tools/deltaFetcher.ts +281 -260
- package/src/tools/deltaSupport.ts +264 -259
- package/src/tools/exportTransactions.ts +230 -218
- package/src/tools/monthTools.ts +180 -165
- package/src/tools/payeeTools.ts +152 -140
- package/src/tools/reconcileAdapter.ts +297 -246
- package/src/tools/reconciliation/CLAUDE.md +506 -0
- package/src/tools/reconciliation/__tests__/adapter.causes.test.ts +135 -112
- package/src/tools/reconciliation/__tests__/adapter.test.ts +249 -227
- package/src/tools/reconciliation/__tests__/analyzer.test.ts +408 -335
- package/src/tools/reconciliation/__tests__/csvParser.test.ts +71 -69
- package/src/tools/reconciliation/__tests__/executor.integration.test.ts +348 -323
- package/src/tools/reconciliation/__tests__/executor.progress.test.ts +503 -457
- package/src/tools/reconciliation/__tests__/executor.test.ts +898 -831
- package/src/tools/reconciliation/__tests__/matcher.test.ts +667 -663
- package/src/tools/reconciliation/__tests__/payeeNormalizer.test.ts +296 -276
- package/src/tools/reconciliation/__tests__/recommendationEngine.integration.test.ts +692 -624
- package/src/tools/reconciliation/__tests__/recommendationEngine.test.ts +1008 -986
- package/src/tools/reconciliation/__tests__/reconciliation.delta.integration.test.ts +187 -146
- package/src/tools/reconciliation/__tests__/reportFormatter.test.ts +583 -530
- package/src/tools/reconciliation/__tests__/scenarios/adapterCurrency.scenario.test.ts +75 -71
- package/src/tools/reconciliation/__tests__/scenarios/extremes.scenario.test.ts +70 -58
- package/src/tools/reconciliation/__tests__/scenarios/repeatAmount.scenario.test.ts +102 -88
- package/src/tools/reconciliation/__tests__/schemaUrl.test.ts +58 -43
- package/src/tools/reconciliation/__tests__/signDetector.test.ts +209 -206
- package/src/tools/reconciliation/__tests__/ynabAdapter.test.ts +66 -60
- package/src/tools/reconciliation/analyzer.ts +582 -406
- package/src/tools/reconciliation/csvParser.ts +656 -609
- package/src/tools/reconciliation/executor.ts +1290 -1128
- package/src/tools/reconciliation/index.ts +580 -528
- package/src/tools/reconciliation/matcher.ts +256 -240
- package/src/tools/reconciliation/payeeNormalizer.ts +92 -78
- package/src/tools/reconciliation/recommendationEngine.ts +357 -345
- package/src/tools/reconciliation/reportFormatter.ts +349 -276
- package/src/tools/reconciliation/signDetector.ts +89 -83
- package/src/tools/reconciliation/types.ts +164 -153
- package/src/tools/reconciliation/ynabAdapter.ts +17 -15
- package/src/tools/schemas/CLAUDE.md +546 -0
- package/src/tools/schemas/common.ts +1 -1
- package/src/tools/schemas/outputs/__tests__/accountOutputs.test.ts +410 -409
- package/src/tools/schemas/outputs/__tests__/budgetOutputs.test.ts +305 -299
- package/src/tools/schemas/outputs/__tests__/categoryOutputs.test.ts +431 -430
- package/src/tools/schemas/outputs/__tests__/comparisonOutputs.test.ts +510 -495
- package/src/tools/schemas/outputs/__tests__/dateValidation.test.ts +179 -153
- package/src/tools/schemas/outputs/__tests__/discrepancyDirection.test.ts +293 -254
- package/src/tools/schemas/outputs/__tests__/monthOutputs.test.ts +457 -457
- package/src/tools/schemas/outputs/__tests__/payeeOutputs.test.ts +362 -356
- package/src/tools/schemas/outputs/__tests__/reconciliationOutputs.test.ts +402 -399
- package/src/tools/schemas/outputs/__tests__/transactionMutationSchemas.test.ts +225 -211
- package/src/tools/schemas/outputs/__tests__/transactionOutputs.test.ts +457 -454
- package/src/tools/schemas/outputs/__tests__/utilityOutputs.test.ts +316 -315
- package/src/tools/schemas/outputs/accountOutputs.ts +40 -34
- package/src/tools/schemas/outputs/budgetOutputs.ts +24 -19
- package/src/tools/schemas/outputs/categoryOutputs.ts +76 -56
- package/src/tools/schemas/outputs/comparisonOutputs.ts +192 -169
- package/src/tools/schemas/outputs/index.ts +163 -163
- package/src/tools/schemas/outputs/monthOutputs.ts +95 -80
- package/src/tools/schemas/outputs/payeeOutputs.ts +18 -18
- package/src/tools/schemas/outputs/reconciliationOutputs.ts +386 -373
- package/src/tools/schemas/outputs/transactionMutationOutputs.ts +259 -231
- package/src/tools/schemas/outputs/transactionOutputs.ts +81 -71
- package/src/tools/schemas/outputs/utilityOutputs.ts +90 -84
- package/src/tools/schemas/shared/commonOutputs.ts +27 -19
- package/src/tools/toolCategories.ts +114 -114
- package/src/tools/transactionReadTools.ts +327 -0
- package/src/tools/transactionSchemas.ts +484 -0
- package/src/tools/transactionTools.ts +107 -2990
- package/src/tools/transactionUtils.ts +621 -0
- package/src/tools/transactionWriteTools.ts +2110 -0
- package/src/tools/utilityTools.ts +46 -41
- package/src/types/CLAUDE.md +477 -0
- package/src/types/__tests__/index.test.ts +51 -51
- package/src/types/index.ts +43 -39
- package/src/types/integration-tests.d.ts +26 -26
- package/src/types/reconciliation.ts +29 -29
- package/src/types/toolAnnotations.ts +30 -30
- package/src/types/toolRegistration.ts +43 -32
- package/src/utils/CLAUDE.md +508 -0
- package/src/utils/__tests__/dateUtils.test.ts +174 -168
- package/src/utils/__tests__/money.test.ts +193 -187
- package/src/utils/amountUtils.ts +5 -5
- package/src/utils/baseError.ts +5 -5
- package/src/utils/dateUtils.ts +29 -26
- package/src/utils/errors.ts +14 -14
- package/src/utils/money.ts +66 -52
- package/src/utils/validationError.ts +1 -1
- package/tsconfig.json +29 -29
- package/tsconfig.prod.json +16 -16
- package/vitest-reporters/split-json-reporter.ts +247 -204
- package/vitest.config.ts +99 -95
- package/.prettierignore +0 -10
- package/.prettierrc.json +0 -10
- package/eslint.config.js +0 -49
|
@@ -1,1007 +1,1029 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
import {
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { toMoneyValueFromDecimal } from "../../../utils/money.js";
|
|
3
|
+
import { generateRecommendations } from "../recommendationEngine.js";
|
|
3
4
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from
|
|
16
|
-
import { toMoneyValueFromDecimal } from '../../../utils/money.js';
|
|
5
|
+
BankTransaction,
|
|
6
|
+
CreateTransactionRecommendation,
|
|
7
|
+
ManualReviewRecommendation,
|
|
8
|
+
MoneyValue,
|
|
9
|
+
RecommendationContext,
|
|
10
|
+
ReconciliationAnalysis,
|
|
11
|
+
ReconciliationInsight,
|
|
12
|
+
ReviewDuplicateRecommendation,
|
|
13
|
+
TransactionMatch,
|
|
14
|
+
UpdateClearedRecommendation,
|
|
15
|
+
YNABTransaction,
|
|
16
|
+
} from "../types.js";
|
|
17
17
|
|
|
18
18
|
// Helper to create MoneyValue objects
|
|
19
|
-
const makeMoney = (value: number, currency =
|
|
20
|
-
|
|
19
|
+
const makeMoney = (value: number, currency = "USD"): MoneyValue => {
|
|
20
|
+
return toMoneyValueFromDecimal(value, currency);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
// Helper to create minimal mock context
|
|
24
|
-
const createMockContext = (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
24
|
+
const createMockContext = (
|
|
25
|
+
overrides?: Partial<RecommendationContext>,
|
|
26
|
+
): RecommendationContext => {
|
|
27
|
+
const defaultAnalysis: ReconciliationAnalysis = {
|
|
28
|
+
success: true,
|
|
29
|
+
phase: "analysis",
|
|
30
|
+
matches: [],
|
|
31
|
+
auto_matches: [],
|
|
32
|
+
suggested_matches: [],
|
|
33
|
+
unmatched_bank: [],
|
|
34
|
+
unmatched_ynab: [],
|
|
35
|
+
ynab_outside_date_range: [],
|
|
36
|
+
balance_info: {
|
|
37
|
+
current_cleared: makeMoney(100),
|
|
38
|
+
current_uncleared: makeMoney(0),
|
|
39
|
+
current_total: makeMoney(100),
|
|
40
|
+
target_statement: makeMoney(100),
|
|
41
|
+
discrepancy: makeMoney(0),
|
|
42
|
+
on_track: true,
|
|
43
|
+
},
|
|
44
|
+
summary: {
|
|
45
|
+
statement_date_range: "2024-01-01 to 2024-01-31",
|
|
46
|
+
bank_transactions_count: 0,
|
|
47
|
+
ynab_transactions_count: 0,
|
|
48
|
+
ynab_in_range_count: 0,
|
|
49
|
+
ynab_outside_range_count: 0,
|
|
50
|
+
auto_matched: 0,
|
|
51
|
+
suggested_matches: 0,
|
|
52
|
+
unmatched_bank: 0,
|
|
53
|
+
unmatched_ynab: 0,
|
|
54
|
+
current_cleared_balance: makeMoney(100),
|
|
55
|
+
target_statement_balance: makeMoney(100),
|
|
56
|
+
discrepancy: makeMoney(0),
|
|
57
|
+
discrepancy_explanation: "Balanced",
|
|
58
|
+
},
|
|
59
|
+
insights: [],
|
|
60
|
+
next_steps: [],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
account_id: "test-account-id",
|
|
65
|
+
budget_id: "test-budget-id",
|
|
66
|
+
analysis: defaultAnalysis,
|
|
67
|
+
matching_config: {
|
|
68
|
+
amountToleranceCents: 1,
|
|
69
|
+
dateToleranceDays: 2,
|
|
70
|
+
descriptionSimilarityThreshold: 0.8,
|
|
71
|
+
autoMatchThreshold: 90,
|
|
72
|
+
suggestionThreshold: 60,
|
|
73
|
+
},
|
|
74
|
+
...overrides,
|
|
75
|
+
};
|
|
71
76
|
};
|
|
72
77
|
|
|
73
78
|
// Helper to create mock bank transaction
|
|
74
79
|
// NOTE: amount overrides are provided in DECIMAL units (dollars) and converted to milliunits
|
|
75
|
-
const createBankTransaction = (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
const createBankTransaction = (
|
|
81
|
+
overrides?: Partial<BankTransaction>,
|
|
82
|
+
): BankTransaction => {
|
|
83
|
+
const { amount, ...restOverrides } = overrides ?? {};
|
|
84
|
+
const baseAmount = amount ?? -50.0; // dollars
|
|
85
|
+
const amountMilli = Math.round(baseAmount * 1000); // milliunits
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
id: "bank-txn-1",
|
|
89
|
+
date: "2024-01-15",
|
|
90
|
+
amount: amountMilli,
|
|
91
|
+
payee: "Test Store",
|
|
92
|
+
memo: "Test memo",
|
|
93
|
+
original_csv_row: 1,
|
|
94
|
+
...restOverrides,
|
|
95
|
+
};
|
|
89
96
|
};
|
|
90
97
|
|
|
91
98
|
// Helper to create mock YNAB transaction
|
|
92
|
-
const createYNABTransaction = (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
const createYNABTransaction = (
|
|
100
|
+
overrides?: Partial<YNABTransaction>,
|
|
101
|
+
): YNABTransaction => ({
|
|
102
|
+
id: "ynab-txn-1",
|
|
103
|
+
date: "2024-01-15",
|
|
104
|
+
amount: -50000,
|
|
105
|
+
payee_name: "Test Store",
|
|
106
|
+
category_name: "Shopping",
|
|
107
|
+
cleared: "uncleared",
|
|
108
|
+
approved: true,
|
|
109
|
+
memo: "Test memo",
|
|
110
|
+
...overrides,
|
|
102
111
|
});
|
|
103
112
|
|
|
104
113
|
// Helper to create mock insight
|
|
105
114
|
const createInsight = (
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
type: ReconciliationInsight["type"],
|
|
116
|
+
severity: ReconciliationInsight["severity"] = "info",
|
|
108
117
|
): ReconciliationInsight => ({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
id: `insight-${type}-1`,
|
|
119
|
+
type,
|
|
120
|
+
severity,
|
|
121
|
+
title: `Test ${type} insight`,
|
|
122
|
+
description: `This is a test ${type} insight`,
|
|
123
|
+
evidence: {},
|
|
115
124
|
});
|
|
116
125
|
|
|
117
|
-
describe(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
126
|
+
describe("recommendationEngine", () => {
|
|
127
|
+
describe("generateRecommendations", () => {
|
|
128
|
+
describe("empty context scenarios", () => {
|
|
129
|
+
it("should return empty array for completely empty context", () => {
|
|
130
|
+
const context = createMockContext();
|
|
131
|
+
const recommendations = generateRecommendations(context);
|
|
132
|
+
expect(recommendations).toEqual([]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should return empty array with no insights and no unmatched transactions", () => {
|
|
136
|
+
const context = createMockContext({
|
|
137
|
+
analysis: {
|
|
138
|
+
...createMockContext().analysis,
|
|
139
|
+
insights: [],
|
|
140
|
+
unmatched_bank: [],
|
|
141
|
+
unmatched_ynab: [],
|
|
142
|
+
suggested_matches: [],
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
const recommendations = generateRecommendations(context);
|
|
146
|
+
expect(recommendations).toEqual([]);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("insight processing", () => {
|
|
151
|
+
it("should process near_match insights", () => {
|
|
152
|
+
const insight = createInsight("near_match", "warning");
|
|
153
|
+
const context = createMockContext({
|
|
154
|
+
analysis: {
|
|
155
|
+
...createMockContext().analysis,
|
|
156
|
+
insights: [insight],
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const recommendations = generateRecommendations(context);
|
|
161
|
+
|
|
162
|
+
expect(recommendations).toHaveLength(1);
|
|
163
|
+
const rec = recommendations[0] as ManualReviewRecommendation;
|
|
164
|
+
expect(rec.action_type).toBe("manual_review");
|
|
165
|
+
expect(rec.priority).toBe("medium");
|
|
166
|
+
expect(rec.confidence).toBe(0.7); // CONFIDENCE.NEAR_MATCH_REVIEW
|
|
167
|
+
expect(rec.source_insight_id).toBe(insight.id);
|
|
168
|
+
expect(rec.parameters.issue_type).toBe("complex_match");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("should process repeat_amount insights", () => {
|
|
172
|
+
const insight = createInsight("repeat_amount", "info");
|
|
173
|
+
const context = createMockContext({
|
|
174
|
+
analysis: {
|
|
175
|
+
...createMockContext().analysis,
|
|
176
|
+
insights: [insight],
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const recommendations = generateRecommendations(context);
|
|
181
|
+
|
|
182
|
+
expect(recommendations).toHaveLength(1);
|
|
183
|
+
const rec = recommendations[0] as ManualReviewRecommendation;
|
|
184
|
+
expect(rec.action_type).toBe("manual_review");
|
|
185
|
+
expect(rec.priority).toBe("medium");
|
|
186
|
+
expect(rec.confidence).toBe(0.75); // CONFIDENCE.REPEAT_AMOUNT
|
|
187
|
+
expect(rec.source_insight_id).toBe(insight.id);
|
|
188
|
+
expect(rec.message).toContain("recurring pattern");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should process anomaly insights", () => {
|
|
192
|
+
const insight = createInsight("anomaly", "warning");
|
|
193
|
+
const context = createMockContext({
|
|
194
|
+
analysis: {
|
|
195
|
+
...createMockContext().analysis,
|
|
196
|
+
insights: [insight],
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const recommendations = generateRecommendations(context);
|
|
201
|
+
|
|
202
|
+
expect(recommendations).toHaveLength(1);
|
|
203
|
+
const rec = recommendations[0] as ManualReviewRecommendation;
|
|
204
|
+
expect(rec.action_type).toBe("manual_review");
|
|
205
|
+
expect(rec.priority).toBe("low");
|
|
206
|
+
expect(rec.confidence).toBe(0.5); // CONFIDENCE.ANOMALY_REVIEW
|
|
207
|
+
expect(rec.source_insight_id).toBe(insight.id);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("should process critical anomaly insights with higher severity", () => {
|
|
211
|
+
const insight = createInsight("anomaly", "critical");
|
|
212
|
+
const context = createMockContext({
|
|
213
|
+
analysis: {
|
|
214
|
+
...createMockContext().analysis,
|
|
215
|
+
insights: [insight],
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const recommendations = generateRecommendations(context);
|
|
220
|
+
|
|
221
|
+
expect(recommendations).toHaveLength(1);
|
|
222
|
+
const rec = recommendations[0] as ManualReviewRecommendation;
|
|
223
|
+
expect(rec.action_type).toBe("manual_review");
|
|
224
|
+
expect(rec.parameters.issue_type).toBe("large_discrepancy");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("should process multiple insights", () => {
|
|
228
|
+
const insights = [
|
|
229
|
+
createInsight("near_match", "warning"),
|
|
230
|
+
createInsight("repeat_amount", "info"),
|
|
231
|
+
createInsight("anomaly", "warning"),
|
|
232
|
+
];
|
|
233
|
+
const context = createMockContext({
|
|
234
|
+
analysis: {
|
|
235
|
+
...createMockContext().analysis,
|
|
236
|
+
insights,
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const recommendations = generateRecommendations(context);
|
|
241
|
+
|
|
242
|
+
expect(recommendations).toHaveLength(3);
|
|
243
|
+
expect(recommendations.map((r) => r.action_type)).toEqual([
|
|
244
|
+
"manual_review",
|
|
245
|
+
"manual_review",
|
|
246
|
+
"manual_review",
|
|
247
|
+
]);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe("unmatched bank transactions", () => {
|
|
252
|
+
it("should create create_transaction recommendation for unmatched bank transaction", () => {
|
|
253
|
+
const bankTxn = createBankTransaction({
|
|
254
|
+
id: "bank-1",
|
|
255
|
+
amount: -75.5,
|
|
256
|
+
payee: "Coffee Shop",
|
|
257
|
+
date: "2024-01-20",
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const context = createMockContext({
|
|
261
|
+
analysis: {
|
|
262
|
+
...createMockContext().analysis,
|
|
263
|
+
unmatched_bank: [bankTxn],
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
const recommendations = generateRecommendations(context);
|
|
268
|
+
|
|
269
|
+
expect(recommendations).toHaveLength(1);
|
|
270
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
271
|
+
expect(rec.action_type).toBe("create_transaction");
|
|
272
|
+
expect(rec.priority).toBe("medium");
|
|
273
|
+
expect(rec.confidence).toBe(0.8); // CONFIDENCE.UNMATCHED_BANK
|
|
274
|
+
expect(rec.parameters.account_id).toBe("test-account-id");
|
|
275
|
+
expect(rec.parameters.date).toBe("2024-01-20");
|
|
276
|
+
expect(rec.parameters.amount).toBe(-75500); // In milliunits
|
|
277
|
+
expect(rec.parameters.payee_name).toBe("Coffee Shop");
|
|
278
|
+
expect(rec.parameters.cleared).toBe("cleared");
|
|
279
|
+
expect(rec.parameters.approved).toBe(true);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("should include memo if present in bank transaction", () => {
|
|
283
|
+
const bankTxn = createBankTransaction({
|
|
284
|
+
memo: "Business expense",
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const context = createMockContext({
|
|
288
|
+
analysis: {
|
|
289
|
+
...createMockContext().analysis,
|
|
290
|
+
unmatched_bank: [bankTxn],
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const recommendations = generateRecommendations(context);
|
|
295
|
+
|
|
296
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
297
|
+
expect(rec.parameters.memo).toBe("Business expense");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should not include memo if not present in bank transaction", () => {
|
|
301
|
+
const bankTxn = createBankTransaction();
|
|
302
|
+
bankTxn.memo = undefined;
|
|
303
|
+
|
|
304
|
+
const context = createMockContext({
|
|
305
|
+
analysis: {
|
|
306
|
+
...createMockContext().analysis,
|
|
307
|
+
unmatched_bank: [bankTxn],
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const recommendations = generateRecommendations(context);
|
|
312
|
+
|
|
313
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
314
|
+
expect(rec.parameters.memo).toBeUndefined();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("should create recommendations for multiple unmatched bank transactions", () => {
|
|
318
|
+
const bankTxns = [
|
|
319
|
+
createBankTransaction({ id: "b1", amount: -10.0 }),
|
|
320
|
+
createBankTransaction({ id: "b2", amount: -20.0 }),
|
|
321
|
+
createBankTransaction({ id: "b3", amount: -30.0 }),
|
|
322
|
+
];
|
|
323
|
+
|
|
324
|
+
const context = createMockContext({
|
|
325
|
+
analysis: {
|
|
326
|
+
...createMockContext().analysis,
|
|
327
|
+
unmatched_bank: bankTxns,
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const recommendations = generateRecommendations(context);
|
|
332
|
+
|
|
333
|
+
expect(recommendations).toHaveLength(3);
|
|
334
|
+
expect(
|
|
335
|
+
recommendations.every((r) => r.action_type === "create_transaction"),
|
|
336
|
+
).toBe(true);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
describe("unmatched YNAB transactions", () => {
|
|
341
|
+
it("should create update_cleared recommendation for uncleared YNAB transaction", () => {
|
|
342
|
+
const ynabTxn = createYNABTransaction({
|
|
343
|
+
id: "ynab-1",
|
|
344
|
+
cleared: "uncleared",
|
|
345
|
+
payee_name: "Restaurant",
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
const context = createMockContext({
|
|
349
|
+
analysis: {
|
|
350
|
+
...createMockContext().analysis,
|
|
351
|
+
unmatched_ynab: [ynabTxn],
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const recommendations = generateRecommendations(context);
|
|
356
|
+
|
|
357
|
+
expect(recommendations).toHaveLength(1);
|
|
358
|
+
const rec = recommendations[0] as UpdateClearedRecommendation;
|
|
359
|
+
expect(rec.action_type).toBe("update_cleared");
|
|
360
|
+
expect(rec.priority).toBe("low");
|
|
361
|
+
expect(rec.confidence).toBe(0.6); // CONFIDENCE.UPDATE_CLEARED
|
|
362
|
+
expect(rec.parameters.transaction_id).toBe("ynab-1");
|
|
363
|
+
expect(rec.parameters.cleared).toBe("cleared");
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("should not create recommendation for already cleared YNAB transaction", () => {
|
|
367
|
+
const ynabTxn = createYNABTransaction({
|
|
368
|
+
cleared: "cleared",
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
const context = createMockContext({
|
|
372
|
+
analysis: {
|
|
373
|
+
...createMockContext().analysis,
|
|
374
|
+
unmatched_ynab: [ynabTxn],
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
const recommendations = generateRecommendations(context);
|
|
379
|
+
|
|
380
|
+
expect(recommendations).toHaveLength(0);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("should not create recommendation for reconciled YNAB transaction", () => {
|
|
384
|
+
const ynabTxn = createYNABTransaction({
|
|
385
|
+
cleared: "reconciled",
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const context = createMockContext({
|
|
389
|
+
analysis: {
|
|
390
|
+
...createMockContext().analysis,
|
|
391
|
+
unmatched_ynab: [ynabTxn],
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
const recommendations = generateRecommendations(context);
|
|
396
|
+
|
|
397
|
+
expect(recommendations).toHaveLength(0);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("should handle null payee_name in YNAB transaction", () => {
|
|
401
|
+
const ynabTxn = createYNABTransaction({
|
|
402
|
+
cleared: "uncleared",
|
|
403
|
+
payee_name: null,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const context = createMockContext({
|
|
407
|
+
analysis: {
|
|
408
|
+
...createMockContext().analysis,
|
|
409
|
+
unmatched_ynab: [ynabTxn],
|
|
410
|
+
},
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const recommendations = generateRecommendations(context);
|
|
414
|
+
|
|
415
|
+
expect(recommendations).toHaveLength(1);
|
|
416
|
+
const rec = recommendations[0] as UpdateClearedRecommendation;
|
|
417
|
+
expect(rec.message).toContain("Unknown");
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
describe("suggested matches", () => {
|
|
422
|
+
it("should create review_duplicate recommendation for suggested match", () => {
|
|
423
|
+
const bankTxn = createBankTransaction();
|
|
424
|
+
const ynabTxn = createYNABTransaction();
|
|
425
|
+
|
|
426
|
+
const suggestedMatch: TransactionMatch = {
|
|
427
|
+
bankTransaction: bankTxn,
|
|
428
|
+
ynabTransaction: ynabTxn,
|
|
429
|
+
confidence: "medium",
|
|
430
|
+
confidenceScore: 75,
|
|
431
|
+
matchReason: "Fuzzy payee match",
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const context = createMockContext({
|
|
435
|
+
analysis: {
|
|
436
|
+
...createMockContext().analysis,
|
|
437
|
+
suggested_matches: [suggestedMatch],
|
|
438
|
+
},
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
const recommendations = generateRecommendations(context);
|
|
442
|
+
|
|
443
|
+
expect(recommendations).toHaveLength(1);
|
|
444
|
+
const rec = recommendations[0] as ReviewDuplicateRecommendation;
|
|
445
|
+
expect(rec.action_type).toBe("review_duplicate");
|
|
446
|
+
expect(rec.priority).toBe("high");
|
|
447
|
+
expect(rec.confidence).toBe(0.75); // confidence_score / 100
|
|
448
|
+
expect(rec.parameters.candidate_ids).toContain(ynabTxn.id);
|
|
449
|
+
expect(rec.parameters.suggested_match_id).toBe(ynabTxn.id);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it("should create create_transaction for suggested match with no YNAB transaction", () => {
|
|
453
|
+
const bankTxn = createBankTransaction({ amount: -45.0 });
|
|
454
|
+
|
|
455
|
+
const suggestedMatch: TransactionMatch = {
|
|
456
|
+
bankTransaction: bankTxn,
|
|
457
|
+
confidence: "none",
|
|
458
|
+
confidenceScore: 0,
|
|
459
|
+
matchReason: "No match found",
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
const context = createMockContext({
|
|
463
|
+
analysis: {
|
|
464
|
+
...createMockContext().analysis,
|
|
465
|
+
suggested_matches: [suggestedMatch],
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
const recommendations = generateRecommendations(context);
|
|
470
|
+
|
|
471
|
+
expect(recommendations).toHaveLength(1);
|
|
472
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
473
|
+
expect(rec.action_type).toBe("create_transaction");
|
|
474
|
+
expect(rec.priority).toBe("high");
|
|
475
|
+
expect(rec.confidence).toBe(0.95); // CONFIDENCE.CREATE_EXACT_MATCH
|
|
476
|
+
expect(rec.parameters.amount).toBe(-45000); // In milliunits
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it("should create manual_review for combination match with multiple candidates", () => {
|
|
480
|
+
const bankTxn = createBankTransaction({
|
|
481
|
+
amount: -100.0,
|
|
482
|
+
payee: "Split Payment",
|
|
483
|
+
});
|
|
484
|
+
const ynabTxn1 = createYNABTransaction({
|
|
485
|
+
id: "y1",
|
|
486
|
+
amount: -50000,
|
|
487
|
+
payee_name: "Vendor A",
|
|
488
|
+
});
|
|
489
|
+
const ynabTxn2 = createYNABTransaction({
|
|
490
|
+
id: "y2",
|
|
491
|
+
amount: -50000,
|
|
492
|
+
payee_name: "Vendor B",
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
const suggestedMatch: TransactionMatch = {
|
|
496
|
+
bankTransaction: bankTxn,
|
|
497
|
+
candidates: [
|
|
498
|
+
{
|
|
499
|
+
ynab_transaction: ynabTxn1,
|
|
500
|
+
confidence: 60,
|
|
501
|
+
match_reason: "Partial amount match",
|
|
502
|
+
explanation: "Amount matches half of bank transaction",
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
ynab_transaction: ynabTxn2,
|
|
506
|
+
confidence: 60,
|
|
507
|
+
match_reason: "Partial amount match",
|
|
508
|
+
explanation: "Amount matches half of bank transaction",
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
confidence: "medium",
|
|
512
|
+
confidenceScore: 60,
|
|
513
|
+
matchReason: "combination_match",
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const context = createMockContext({
|
|
517
|
+
analysis: {
|
|
518
|
+
...createMockContext().analysis,
|
|
519
|
+
suggested_matches: [suggestedMatch],
|
|
520
|
+
},
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
const recommendations = generateRecommendations(context);
|
|
524
|
+
|
|
525
|
+
expect(recommendations).toHaveLength(1);
|
|
526
|
+
const rec = recommendations[0] as ManualReviewRecommendation;
|
|
527
|
+
expect(rec.action_type).toBe("manual_review");
|
|
528
|
+
expect(rec.priority).toBe("medium");
|
|
529
|
+
expect(rec.confidence).toBe(0.7); // CONFIDENCE.NEAR_MATCH_REVIEW
|
|
530
|
+
expect(rec.parameters.issue_type).toBe("complex_match");
|
|
531
|
+
expect(rec.parameters.related_transactions).toHaveLength(3); // 1 bank + 2 YNAB
|
|
532
|
+
|
|
533
|
+
// Verify related transactions structure
|
|
534
|
+
const relatedTxns = rec.parameters.related_transactions!;
|
|
535
|
+
expect(relatedTxns[0]?.source).toBe("bank");
|
|
536
|
+
expect(relatedTxns[0]?.id).toBe(bankTxn.id);
|
|
537
|
+
expect(relatedTxns[0]?.description).toBe("Split Payment");
|
|
538
|
+
expect(relatedTxns[1]?.source).toBe("ynab");
|
|
539
|
+
expect(relatedTxns[1]?.id).toBe("y1");
|
|
540
|
+
expect(relatedTxns[2]?.source).toBe("ynab");
|
|
541
|
+
expect(relatedTxns[2]?.id).toBe("y2");
|
|
542
|
+
|
|
543
|
+
// Verify enhanced metadata
|
|
544
|
+
expect(rec.metadata?.bank_transaction_amount).toBeDefined();
|
|
545
|
+
expect(rec.metadata?.bank_transaction_amount.value).toBe(-100.0);
|
|
546
|
+
expect(rec.metadata?.candidate_total_amount).toBeDefined();
|
|
547
|
+
expect(rec.metadata?.candidate_total_amount.value).toBe(-100.0); // -50 + -50
|
|
548
|
+
expect(rec.metadata?.candidate_count).toBe(2);
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
describe("amount sign preservation (CRITICAL)", () => {
|
|
553
|
+
it("should preserve negative amounts for expenses in create_transaction", () => {
|
|
554
|
+
const bankTxn = createBankTransaction({
|
|
555
|
+
amount: -123.45,
|
|
556
|
+
payee: "Grocery Store",
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
const context = createMockContext({
|
|
560
|
+
analysis: {
|
|
561
|
+
...createMockContext().analysis,
|
|
562
|
+
unmatched_bank: [bankTxn],
|
|
563
|
+
},
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
const recommendations = generateRecommendations(context);
|
|
567
|
+
|
|
568
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
569
|
+
expect(rec.parameters.amount).toBe(-123450); // In milliunits
|
|
570
|
+
expect(rec.parameters.amount).toBeLessThan(0);
|
|
571
|
+
expect(rec.estimated_impact.value).toBe(-123.45); // Estimated impact stays in dollars
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it("should preserve positive amounts for income in create_transaction", () => {
|
|
575
|
+
const bankTxn = createBankTransaction({
|
|
576
|
+
amount: 500.0,
|
|
577
|
+
payee: "Paycheck Refund",
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
const context = createMockContext({
|
|
581
|
+
analysis: {
|
|
582
|
+
...createMockContext().analysis,
|
|
583
|
+
unmatched_bank: [bankTxn],
|
|
584
|
+
},
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
const recommendations = generateRecommendations(context);
|
|
588
|
+
|
|
589
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
590
|
+
expect(rec.parameters.amount).toBe(500000); // In milliunits
|
|
591
|
+
expect(rec.parameters.amount).toBeGreaterThan(0);
|
|
592
|
+
expect(rec.estimated_impact.value).toBe(500.0); // Estimated impact stays in dollars
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it("should preserve negative amounts in suggested match create_transaction", () => {
|
|
596
|
+
const bankTxn = createBankTransaction({ amount: -99.99 });
|
|
597
|
+
|
|
598
|
+
const suggestedMatch: TransactionMatch = {
|
|
599
|
+
bankTransaction: bankTxn,
|
|
600
|
+
confidence: "none",
|
|
601
|
+
confidenceScore: 0,
|
|
602
|
+
matchReason: "No match",
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
const context = createMockContext({
|
|
606
|
+
analysis: {
|
|
607
|
+
...createMockContext().analysis,
|
|
608
|
+
suggested_matches: [suggestedMatch],
|
|
609
|
+
},
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
const recommendations = generateRecommendations(context);
|
|
613
|
+
|
|
614
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
615
|
+
expect(rec.parameters.amount).toBe(-99990); // In milliunits
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it("should handle zero amounts correctly", () => {
|
|
619
|
+
const bankTxn = createBankTransaction({ amount: 0 });
|
|
620
|
+
|
|
621
|
+
const context = createMockContext({
|
|
622
|
+
analysis: {
|
|
623
|
+
...createMockContext().analysis,
|
|
624
|
+
unmatched_bank: [bankTxn],
|
|
625
|
+
},
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
const recommendations = generateRecommendations(context);
|
|
629
|
+
|
|
630
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
631
|
+
expect(rec.parameters.amount).toBe(0); // Zero in milliunits is still zero
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
describe("sorting logic", () => {
|
|
636
|
+
it("should sort by priority (high > medium > low)", () => {
|
|
637
|
+
const bankTxn = createBankTransaction();
|
|
638
|
+
const ynabTxn = createYNABTransaction({ cleared: "uncleared" });
|
|
639
|
+
const insight = createInsight("anomaly", "warning");
|
|
640
|
+
|
|
641
|
+
// Create context that will generate all priority levels
|
|
642
|
+
const context = createMockContext({
|
|
643
|
+
analysis: {
|
|
644
|
+
...createMockContext().analysis,
|
|
645
|
+
unmatched_bank: [bankTxn], // medium priority
|
|
646
|
+
unmatched_ynab: [ynabTxn], // low priority
|
|
647
|
+
insights: [insight], // low priority (anomaly)
|
|
648
|
+
},
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
const recommendations = generateRecommendations(context);
|
|
652
|
+
|
|
653
|
+
expect(recommendations).toHaveLength(3);
|
|
654
|
+
// First should be medium (unmatched_bank)
|
|
655
|
+
expect(recommendations[0].priority).toBe("medium");
|
|
656
|
+
// Next should be low priority items
|
|
657
|
+
expect(recommendations[1].priority).toBe("low");
|
|
658
|
+
expect(recommendations[2].priority).toBe("low");
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
it("should sort by confidence when priorities are equal", () => {
|
|
662
|
+
const insights = [
|
|
663
|
+
createInsight("near_match", "warning"), // priority: medium, confidence: 0.7
|
|
664
|
+
createInsight("repeat_amount", "info"), // priority: medium, confidence: 0.75
|
|
665
|
+
];
|
|
666
|
+
|
|
667
|
+
const context = createMockContext({
|
|
668
|
+
analysis: {
|
|
669
|
+
...createMockContext().analysis,
|
|
670
|
+
insights,
|
|
671
|
+
},
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
const recommendations = generateRecommendations(context);
|
|
675
|
+
|
|
676
|
+
expect(recommendations).toHaveLength(2);
|
|
677
|
+
// Both are medium priority, so should be sorted by confidence (0.75 > 0.7)
|
|
678
|
+
expect(recommendations[0].confidence).toBe(0.75); // repeat_amount
|
|
679
|
+
expect(recommendations[1].confidence).toBe(0.7); // near_match
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
it("should handle mixed priorities and confidence", () => {
|
|
683
|
+
const bankTxn = createBankTransaction();
|
|
684
|
+
const ynabTxn = createYNABTransaction({ cleared: "uncleared" });
|
|
685
|
+
const suggestedMatch: TransactionMatch = {
|
|
686
|
+
bankTransaction: bankTxn,
|
|
687
|
+
ynabTransaction: ynabTxn,
|
|
688
|
+
confidence: "medium",
|
|
689
|
+
confidenceScore: 75,
|
|
690
|
+
matchReason: "Suggested",
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
const insights = [
|
|
694
|
+
createInsight("near_match", "warning"), // medium priority, 0.7 confidence
|
|
695
|
+
createInsight("anomaly", "warning"), // low priority, 0.5 confidence
|
|
696
|
+
];
|
|
697
|
+
|
|
698
|
+
const context = createMockContext({
|
|
699
|
+
analysis: {
|
|
700
|
+
...createMockContext().analysis,
|
|
701
|
+
suggested_matches: [suggestedMatch], // high priority, 0.75 confidence
|
|
702
|
+
unmatched_bank: [createBankTransaction({ id: "b2" })], // medium priority, 0.8 confidence
|
|
703
|
+
insights,
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
const recommendations = generateRecommendations(context);
|
|
708
|
+
|
|
709
|
+
// Should be: high priority first, then medium sorted by confidence, then low
|
|
710
|
+
expect(recommendations[0].priority).toBe("high");
|
|
711
|
+
expect(recommendations[1].priority).toBe("medium");
|
|
712
|
+
expect(recommendations[1].confidence).toBe(0.8); // unmatched_bank
|
|
713
|
+
expect(recommendations[2].priority).toBe("medium");
|
|
714
|
+
expect(recommendations[2].confidence).toBe(0.7); // near_match
|
|
715
|
+
expect(recommendations[3].priority).toBe("low");
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
describe("recommendation metadata", () => {
|
|
720
|
+
it("should include correct metadata in all recommendations", () => {
|
|
721
|
+
const bankTxn = createBankTransaction();
|
|
722
|
+
const context = createMockContext({
|
|
723
|
+
analysis: {
|
|
724
|
+
...createMockContext().analysis,
|
|
725
|
+
unmatched_bank: [bankTxn],
|
|
726
|
+
},
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
const recommendations = generateRecommendations(context);
|
|
730
|
+
|
|
731
|
+
const rec = recommendations[0];
|
|
732
|
+
expect(rec.id).toBeDefined();
|
|
733
|
+
expect(rec.account_id).toBe("test-account-id");
|
|
734
|
+
expect(rec.metadata.version).toBe("1.0");
|
|
735
|
+
expect(rec.metadata.created_at).toBeDefined();
|
|
736
|
+
expect(new Date(rec.metadata.created_at).getTime()).not.toBeNaN();
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
it("should generate unique IDs for each recommendation", () => {
|
|
740
|
+
const bankTxns = [
|
|
741
|
+
createBankTransaction({ id: "b1" }),
|
|
742
|
+
createBankTransaction({ id: "b2" }),
|
|
743
|
+
createBankTransaction({ id: "b3" }),
|
|
744
|
+
];
|
|
745
|
+
|
|
746
|
+
const context = createMockContext({
|
|
747
|
+
analysis: {
|
|
748
|
+
...createMockContext().analysis,
|
|
749
|
+
unmatched_bank: bankTxns,
|
|
750
|
+
},
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
const recommendations = generateRecommendations(context);
|
|
754
|
+
|
|
755
|
+
const ids = recommendations.map((r) => r.id);
|
|
756
|
+
const uniqueIds = new Set(ids);
|
|
757
|
+
expect(uniqueIds.size).toBe(ids.length);
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
it("should use correct currency from balance info", () => {
|
|
761
|
+
const bankTxn = createBankTransaction({ amount: -50.0 });
|
|
762
|
+
const context = createMockContext({
|
|
763
|
+
analysis: {
|
|
764
|
+
...createMockContext().analysis,
|
|
765
|
+
unmatched_bank: [bankTxn],
|
|
766
|
+
balance_info: {
|
|
767
|
+
...createMockContext().analysis.balance_info,
|
|
768
|
+
current_cleared: makeMoney(100, "EUR"),
|
|
769
|
+
},
|
|
770
|
+
},
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
const recommendations = generateRecommendations(context);
|
|
774
|
+
|
|
775
|
+
const rec = recommendations[0];
|
|
776
|
+
expect(rec.estimated_impact.currency).toBe("EUR");
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
it("should include enhanced metadata in insight-based manual review recommendations", () => {
|
|
780
|
+
const insight = createInsight("near_match", "critical");
|
|
781
|
+
const context = createMockContext({
|
|
782
|
+
analysis: {
|
|
783
|
+
...createMockContext().analysis,
|
|
784
|
+
insights: [insight],
|
|
785
|
+
balance_info: {
|
|
786
|
+
...createMockContext().analysis.balance_info,
|
|
787
|
+
discrepancy: makeMoney(-100, "USD"),
|
|
788
|
+
},
|
|
789
|
+
},
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
const recommendations = generateRecommendations(context);
|
|
793
|
+
|
|
794
|
+
expect(recommendations).toHaveLength(1);
|
|
795
|
+
const rec = recommendations[0] as ManualReviewRecommendation;
|
|
796
|
+
expect(rec.action_type).toBe("manual_review");
|
|
797
|
+
|
|
798
|
+
// Verify enhanced metadata fields
|
|
799
|
+
expect(rec.metadata?.current_discrepancy).toBeDefined();
|
|
800
|
+
expect(rec.metadata?.current_discrepancy.value).toBe(-100);
|
|
801
|
+
expect(rec.metadata?.current_discrepancy.currency).toBe("USD");
|
|
802
|
+
expect(rec.metadata?.insight_severity).toBe("critical");
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it("should include enhanced metadata for all insight-based recommendation types", () => {
|
|
806
|
+
const nearMatchInsight = createInsight("near_match", "warning");
|
|
807
|
+
const repeatAmountInsight = createInsight("repeat_amount", "info");
|
|
808
|
+
const anomalyInsight = createInsight("anomaly", "critical");
|
|
809
|
+
|
|
810
|
+
const context = createMockContext({
|
|
811
|
+
analysis: {
|
|
812
|
+
...createMockContext().analysis,
|
|
813
|
+
insights: [nearMatchInsight, repeatAmountInsight, anomalyInsight],
|
|
814
|
+
balance_info: {
|
|
815
|
+
...createMockContext().analysis.balance_info,
|
|
816
|
+
discrepancy: makeMoney(-250.75, "CAD"),
|
|
817
|
+
},
|
|
818
|
+
},
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
const recommendations = generateRecommendations(context);
|
|
822
|
+
|
|
823
|
+
expect(recommendations).toHaveLength(3);
|
|
824
|
+
|
|
825
|
+
// All insight-based recommendations should have enhanced metadata
|
|
826
|
+
for (const rec of recommendations) {
|
|
827
|
+
expect(rec.action_type).toBe("manual_review");
|
|
828
|
+
const manualRec = rec as ManualReviewRecommendation;
|
|
829
|
+
|
|
830
|
+
expect(manualRec.metadata?.current_discrepancy).toBeDefined();
|
|
831
|
+
expect(manualRec.metadata?.current_discrepancy.value).toBe(-250.75);
|
|
832
|
+
expect(manualRec.metadata?.current_discrepancy.currency).toBe("CAD");
|
|
833
|
+
expect(manualRec.metadata?.insight_severity).toMatch(
|
|
834
|
+
/^(info|warning|critical)$/,
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// Verify specific severities
|
|
839
|
+
const severities = recommendations.map(
|
|
840
|
+
(r) => (r as ManualReviewRecommendation).metadata?.insight_severity,
|
|
841
|
+
);
|
|
842
|
+
expect(severities).toContain("warning");
|
|
843
|
+
expect(severities).toContain("info");
|
|
844
|
+
expect(severities).toContain("critical");
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
describe("edge cases", () => {
|
|
849
|
+
it("should handle empty insights array", () => {
|
|
850
|
+
const context = createMockContext({
|
|
851
|
+
analysis: {
|
|
852
|
+
...createMockContext().analysis,
|
|
853
|
+
insights: [],
|
|
854
|
+
},
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
const recommendations = generateRecommendations(context);
|
|
858
|
+
expect(recommendations).toEqual([]);
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it("should handle empty unmatched arrays", () => {
|
|
862
|
+
const context = createMockContext({
|
|
863
|
+
analysis: {
|
|
864
|
+
...createMockContext().analysis,
|
|
865
|
+
unmatched_bank: [],
|
|
866
|
+
unmatched_ynab: [],
|
|
867
|
+
suggested_matches: [],
|
|
868
|
+
},
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
const recommendations = generateRecommendations(context);
|
|
872
|
+
expect(recommendations).toEqual([]);
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
it("should handle missing optional fields", () => {
|
|
876
|
+
const bankTxn = createBankTransaction();
|
|
877
|
+
bankTxn.memo = undefined;
|
|
878
|
+
|
|
879
|
+
const context = createMockContext({
|
|
880
|
+
analysis: {
|
|
881
|
+
...createMockContext().analysis,
|
|
882
|
+
unmatched_bank: [bankTxn],
|
|
883
|
+
},
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
const recommendations = generateRecommendations(context);
|
|
887
|
+
|
|
888
|
+
expect(recommendations).toHaveLength(1);
|
|
889
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
890
|
+
expect(rec.parameters.memo).toBeUndefined();
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
it("should handle very large arrays of recommendations", () => {
|
|
894
|
+
const bankTxns = Array.from({ length: 100 }, (_, i) =>
|
|
895
|
+
createBankTransaction({ id: `b${i}`, amount: -10.0 - i }),
|
|
896
|
+
);
|
|
897
|
+
|
|
898
|
+
const context = createMockContext({
|
|
899
|
+
analysis: {
|
|
900
|
+
...createMockContext().analysis,
|
|
901
|
+
unmatched_bank: bankTxns,
|
|
902
|
+
},
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
const recommendations = generateRecommendations(context);
|
|
906
|
+
|
|
907
|
+
expect(recommendations).toHaveLength(100);
|
|
908
|
+
// Verify sorting still works
|
|
909
|
+
for (let i = 0; i < recommendations.length - 1; i++) {
|
|
910
|
+
expect(recommendations[i].priority).toBeDefined();
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
it("should handle insight without evidence", () => {
|
|
915
|
+
const insight = createInsight("near_match");
|
|
916
|
+
insight.evidence = undefined;
|
|
917
|
+
|
|
918
|
+
const context = createMockContext({
|
|
919
|
+
analysis: {
|
|
920
|
+
...createMockContext().analysis,
|
|
921
|
+
insights: [insight],
|
|
922
|
+
},
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
const recommendations = generateRecommendations(context);
|
|
926
|
+
|
|
927
|
+
expect(recommendations).toHaveLength(1);
|
|
928
|
+
expect(recommendations[0]).toBeDefined();
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
it("should handle transactions with very small amounts", () => {
|
|
932
|
+
const bankTxn = createBankTransaction({ amount: -0.01 });
|
|
933
|
+
|
|
934
|
+
const context = createMockContext({
|
|
935
|
+
analysis: {
|
|
936
|
+
...createMockContext().analysis,
|
|
937
|
+
unmatched_bank: [bankTxn],
|
|
938
|
+
},
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
const recommendations = generateRecommendations(context);
|
|
942
|
+
|
|
943
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
944
|
+
expect(rec.parameters.amount).toBe(-10); // In milliunits (0.01 * 1000)
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
it("should handle transactions with very large amounts", () => {
|
|
948
|
+
const bankTxn = createBankTransaction({ amount: -999999.99 });
|
|
949
|
+
|
|
950
|
+
const context = createMockContext({
|
|
951
|
+
analysis: {
|
|
952
|
+
...createMockContext().analysis,
|
|
953
|
+
unmatched_bank: [bankTxn],
|
|
954
|
+
},
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
const recommendations = generateRecommendations(context);
|
|
958
|
+
|
|
959
|
+
const rec = recommendations[0] as CreateTransactionRecommendation;
|
|
960
|
+
expect(rec.parameters.amount).toBe(-999999990); // In milliunits
|
|
961
|
+
});
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
describe("combined scenarios", () => {
|
|
965
|
+
it("should handle combination of insights, unmatched bank, and unmatched YNAB", () => {
|
|
966
|
+
const bankTxn = createBankTransaction({ id: "b1" });
|
|
967
|
+
const ynabTxn = createYNABTransaction({
|
|
968
|
+
id: "y1",
|
|
969
|
+
cleared: "uncleared",
|
|
970
|
+
});
|
|
971
|
+
const insight = createInsight("near_match", "warning");
|
|
972
|
+
|
|
973
|
+
const context = createMockContext({
|
|
974
|
+
analysis: {
|
|
975
|
+
...createMockContext().analysis,
|
|
976
|
+
insights: [insight],
|
|
977
|
+
unmatched_bank: [bankTxn],
|
|
978
|
+
unmatched_ynab: [ynabTxn],
|
|
979
|
+
},
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
const recommendations = generateRecommendations(context);
|
|
983
|
+
|
|
984
|
+
expect(recommendations).toHaveLength(3);
|
|
985
|
+
expect(recommendations.map((r) => r.action_type).sort()).toEqual([
|
|
986
|
+
"create_transaction",
|
|
987
|
+
"manual_review",
|
|
988
|
+
"update_cleared",
|
|
989
|
+
]);
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
it("should handle all recommendation types at once", () => {
|
|
993
|
+
const bankTxn = createBankTransaction({ id: "b1" });
|
|
994
|
+
const ynabTxn = createYNABTransaction({
|
|
995
|
+
id: "y1",
|
|
996
|
+
cleared: "uncleared",
|
|
997
|
+
});
|
|
998
|
+
const suggestedMatch: TransactionMatch = {
|
|
999
|
+
bankTransaction: createBankTransaction({ id: "b2" }),
|
|
1000
|
+
ynabTransaction: createYNABTransaction({ id: "y2" }),
|
|
1001
|
+
confidence: "medium",
|
|
1002
|
+
confidenceScore: 75,
|
|
1003
|
+
matchReason: "Suggested",
|
|
1004
|
+
};
|
|
1005
|
+
const insights = [
|
|
1006
|
+
createInsight("near_match", "warning"),
|
|
1007
|
+
createInsight("repeat_amount", "info"),
|
|
1008
|
+
createInsight("anomaly", "critical"),
|
|
1009
|
+
];
|
|
1010
|
+
|
|
1011
|
+
const context = createMockContext({
|
|
1012
|
+
analysis: {
|
|
1013
|
+
...createMockContext().analysis,
|
|
1014
|
+
insights,
|
|
1015
|
+
unmatched_bank: [bankTxn],
|
|
1016
|
+
unmatched_ynab: [ynabTxn],
|
|
1017
|
+
suggested_matches: [suggestedMatch],
|
|
1018
|
+
},
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
const recommendations = generateRecommendations(context);
|
|
1022
|
+
|
|
1023
|
+
expect(recommendations.length).toBeGreaterThan(0);
|
|
1024
|
+
const actionTypes = new Set(recommendations.map((r) => r.action_type));
|
|
1025
|
+
expect(actionTypes.size).toBeGreaterThan(1);
|
|
1026
|
+
});
|
|
1027
|
+
});
|
|
1028
|
+
});
|
|
1007
1029
|
});
|