@fantastic.dev/better-stripe 0.34.0 → 0.37.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 +260 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +664 -2
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +332 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +664 -2
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +332 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/refundCommandEvidence.d.ts +14 -0
- package/dist/client/connect/refundCommandEvidence.d.ts.map +1 -0
- package/dist/client/connect/refundCommandEvidence.js +20 -0
- package/dist/client/connect/refundCommandEvidence.js.map +1 -0
- package/dist/client/connect/refundCommandNormalization.d.ts +11 -0
- package/dist/client/connect/refundCommandNormalization.d.ts.map +1 -0
- package/dist/client/connect/refundCommandNormalization.js +12 -0
- package/dist/client/connect/refundCommandNormalization.js.map +1 -0
- package/dist/client/financialObservations.d.ts +42 -0
- package/dist/client/financialObservations.d.ts.map +1 -0
- package/dist/client/financialObservations.js +58 -0
- package/dist/client/financialObservations.js.map +1 -0
- package/dist/client/financialOwnership.d.ts +52 -0
- package/dist/client/financialOwnership.d.ts.map +1 -0
- package/dist/client/financialOwnership.js +72 -0
- package/dist/client/financialOwnership.js.map +1 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/observationPagination.d.ts +10 -0
- package/dist/client/observationPagination.d.ts.map +1 -0
- package/dist/client/observationPagination.js +12 -0
- package/dist/client/observationPagination.js.map +1 -0
- package/dist/client/operationEvidence.d.ts +37 -0
- package/dist/client/operationEvidence.d.ts.map +1 -0
- package/dist/client/operationEvidence.js +44 -0
- package/dist/client/operationEvidence.js.map +1 -0
- package/dist/client/publicTypes.d.ts +6 -0
- package/dist/client/publicTypes.d.ts.map +1 -1
- package/dist/client/readContracts.d.ts +31 -0
- package/dist/client/readContracts.d.ts.map +1 -1
- package/dist/client/readContracts.js +14 -0
- package/dist/client/readContracts.js.map +1 -1
- package/dist/client/transferObservations.d.ts +59 -0
- package/dist/client/transferObservations.d.ts.map +1 -0
- package/dist/client/transferObservations.js +82 -0
- package/dist/client/transferObservations.js.map +1 -0
- package/dist/component/_generated/component.d.ts +687 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/affiliateRecovery/mutations.d.ts.map +1 -1
- package/dist/component/affiliateRecovery/mutations.js +4 -1
- package/dist/component/affiliateRecovery/mutations.js.map +1 -1
- package/dist/component/connect/mutations.d.ts.map +1 -1
- package/dist/component/connect/mutations.js +18 -2
- package/dist/component/connect/mutations.js.map +1 -1
- package/dist/component/connect/queries.d.ts +8 -0
- package/dist/component/connect/queries.d.ts.map +1 -1
- package/dist/component/connect/reversalClaims.d.ts.map +1 -1
- package/dist/component/connect/reversalClaims.js +7 -1
- package/dist/component/connect/reversalClaims.js.map +1 -1
- package/dist/component/connect/reversalReceipts.d.ts.map +1 -1
- package/dist/component/connect/reversalReceipts.js +2 -0
- package/dist/component/connect/reversalReceipts.js.map +1 -1
- package/dist/component/connect/schema.d.ts +11 -1
- package/dist/component/connect/schema.d.ts.map +1 -1
- package/dist/component/connect/schema.js +9 -1
- package/dist/component/connect/schema.js.map +1 -1
- package/dist/component/connect/validators.d.ts +9 -1
- package/dist/component/connect/validators.d.ts.map +1 -1
- package/dist/component/connect/validators.js +2 -0
- package/dist/component/connect/validators.js.map +1 -1
- package/dist/component/earnings/pairedAdjustment.d.ts +12 -0
- package/dist/component/earnings/pairedAdjustment.d.ts.map +1 -0
- package/dist/component/earnings/pairedAdjustment.js +46 -0
- package/dist/component/earnings/pairedAdjustment.js.map +1 -0
- package/dist/component/earnings/triggers.d.ts +546 -2
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/earnings/triggers.js +17 -3
- package/dist/component/earnings/triggers.js.map +1 -1
- package/dist/component/financialObservations/continuation.d.ts +7 -0
- package/dist/component/financialObservations/continuation.d.ts.map +1 -0
- package/dist/component/financialObservations/continuation.js +131 -0
- package/dist/component/financialObservations/continuation.js.map +1 -0
- package/dist/component/financialObservations/generations.d.ts +6 -0
- package/dist/component/financialObservations/generations.d.ts.map +1 -0
- package/dist/component/financialObservations/generations.js +46 -0
- package/dist/component/financialObservations/generations.js.map +1 -0
- package/dist/component/financialObservations/mutations.d.ts +62 -0
- package/dist/component/financialObservations/mutations.d.ts.map +1 -0
- package/dist/component/financialObservations/mutations.js +69 -0
- package/dist/component/financialObservations/mutations.js.map +1 -0
- package/dist/component/financialObservations/queries.d.ts +307 -0
- package/dist/component/financialObservations/queries.d.ts.map +1 -0
- package/dist/component/financialObservations/queries.js +219 -0
- package/dist/component/financialObservations/queries.js.map +1 -0
- package/dist/component/financialObservations/schema.d.ts +182 -0
- package/dist/component/financialObservations/schema.d.ts.map +1 -0
- package/dist/component/financialObservations/schema.js +53 -0
- package/dist/component/financialObservations/schema.js.map +1 -0
- package/dist/component/financialObservations/settlement.d.ts +7 -0
- package/dist/component/financialObservations/settlement.d.ts.map +1 -0
- package/dist/component/financialObservations/settlement.js +118 -0
- package/dist/component/financialObservations/settlement.js.map +1 -0
- package/dist/component/financialObservations/settlementHelpers.d.ts +46 -0
- package/dist/component/financialObservations/settlementHelpers.d.ts.map +1 -0
- package/dist/component/financialObservations/settlementHelpers.js +70 -0
- package/dist/component/financialObservations/settlementHelpers.js.map +1 -0
- package/dist/component/financialObservations/transferBatches.d.ts +12 -0
- package/dist/component/financialObservations/transferBatches.d.ts.map +1 -0
- package/dist/component/financialObservations/transferBatches.js +76 -0
- package/dist/component/financialObservations/transferBatches.js.map +1 -0
- package/dist/component/financialObservations/transferContinuation.d.ts +5 -0
- package/dist/component/financialObservations/transferContinuation.d.ts.map +1 -0
- package/dist/component/financialObservations/transferContinuation.js +35 -0
- package/dist/component/financialObservations/transferContinuation.js.map +1 -0
- package/dist/component/financialObservations/transferContinuationState.d.ts +8 -0
- package/dist/component/financialObservations/transferContinuationState.d.ts.map +1 -0
- package/dist/component/financialObservations/transferContinuationState.js +69 -0
- package/dist/component/financialObservations/transferContinuationState.js.map +1 -0
- package/dist/component/financialObservations/transferContinuationSteps.d.ts +5 -0
- package/dist/component/financialObservations/transferContinuationSteps.d.ts.map +1 -0
- package/dist/component/financialObservations/transferContinuationSteps.js +174 -0
- package/dist/component/financialObservations/transferContinuationSteps.js.map +1 -0
- package/dist/component/financialObservations/transferHelpers.d.ts +18 -0
- package/dist/component/financialObservations/transferHelpers.d.ts.map +1 -0
- package/dist/component/financialObservations/transferHelpers.js +37 -0
- package/dist/component/financialObservations/transferHelpers.js.map +1 -0
- package/dist/component/financialObservations/transferReferenceSchema.d.ts +56 -0
- package/dist/component/financialObservations/transferReferenceSchema.d.ts.map +1 -0
- package/dist/component/financialObservations/transferReferenceSchema.js +21 -0
- package/dist/component/financialObservations/transferReferenceSchema.js.map +1 -0
- package/dist/component/financialObservations/transferSchema.d.ts +237 -0
- package/dist/component/financialObservations/transferSchema.d.ts.map +1 -0
- package/dist/component/financialObservations/transferSchema.js +65 -0
- package/dist/component/financialObservations/transferSchema.js.map +1 -0
- package/dist/component/financialObservations/transfers.d.ts +7 -0
- package/dist/component/financialObservations/transfers.d.ts.map +1 -0
- package/dist/component/financialObservations/transfers.js +79 -0
- package/dist/component/financialObservations/transfers.js.map +1 -0
- package/dist/component/financialOwnership/helpers.d.ts +37 -0
- package/dist/component/financialOwnership/helpers.d.ts.map +1 -0
- package/dist/component/financialOwnership/helpers.js +76 -0
- package/dist/component/financialOwnership/helpers.js.map +1 -0
- package/dist/component/financialOwnership/mutations.d.ts +28 -0
- package/dist/component/financialOwnership/mutations.d.ts.map +1 -0
- package/dist/component/financialOwnership/mutations.js +74 -0
- package/dist/component/financialOwnership/mutations.js.map +1 -0
- package/dist/component/financialOwnership/queries.d.ts +57 -0
- package/dist/component/financialOwnership/queries.d.ts.map +1 -0
- package/dist/component/financialOwnership/queries.js +50 -0
- package/dist/component/financialOwnership/queries.js.map +1 -0
- package/dist/component/financialOwnership/schema.d.ts +140 -0
- package/dist/component/financialOwnership/schema.d.ts.map +1 -0
- package/dist/component/financialOwnership/schema.js +35 -0
- package/dist/component/financialOwnership/schema.js.map +1 -0
- package/dist/component/operationEvidence/canonical.d.ts +4 -0
- package/dist/component/operationEvidence/canonical.d.ts.map +1 -0
- package/dist/component/operationEvidence/canonical.js +8 -0
- package/dist/component/operationEvidence/canonical.js.map +1 -0
- package/dist/component/operationEvidence/helpers.d.ts +87 -0
- package/dist/component/operationEvidence/helpers.d.ts.map +1 -0
- package/dist/component/operationEvidence/helpers.js +49 -0
- package/dist/component/operationEvidence/helpers.js.map +1 -0
- package/dist/component/operationEvidence/maintenance.d.ts +88 -0
- package/dist/component/operationEvidence/maintenance.d.ts.map +1 -0
- package/dist/component/operationEvidence/maintenance.js +59 -0
- package/dist/component/operationEvidence/maintenance.js.map +1 -0
- package/dist/component/operationEvidence/mutations.d.ts +97 -0
- package/dist/component/operationEvidence/mutations.d.ts.map +1 -0
- package/dist/component/operationEvidence/mutations.js +14 -0
- package/dist/component/operationEvidence/mutations.js.map +1 -0
- package/dist/component/operationEvidence/queries.d.ts +205 -0
- package/dist/component/operationEvidence/queries.d.ts.map +1 -0
- package/dist/component/operationEvidence/queries.js +75 -0
- package/dist/component/operationEvidence/queries.js.map +1 -0
- package/dist/component/operationEvidence/schema.d.ts +536 -0
- package/dist/component/operationEvidence/schema.d.ts.map +1 -0
- package/dist/component/operationEvidence/schema.js +53 -0
- package/dist/component/operationEvidence/schema.js.map +1 -0
- package/dist/component/refundHistory/commandBinding.d.ts +17 -0
- package/dist/component/refundHistory/commandBinding.d.ts.map +1 -0
- package/dist/component/refundHistory/commandBinding.js +41 -0
- package/dist/component/refundHistory/commandBinding.js.map +1 -0
- package/dist/component/refundHistory/commandEvidence.d.ts +50 -0
- package/dist/component/refundHistory/commandEvidence.d.ts.map +1 -0
- package/dist/component/refundHistory/commandEvidence.js +58 -0
- package/dist/component/refundHistory/commandEvidence.js.map +1 -0
- package/dist/component/refundHistory/commandEvidenceValidator.d.ts +89 -0
- package/dist/component/refundHistory/commandEvidenceValidator.d.ts.map +1 -0
- package/dist/component/refundHistory/commandEvidenceValidator.js +8 -0
- package/dist/component/refundHistory/commandEvidenceValidator.js.map +1 -0
- package/dist/component/refundHistory/commandFields.d.ts +8 -0
- package/dist/component/refundHistory/commandFields.d.ts.map +1 -0
- package/dist/component/refundHistory/commandFields.js +9 -0
- package/dist/component/refundHistory/commandFields.js.map +1 -0
- package/dist/component/refundHistory/mutations.d.ts +8 -0
- package/dist/component/refundHistory/mutations.d.ts.map +1 -0
- package/dist/component/refundHistory/mutations.js +25 -0
- package/dist/component/refundHistory/mutations.js.map +1 -0
- package/dist/component/refundHistory/originalSeller.d.ts +5 -0
- package/dist/component/refundHistory/originalSeller.d.ts.map +1 -0
- package/dist/component/refundHistory/originalSeller.js +35 -0
- package/dist/component/refundHistory/originalSeller.js.map +1 -0
- package/dist/component/refundHistory/queries.d.ts +51 -0
- package/dist/component/refundHistory/queries.d.ts.map +1 -1
- package/dist/component/refundHistory/queries.js +14 -0
- package/dist/component/refundHistory/queries.js.map +1 -1
- package/dist/component/schema.d.ts +332 -1
- package/dist/component/schema.js +15 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/settlement/mutations.d.ts.map +1 -1
- package/dist/component/settlement/mutations.js +5 -1
- package/dist/component/settlement/mutations.js.map +1 -1
- package/dist/shared/refundCommandScope.d.ts +10 -0
- package/dist/shared/refundCommandScope.d.ts.map +1 -0
- package/dist/shared/refundCommandScope.js +9 -0
- package/dist/shared/refundCommandScope.js.map +1 -0
- package/docs/financial-observations.md +244 -0
- package/docs/financial-ownership.md +54 -0
- package/docs/refund-command-evidence.md +55 -0
- package/package.json +5 -2
- package/src/client/connect/refundCommandEvidence.ts +41 -0
- package/src/client/connect/refundCommandNormalization.ts +28 -0
- package/src/client/financialObservations.test.ts +109 -0
- package/src/client/financialObservations.ts +106 -0
- package/src/client/financialOwnership.test.ts +80 -0
- package/src/client/financialOwnership.ts +116 -0
- package/src/client/index.ts +2 -2
- package/src/client/observationPagination.ts +11 -0
- package/src/client/operationEvidence.test.ts +110 -0
- package/src/client/operationEvidence.ts +92 -0
- package/src/client/publicTypes.ts +45 -0
- package/src/client/readContracts.ts +25 -0
- package/src/client/refund-command-evidence.test.ts +68 -0
- package/src/client/refund-command-normalization.test.ts +61 -0
- package/src/client/transferContinuation.test.ts +94 -0
- package/src/client/transferObservations.test.ts +98 -0
- package/src/client/transferObservations.ts +180 -0
- package/src/component/_generated/api.ts +54 -0
- package/src/component/_generated/component.ts +797 -0
- package/src/component/affiliateRecovery/mutations.ts +10 -1
- package/src/component/connect/mutations.ts +29 -2
- package/src/component/connect/reversalClaims.ts +19 -1
- package/src/component/connect/reversalReceipts.ts +2 -0
- package/src/component/connect/schema.ts +9 -1
- package/src/component/connect/validators.ts +2 -0
- package/src/component/core/reset.test.ts +8 -1
- package/src/component/earnings/earnings-totals.test.ts +14 -10
- package/src/component/earnings/paired-adjustment.test.ts +258 -0
- package/src/component/earnings/pairedAdjustment.ts +77 -0
- package/src/component/earnings/triggers.ts +23 -11
- package/src/component/financialObservations/continuation.test.ts +445 -0
- package/src/component/financialObservations/continuation.ts +159 -0
- package/src/component/financialObservations/generations.ts +53 -0
- package/src/component/financialObservations/mutations.ts +75 -0
- package/src/component/financialObservations/observation-boundaries.test.ts +466 -0
- package/src/component/financialObservations/queries.ts +246 -0
- package/src/component/financialObservations/schema.ts +68 -0
- package/src/component/financialObservations/settlement-observations.test.ts +86 -0
- package/src/component/financialObservations/settlement.ts +142 -0
- package/src/component/financialObservations/settlementHelpers.ts +92 -0
- package/src/component/financialObservations/transfer-batches.test.ts +61 -0
- package/src/component/financialObservations/transfer-boundaries.test.ts +116 -0
- package/src/component/financialObservations/transfer-continuation-guards.test.ts +428 -0
- package/src/component/financialObservations/transfer-continuation.test.ts +154 -0
- package/src/component/financialObservations/transfer-observations.test.ts +212 -0
- package/src/component/financialObservations/transfer-overflow.test.ts +181 -0
- package/src/component/financialObservations/transfer-writers.test.ts +162 -0
- package/src/component/financialObservations/transferBatches.ts +96 -0
- package/src/component/financialObservations/transferContinuation.ts +53 -0
- package/src/component/financialObservations/transferContinuationState.ts +85 -0
- package/src/component/financialObservations/transferContinuationSteps.ts +232 -0
- package/src/component/financialObservations/transferHelpers.ts +38 -0
- package/src/component/financialObservations/transferReferenceSchema.ts +20 -0
- package/src/component/financialObservations/transferSchema.ts +74 -0
- package/src/component/financialObservations/transfers.ts +99 -0
- package/src/component/financialOwnership/financial-ownership.test.ts +102 -0
- package/src/component/financialOwnership/helpers.ts +98 -0
- package/src/component/financialOwnership/mutations.ts +83 -0
- package/src/component/financialOwnership/ownership-boundaries.test.ts +308 -0
- package/src/component/financialOwnership/queries.ts +65 -0
- package/src/component/financialOwnership/schema.ts +35 -0
- package/src/component/operationEvidence/canonical.ts +10 -0
- package/src/component/operationEvidence/helpers.ts +65 -0
- package/src/component/operationEvidence/integrity.test.ts +257 -0
- package/src/component/operationEvidence/maintenance.test.ts +152 -0
- package/src/component/operationEvidence/maintenance.ts +89 -0
- package/src/component/operationEvidence/mutations.ts +14 -0
- package/src/component/operationEvidence/queries.ts +108 -0
- package/src/component/operationEvidence/reads.test.ts +140 -0
- package/src/component/operationEvidence/schema.ts +62 -0
- package/src/component/refundHistory/command-evidence.test.ts +288 -0
- package/src/component/refundHistory/command-normalization-resource.test.ts +77 -0
- package/src/component/refundHistory/command-normalization.test.ts +229 -0
- package/src/component/refundHistory/command-provenance.test.ts +59 -0
- package/src/component/refundHistory/commandBinding.ts +54 -0
- package/src/component/refundHistory/commandEvidence.ts +76 -0
- package/src/component/refundHistory/commandEvidenceValidator.ts +18 -0
- package/src/component/refundHistory/commandFields.ts +9 -0
- package/src/component/refundHistory/mutations.ts +33 -0
- package/src/component/refundHistory/original-seller-boundaries.test.ts +138 -0
- package/src/component/refundHistory/original-seller.test.ts +175 -0
- package/src/component/refundHistory/originalSeller.ts +48 -0
- package/src/component/refundHistory/queries.ts +15 -0
- package/src/component/schema.ts +28 -0
- package/src/component/settlement/mutations.ts +5 -1
- package/src/shared/refundCommandScope.ts +19 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import { makeFunctionReference } from "convex/server";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { modules, schema } from "../../test.js";
|
|
5
|
+
import { observeTransfer } from "./transfers.js";
|
|
6
|
+
const upsert = makeFunctionReference<"mutation">(
|
|
7
|
+
"connect/mutations:upsertTransfer",
|
|
8
|
+
);
|
|
9
|
+
const source = makeFunctionReference<"query">(
|
|
10
|
+
"financialObservations/queries:transfer",
|
|
11
|
+
);
|
|
12
|
+
const bucket = makeFunctionReference<"query">(
|
|
13
|
+
"financialObservations/queries:transferBucket",
|
|
14
|
+
);
|
|
15
|
+
function input(i = 0) {
|
|
16
|
+
return {
|
|
17
|
+
stripeTransferId: `tr_${i}`,
|
|
18
|
+
destinationAccountId: "opaque",
|
|
19
|
+
amount: 1,
|
|
20
|
+
currency: "usd",
|
|
21
|
+
status: "paid" as const,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
it("preserves ambiguous observation rows instead of choosing or repairing one", async () => {
|
|
25
|
+
const t = convexTest(schema, modules);
|
|
26
|
+
await t.mutation(upsert, input());
|
|
27
|
+
const f = await t.run(async (ctx) => {
|
|
28
|
+
const original = (
|
|
29
|
+
await ctx.db.query("financialTransferObservations").take(1)
|
|
30
|
+
)[0];
|
|
31
|
+
const { _id, _creationTime, ...fields } = original;
|
|
32
|
+
await ctx.db.insert("financialTransferObservations", fields);
|
|
33
|
+
return {
|
|
34
|
+
original,
|
|
35
|
+
rows: await ctx.db.query("financialTransferObservations").collect(),
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
await t.mutation(upsert, { ...input(), metadata: { late: true } });
|
|
39
|
+
expect(
|
|
40
|
+
await t.query(source, { transferId: f.original.transferId }),
|
|
41
|
+
).toMatchObject({ coverage: "unknown", observation: null });
|
|
42
|
+
expect(
|
|
43
|
+
await t.run((ctx) =>
|
|
44
|
+
ctx.db.query("financialTransferObservations").collect(),
|
|
45
|
+
),
|
|
46
|
+
).toEqual(f.rows);
|
|
47
|
+
expect(
|
|
48
|
+
(await t.run((ctx) => ctx.db.get("transfers", f.original.transferId)))
|
|
49
|
+
?.metadata,
|
|
50
|
+
).toEqual({ late: true });
|
|
51
|
+
});
|
|
52
|
+
it("marks exhausted generations unknown while preserving the actual financial update", async () => {
|
|
53
|
+
const t = convexTest(schema, modules);
|
|
54
|
+
await t.mutation(upsert, input());
|
|
55
|
+
const row = await t.run(async (ctx) => {
|
|
56
|
+
const r = (await ctx.db.query("financialTransferObservations").take(1))[0];
|
|
57
|
+
await ctx.db.patch("financialTransferObservations", r._id, {
|
|
58
|
+
generation: Number.MAX_SAFE_INTEGER,
|
|
59
|
+
});
|
|
60
|
+
return r;
|
|
61
|
+
});
|
|
62
|
+
await t.mutation(upsert, { ...input(), metadata: { late: true } });
|
|
63
|
+
expect(await t.query(source, { transferId: row.transferId })).toMatchObject({
|
|
64
|
+
coverage: "unknown",
|
|
65
|
+
observation: null,
|
|
66
|
+
});
|
|
67
|
+
expect(
|
|
68
|
+
await t.run((ctx) => ctx.db.get("financialTransferObservations", row._id)),
|
|
69
|
+
).toMatchObject({ generation: 0, isContradictory: true });
|
|
70
|
+
expect(
|
|
71
|
+
(await t.run((ctx) => ctx.db.get("transfers", row.transferId)))?.metadata,
|
|
72
|
+
).toEqual({ late: true });
|
|
73
|
+
});
|
|
74
|
+
it("retains native cursor metadata and visits every exact bucket row across page bounds", async () => {
|
|
75
|
+
const t = convexTest(schema, modules);
|
|
76
|
+
await t.run(async (ctx) => {
|
|
77
|
+
for (let i = 0; i < 105; i++) {
|
|
78
|
+
const id = await ctx.db.insert("transfers", {
|
|
79
|
+
...input(i),
|
|
80
|
+
totalsRecorded: true,
|
|
81
|
+
});
|
|
82
|
+
await observeTransfer(ctx, (await ctx.db.get("transfers", id))!);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const first = await t.query(bucket, {
|
|
86
|
+
bucketKey: "opaque",
|
|
87
|
+
paginationOpts: { numItems: 100, cursor: null, id: 19 },
|
|
88
|
+
});
|
|
89
|
+
expect(first.page).toHaveLength(100);
|
|
90
|
+
expect(first.isDone).toBe(false);
|
|
91
|
+
expect(first.continueCursor).toEqual(expect.any(String));
|
|
92
|
+
const next = await t.query(bucket, {
|
|
93
|
+
bucketKey: "opaque",
|
|
94
|
+
paginationOpts: { numItems: 100, cursor: first.continueCursor, id: 19 },
|
|
95
|
+
});
|
|
96
|
+
expect(next.page).toHaveLength(5);
|
|
97
|
+
expect(next.isDone).toBe(true);
|
|
98
|
+
expect(
|
|
99
|
+
new Set([...first.page, ...next.page].map((r) => r.transferId)).size,
|
|
100
|
+
).toBe(105);
|
|
101
|
+
expect(first).toMatchObject({ coverage: "unknown", hasDeferredWork: false });
|
|
102
|
+
await expect(
|
|
103
|
+
t.query(bucket, {
|
|
104
|
+
bucketKey: "opaque",
|
|
105
|
+
paginationOpts: { numItems: 101, cursor: null },
|
|
106
|
+
}),
|
|
107
|
+
).rejects.toThrow();
|
|
108
|
+
expect(
|
|
109
|
+
(
|
|
110
|
+
await t.query(bucket, {
|
|
111
|
+
bucketKey: "foreign",
|
|
112
|
+
paginationOpts: { numItems: 25, cursor: null },
|
|
113
|
+
})
|
|
114
|
+
).page,
|
|
115
|
+
).toEqual([]);
|
|
116
|
+
});
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { deferTransferFacts } from "./transferBatches.js";
|
|
2
|
+
import { convexTest } from "convex-test";
|
|
3
|
+
import { makeFunctionReference } from "convex/server";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
6
|
+
import { continueTransferBatch } from "./transferContinuation.js";
|
|
7
|
+
const resume = makeFunctionReference<"mutation">(
|
|
8
|
+
"financialObservations/mutations:resumeTransferBatch",
|
|
9
|
+
);
|
|
10
|
+
const upsert = makeFunctionReference<"mutation">(
|
|
11
|
+
"connect/mutations:upsertTransfer",
|
|
12
|
+
);
|
|
13
|
+
const register = makeFunctionReference<"mutation">(
|
|
14
|
+
"financialOwnership/mutations:register",
|
|
15
|
+
);
|
|
16
|
+
async function fixture() {
|
|
17
|
+
const t = convexTest(schema, modules);
|
|
18
|
+
const ids = await t.run(async (ctx) => {
|
|
19
|
+
const ids = [];
|
|
20
|
+
for (let i = 0; i < 101; i++)
|
|
21
|
+
ids.push(
|
|
22
|
+
await ctx.db.insert("transfers", {
|
|
23
|
+
stripeTransferId: `tr_${i}`,
|
|
24
|
+
sourceChargeId: "ch",
|
|
25
|
+
destinationAccountId: "opaque",
|
|
26
|
+
amount: 1,
|
|
27
|
+
currency: "usd",
|
|
28
|
+
status: "paid",
|
|
29
|
+
totalsRecorded: true,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
await ctx.db.insert("currencyTotals", {
|
|
33
|
+
accountId: "opaque",
|
|
34
|
+
currency: "usd",
|
|
35
|
+
kind: "earnings",
|
|
36
|
+
gross: 101,
|
|
37
|
+
reversed: 0,
|
|
38
|
+
paidOut: 0,
|
|
39
|
+
count: 101,
|
|
40
|
+
});
|
|
41
|
+
return ids;
|
|
42
|
+
});
|
|
43
|
+
await t.mutation(
|
|
44
|
+
makeFunctionReference<"mutation">("connect/mutations:claimReversalSlices"),
|
|
45
|
+
{ operationId: "op", sourceChargeId: "ch", mode: { kind: "full" } },
|
|
46
|
+
);
|
|
47
|
+
const batch = await t.run(
|
|
48
|
+
async (ctx) => (await ctx.db.query("financialTransferBatches").take(1))[0],
|
|
49
|
+
);
|
|
50
|
+
return { t, ids, batch };
|
|
51
|
+
}
|
|
52
|
+
function fact() {
|
|
53
|
+
return {
|
|
54
|
+
stripeTransferId: "tr_0",
|
|
55
|
+
sourceChargeId: "ch",
|
|
56
|
+
destinationAccountId: "opaque",
|
|
57
|
+
amount: 1,
|
|
58
|
+
currency: "usd",
|
|
59
|
+
status: "paid",
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
it("holds instead of absorbing an inter-commit financial write", async () => {
|
|
63
|
+
const { t, batch } = await fixture();
|
|
64
|
+
const first = await t.mutation(resume, {
|
|
65
|
+
batchId: batch._id,
|
|
66
|
+
expectedGeneration: 1,
|
|
67
|
+
});
|
|
68
|
+
await t.mutation(upsert, { ...fact(), metadata: { late: true } });
|
|
69
|
+
const held = await t.mutation(resume, {
|
|
70
|
+
batchId: batch._id,
|
|
71
|
+
expectedGeneration: first.batch.generation,
|
|
72
|
+
});
|
|
73
|
+
expect(held).toMatchObject({
|
|
74
|
+
coverage: "unknown",
|
|
75
|
+
hasDeferredWork: true,
|
|
76
|
+
batch: {
|
|
77
|
+
state: "pending",
|
|
78
|
+
isContradictory: true,
|
|
79
|
+
continuation: {
|
|
80
|
+
state: "held",
|
|
81
|
+
nextReference: 50,
|
|
82
|
+
validatedReferences: 0,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it("preserves an explicit prior unknown after a late first registration", async () => {
|
|
88
|
+
const { t, ids, batch } = await fixture();
|
|
89
|
+
await t.mutation(upsert, fact());
|
|
90
|
+
await t.mutation(register, {
|
|
91
|
+
bucketKey: "opaque",
|
|
92
|
+
kind: "logical",
|
|
93
|
+
userId: "late_owner",
|
|
94
|
+
source: { integration: "host", recordId: "late" },
|
|
95
|
+
});
|
|
96
|
+
await t.mutation(resume, { batchId: batch._id, expectedGeneration: 1 });
|
|
97
|
+
const observation = await t.run(
|
|
98
|
+
async (ctx) =>
|
|
99
|
+
(
|
|
100
|
+
await ctx.db
|
|
101
|
+
.query("financialTransferObservations")
|
|
102
|
+
.withIndex("by_transfer_id", (q) => q.eq("transferId", ids[0]))
|
|
103
|
+
.take(2)
|
|
104
|
+
)[0],
|
|
105
|
+
);
|
|
106
|
+
expect(observation.ownershipStatus).toBe("unknown");
|
|
107
|
+
expect(observation.userId).toBeUndefined();
|
|
108
|
+
expect(observation.registrationId).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
it("holds a missing original transfer without selecting a replacement", async () => {
|
|
111
|
+
const { t, ids, batch } = await fixture();
|
|
112
|
+
await t.run((ctx) => ctx.db.delete("transfers", ids[0]));
|
|
113
|
+
await expect(
|
|
114
|
+
t.mutation(resume, { batchId: batch._id, expectedGeneration: 1 }),
|
|
115
|
+
).resolves.toMatchObject({
|
|
116
|
+
coverage: "unknown",
|
|
117
|
+
hasDeferredWork: true,
|
|
118
|
+
batch: {
|
|
119
|
+
isContradictory: true,
|
|
120
|
+
continuation: { state: "held", nextReference: 0 },
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
it("holds duplicate original references across indexed batches", async () => {
|
|
125
|
+
const { t, ids, batch } = await fixture();
|
|
126
|
+
const refs = [...ids];
|
|
127
|
+
refs[60] = refs[0];
|
|
128
|
+
await t.run((ctx) =>
|
|
129
|
+
ctx.db.patch("financialTransferBatches", batch._id, { transferIds: refs }),
|
|
130
|
+
);
|
|
131
|
+
const first = await t.mutation(resume, {
|
|
132
|
+
batchId: batch._id,
|
|
133
|
+
expectedGeneration: 1,
|
|
134
|
+
});
|
|
135
|
+
const held = await t.mutation(resume, {
|
|
136
|
+
batchId: batch._id,
|
|
137
|
+
expectedGeneration: first.batch.generation,
|
|
138
|
+
});
|
|
139
|
+
expect(held.batch.continuation.state).toBe("held");
|
|
140
|
+
expect(held.hasDeferredWork).toBe(true);
|
|
141
|
+
});
|
|
142
|
+
it("validates committed reference slots rather than advancing a counter over a gap", async () => {
|
|
143
|
+
const { t, batch } = await fixture();
|
|
144
|
+
let r = await t.mutation(resume, {
|
|
145
|
+
batchId: batch._id,
|
|
146
|
+
expectedGeneration: 1,
|
|
147
|
+
});
|
|
148
|
+
for (let i = 0; i < 2; i++)
|
|
149
|
+
r = await t.mutation(resume, {
|
|
150
|
+
batchId: batch._id,
|
|
151
|
+
expectedGeneration: r.batch.generation,
|
|
152
|
+
});
|
|
153
|
+
await t.run(async (ctx) => {
|
|
154
|
+
const row = (
|
|
155
|
+
await ctx.db
|
|
156
|
+
.query("financialTransferBatchReferences")
|
|
157
|
+
.withIndex("by_batch_position", (q) =>
|
|
158
|
+
q.eq("batchId", batch._id).eq("position", 0),
|
|
159
|
+
)
|
|
160
|
+
.take(1)
|
|
161
|
+
)[0];
|
|
162
|
+
await ctx.db.delete("financialTransferBatchReferences", row._id);
|
|
163
|
+
});
|
|
164
|
+
r = await t.mutation(resume, {
|
|
165
|
+
batchId: batch._id,
|
|
166
|
+
expectedGeneration: r.batch.generation,
|
|
167
|
+
});
|
|
168
|
+
expect(r.batch.continuation.state).toBe("held");
|
|
169
|
+
expect(r.hasDeferredWork).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
it("rolls back every cursor/reference/observation write before commit and resumes safely", async () => {
|
|
172
|
+
const { t, batch } = await fixture();
|
|
173
|
+
const before = await t.run((ctx) =>
|
|
174
|
+
ctx.db.query("financialObservationGenerations").collect(),
|
|
175
|
+
);
|
|
176
|
+
await expect(
|
|
177
|
+
t.run(async (ctx) => {
|
|
178
|
+
await continueTransferBatch(ctx, batch, 1);
|
|
179
|
+
throw new Error("synthetic precommit interruption");
|
|
180
|
+
}),
|
|
181
|
+
).rejects.toThrow("synthetic precommit interruption");
|
|
182
|
+
expect(
|
|
183
|
+
await t.run((ctx) =>
|
|
184
|
+
ctx.db.query("financialTransferBatchReferences").take(1),
|
|
185
|
+
),
|
|
186
|
+
).toEqual([]);
|
|
187
|
+
expect(
|
|
188
|
+
await t.run((ctx) => ctx.db.query("financialTransferObservations").take(1)),
|
|
189
|
+
).toEqual([]);
|
|
190
|
+
expect(
|
|
191
|
+
await t.run((ctx) =>
|
|
192
|
+
ctx.db.query("financialObservationGenerations").collect(),
|
|
193
|
+
),
|
|
194
|
+
).toEqual(before);
|
|
195
|
+
expect(
|
|
196
|
+
await t.run((ctx) => ctx.db.get("financialTransferBatches", batch._id)),
|
|
197
|
+
).toEqual(batch);
|
|
198
|
+
expect(
|
|
199
|
+
await t.mutation(resume, { batchId: batch._id, expectedGeneration: 1 }),
|
|
200
|
+
).toMatchObject({ batch: { continuation: { nextReference: 50 } } });
|
|
201
|
+
});
|
|
202
|
+
it("holds contradictory observation identity instead of trusting cached hashes", async () => {
|
|
203
|
+
const { t, batch } = await fixture();
|
|
204
|
+
let r = await t.mutation(resume, {
|
|
205
|
+
batchId: batch._id,
|
|
206
|
+
expectedGeneration: 1,
|
|
207
|
+
});
|
|
208
|
+
for (let i = 0; i < 2; i++)
|
|
209
|
+
r = await t.mutation(resume, {
|
|
210
|
+
batchId: batch._id,
|
|
211
|
+
expectedGeneration: r.batch.generation,
|
|
212
|
+
});
|
|
213
|
+
await t.run(async (ctx) => {
|
|
214
|
+
const ref = (
|
|
215
|
+
await ctx.db
|
|
216
|
+
.query("financialTransferBatchReferences")
|
|
217
|
+
.withIndex("by_batch_position", (q) =>
|
|
218
|
+
q.eq("batchId", batch._id).eq("position", 0),
|
|
219
|
+
)
|
|
220
|
+
.take(1)
|
|
221
|
+
)[0];
|
|
222
|
+
await ctx.db.patch("financialTransferObservations", ref.observationId, {
|
|
223
|
+
bucketKey: "foreign",
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
const held = await t.mutation(resume, {
|
|
227
|
+
batchId: batch._id,
|
|
228
|
+
expectedGeneration: r.batch.generation,
|
|
229
|
+
});
|
|
230
|
+
expect(held.batch.continuation.state).toBe("held");
|
|
231
|
+
expect(held.hasDeferredWork).toBe(true);
|
|
232
|
+
});
|
|
233
|
+
it("refuses structurally impossible complete cursors before the historical early return", async () => {
|
|
234
|
+
const { t, batch } = await fixture();
|
|
235
|
+
const first = await t.mutation(resume, {
|
|
236
|
+
batchId: batch._id,
|
|
237
|
+
expectedGeneration: 1,
|
|
238
|
+
});
|
|
239
|
+
await t.run((ctx) =>
|
|
240
|
+
ctx.db.patch("financialTransferBatches", batch._id, {
|
|
241
|
+
state: "complete",
|
|
242
|
+
continuation: { ...first.batch.continuation, state: "complete" },
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
expect(
|
|
246
|
+
await t.mutation(resume, { batchId: batch._id, expectedGeneration: 2 }),
|
|
247
|
+
).toMatchObject({
|
|
248
|
+
coverage: "unknown",
|
|
249
|
+
hasDeferredWork: true,
|
|
250
|
+
batch: {
|
|
251
|
+
state: "pending",
|
|
252
|
+
isContradictory: true,
|
|
253
|
+
continuation: { state: "held", nextReference: 50 },
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
it("retains a completed historical traversal after later financial facts without claiming freshness", async () => {
|
|
258
|
+
const { t, batch } = await fixture();
|
|
259
|
+
let r = await t.mutation(resume, {
|
|
260
|
+
batchId: batch._id,
|
|
261
|
+
expectedGeneration: 1,
|
|
262
|
+
});
|
|
263
|
+
while (r.batch.state !== "complete")
|
|
264
|
+
r = await t.mutation(resume, {
|
|
265
|
+
batchId: batch._id,
|
|
266
|
+
expectedGeneration: r.batch.generation,
|
|
267
|
+
});
|
|
268
|
+
await t.mutation(upsert, { ...fact(), metadata: { later: true } });
|
|
269
|
+
const historic = await t.mutation(resume, {
|
|
270
|
+
batchId: batch._id,
|
|
271
|
+
expectedGeneration: r.batch.generation,
|
|
272
|
+
});
|
|
273
|
+
expect(historic.batch).toEqual(r.batch);
|
|
274
|
+
expect(historic.coverage).toBe("unknown");
|
|
275
|
+
expect(historic.producerGeneration).toBeGreaterThan(r.producerGeneration);
|
|
276
|
+
});
|
|
277
|
+
it("keeps registered pins when a contradictory replacement cannot prove the old owner", async () => {
|
|
278
|
+
const { t, batch, ids } = await fixture();
|
|
279
|
+
await t.mutation(register, {
|
|
280
|
+
bucketKey: "opaque",
|
|
281
|
+
kind: "logical",
|
|
282
|
+
userId: "original",
|
|
283
|
+
source: { integration: "host", recordId: "original" },
|
|
284
|
+
});
|
|
285
|
+
await t.mutation(upsert, fact());
|
|
286
|
+
await t.run(async (ctx) => {
|
|
287
|
+
const registration = (await ctx.db.query("financialOwnership").take(1))[0];
|
|
288
|
+
await ctx.db.patch("financialOwnership", registration._id, {
|
|
289
|
+
userId: "replacement",
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
const held = await t.mutation(resume, {
|
|
293
|
+
batchId: batch._id,
|
|
294
|
+
expectedGeneration: 1,
|
|
295
|
+
});
|
|
296
|
+
expect(held.batch.continuation.state).toBe("held");
|
|
297
|
+
const original = await t.run(
|
|
298
|
+
async (ctx) =>
|
|
299
|
+
(
|
|
300
|
+
await ctx.db
|
|
301
|
+
.query("financialTransferObservations")
|
|
302
|
+
.withIndex("by_transfer_id", (q) => q.eq("transferId", ids[0]))
|
|
303
|
+
.take(1)
|
|
304
|
+
)[0],
|
|
305
|
+
);
|
|
306
|
+
expect(original.userId).toBe("original");
|
|
307
|
+
});
|
|
308
|
+
it.each([0, 1.5, Number.MAX_SAFE_INTEGER + 1])(
|
|
309
|
+
"rejects invalid expected generation %s before progress",
|
|
310
|
+
async (expectedGeneration) => {
|
|
311
|
+
const { t, batch } = await fixture();
|
|
312
|
+
await expect(
|
|
313
|
+
t.mutation(resume, { batchId: batch._id, expectedGeneration }),
|
|
314
|
+
).rejects.toThrow("Invalid observation generation");
|
|
315
|
+
expect(
|
|
316
|
+
await t.run((ctx) => ctx.db.get("financialTransferBatches", batch._id)),
|
|
317
|
+
).toEqual(batch);
|
|
318
|
+
},
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
it("retains pending invalidation when a completed producer reference becomes contradictory", async () => {
|
|
322
|
+
const { t, batch, ids } = await fixture();
|
|
323
|
+
let r = await t.mutation(resume, {
|
|
324
|
+
batchId: batch._id,
|
|
325
|
+
expectedGeneration: 1,
|
|
326
|
+
});
|
|
327
|
+
while (r.batch.state !== "complete")
|
|
328
|
+
r = await t.mutation(resume, {
|
|
329
|
+
batchId: batch._id,
|
|
330
|
+
expectedGeneration: r.batch.generation,
|
|
331
|
+
});
|
|
332
|
+
await t.run(async (ctx) => {
|
|
333
|
+
const operation = (
|
|
334
|
+
await ctx.db
|
|
335
|
+
.query("transferReversalOps")
|
|
336
|
+
.withIndex("by_operation_id", (q) => q.eq("operationId", "op"))
|
|
337
|
+
.take(1)
|
|
338
|
+
)[0];
|
|
339
|
+
await deferTransferFacts(
|
|
340
|
+
ctx,
|
|
341
|
+
operation,
|
|
342
|
+
ids.slice(0, 100),
|
|
343
|
+
"transfer_frontier_claim",
|
|
344
|
+
);
|
|
345
|
+
});
|
|
346
|
+
r = await t.mutation(resume, {
|
|
347
|
+
batchId: batch._id,
|
|
348
|
+
expectedGeneration: r.batch.generation + 1,
|
|
349
|
+
});
|
|
350
|
+
expect(r).toMatchObject({
|
|
351
|
+
coverage: "unknown",
|
|
352
|
+
hasDeferredWork: true,
|
|
353
|
+
batch: {
|
|
354
|
+
state: "pending",
|
|
355
|
+
isContradictory: true,
|
|
356
|
+
referenceCount: 101,
|
|
357
|
+
continuation: {
|
|
358
|
+
state: "held",
|
|
359
|
+
nextReference: 101,
|
|
360
|
+
validatedReferences: 101,
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
expect(r.batch.transferIds).toEqual(ids);
|
|
365
|
+
});
|
|
366
|
+
it("holds duplicate producer markers without selecting an alternative source", async () => {
|
|
367
|
+
const { t, batch } = await fixture();
|
|
368
|
+
await t.run(async (ctx) => {
|
|
369
|
+
const { _id, _creationTime, ...fields } = batch;
|
|
370
|
+
await ctx.db.insert("financialTransferBatches", fields);
|
|
371
|
+
});
|
|
372
|
+
const r = await t.mutation(resume, {
|
|
373
|
+
batchId: batch._id,
|
|
374
|
+
expectedGeneration: 1,
|
|
375
|
+
});
|
|
376
|
+
expect(r.batch.continuation.state).toBe("held");
|
|
377
|
+
expect(r.hasDeferredWork).toBe(true);
|
|
378
|
+
expect(
|
|
379
|
+
await t.run((ctx) =>
|
|
380
|
+
ctx.db.query("financialTransferBatchReferences").take(1),
|
|
381
|
+
),
|
|
382
|
+
).toEqual([]);
|
|
383
|
+
});
|
|
384
|
+
it("holds a duplicated committed slot and preserves both receipts", async () => {
|
|
385
|
+
const { t, batch } = await fixture();
|
|
386
|
+
let r = await t.mutation(resume, {
|
|
387
|
+
batchId: batch._id,
|
|
388
|
+
expectedGeneration: 1,
|
|
389
|
+
});
|
|
390
|
+
for (let i = 0; i < 2; i++)
|
|
391
|
+
r = await t.mutation(resume, {
|
|
392
|
+
batchId: batch._id,
|
|
393
|
+
expectedGeneration: r.batch.generation,
|
|
394
|
+
});
|
|
395
|
+
const before = await t.run(async (ctx) => {
|
|
396
|
+
const original = (
|
|
397
|
+
await ctx.db
|
|
398
|
+
.query("financialTransferBatchReferences")
|
|
399
|
+
.withIndex("by_batch_position", (q) =>
|
|
400
|
+
q.eq("batchId", batch._id).eq("position", 0),
|
|
401
|
+
)
|
|
402
|
+
.take(1)
|
|
403
|
+
)[0];
|
|
404
|
+
const { _id, _creationTime, ...fields } = original;
|
|
405
|
+
await ctx.db.insert("financialTransferBatchReferences", fields);
|
|
406
|
+
return ctx.db
|
|
407
|
+
.query("financialTransferBatchReferences")
|
|
408
|
+
.withIndex("by_batch_position", (q) =>
|
|
409
|
+
q.eq("batchId", batch._id).eq("position", 0),
|
|
410
|
+
)
|
|
411
|
+
.take(3);
|
|
412
|
+
});
|
|
413
|
+
const held = await t.mutation(resume, {
|
|
414
|
+
batchId: batch._id,
|
|
415
|
+
expectedGeneration: r.batch.generation,
|
|
416
|
+
});
|
|
417
|
+
expect(held.batch.continuation.state).toBe("held");
|
|
418
|
+
expect(
|
|
419
|
+
await t.run((ctx) =>
|
|
420
|
+
ctx.db
|
|
421
|
+
.query("financialTransferBatchReferences")
|
|
422
|
+
.withIndex("by_batch_position", (q) =>
|
|
423
|
+
q.eq("batchId", batch._id).eq("position", 0),
|
|
424
|
+
)
|
|
425
|
+
.take(3),
|
|
426
|
+
),
|
|
427
|
+
).toEqual(before);
|
|
428
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import { makeFunctionReference } from "convex/server";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { modules, schema } from "../../test.js";
|
|
5
|
+
const resume = makeFunctionReference<"mutation">(
|
|
6
|
+
"financialObservations/mutations:resumeTransferBatch",
|
|
7
|
+
);
|
|
8
|
+
const batches = makeFunctionReference<"query">(
|
|
9
|
+
"financialObservations/queries:transferBatches",
|
|
10
|
+
);
|
|
11
|
+
const references = makeFunctionReference<"query">(
|
|
12
|
+
"financialObservations/queries:transferReferences",
|
|
13
|
+
);
|
|
14
|
+
const claim = makeFunctionReference<"mutation">(
|
|
15
|
+
"connect/mutations:claimReversalSlices",
|
|
16
|
+
);
|
|
17
|
+
const release = makeFunctionReference<"mutation">(
|
|
18
|
+
"connect/mutations:releaseReversalClaim",
|
|
19
|
+
);
|
|
20
|
+
async function fixture(kind: "claim" | "release") {
|
|
21
|
+
const t = convexTest(schema, modules);
|
|
22
|
+
await t.run(async (ctx) => {
|
|
23
|
+
for (let i = 0; i < 101; i++)
|
|
24
|
+
await ctx.db.insert("transfers", {
|
|
25
|
+
stripeTransferId: `tr_${i}`,
|
|
26
|
+
sourceChargeId: "ch",
|
|
27
|
+
destinationAccountId: "opaque",
|
|
28
|
+
amount: 1,
|
|
29
|
+
currency: "usd",
|
|
30
|
+
role: "store",
|
|
31
|
+
status: "paid",
|
|
32
|
+
totalsRecorded: true,
|
|
33
|
+
...(kind === "release" ? { reversalClaimedAmount: 1 } : {}),
|
|
34
|
+
});
|
|
35
|
+
await ctx.db.insert("currencyTotals", {
|
|
36
|
+
accountId: "opaque",
|
|
37
|
+
currency: "usd",
|
|
38
|
+
kind: "earnings",
|
|
39
|
+
gross: 101,
|
|
40
|
+
reversed: 0,
|
|
41
|
+
paidOut: 0,
|
|
42
|
+
count: 101,
|
|
43
|
+
});
|
|
44
|
+
if (kind === "release")
|
|
45
|
+
await ctx.db.insert("transferReversalOps", {
|
|
46
|
+
operationId: "op",
|
|
47
|
+
sourceChargeId: "ch",
|
|
48
|
+
slices: Array.from({ length: 101 }, (_, i) => ({
|
|
49
|
+
stripeTransferId: `tr_${i}`,
|
|
50
|
+
from: 0,
|
|
51
|
+
to: 1,
|
|
52
|
+
})),
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
if (kind === "claim")
|
|
56
|
+
await t.mutation(claim, {
|
|
57
|
+
operationId: "op",
|
|
58
|
+
sourceChargeId: "ch",
|
|
59
|
+
mode: { kind: "full" },
|
|
60
|
+
});
|
|
61
|
+
else
|
|
62
|
+
await t.mutation(release, {
|
|
63
|
+
operationId: "op",
|
|
64
|
+
verified: Array.from({ length: 101 }, (_, i) => ({
|
|
65
|
+
stripeTransferId: `tr_${i}`,
|
|
66
|
+
amountReversed: 0,
|
|
67
|
+
})),
|
|
68
|
+
});
|
|
69
|
+
const page = await t.query(batches, {
|
|
70
|
+
operationId: "op",
|
|
71
|
+
paginationOpts: { numItems: 25, cursor: null },
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
t,
|
|
75
|
+
batch: page.page[0],
|
|
76
|
+
financial: await t.run((ctx) => ctx.db.query("transfers").take(102)),
|
|
77
|
+
totals: await t.run((ctx) => ctx.db.query("currencyTotals").take(2)),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
it.each(["claim", "release"] as const)(
|
|
81
|
+
"visits and validates every %s reference across separate bounded commits",
|
|
82
|
+
async (kind) => {
|
|
83
|
+
const { t, batch, financial, totals } = await fixture(kind);
|
|
84
|
+
let result = await t.mutation(resume, {
|
|
85
|
+
batchId: batch._id,
|
|
86
|
+
expectedGeneration: 1,
|
|
87
|
+
});
|
|
88
|
+
expect(result).toMatchObject({
|
|
89
|
+
coverage: "unknown",
|
|
90
|
+
hasDeferredWork: true,
|
|
91
|
+
batch: {
|
|
92
|
+
generation: 2,
|
|
93
|
+
state: "pending",
|
|
94
|
+
continuation: {
|
|
95
|
+
state: "indexing",
|
|
96
|
+
nextReference: 50,
|
|
97
|
+
validatedReferences: 0,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
expect(
|
|
102
|
+
await t.mutation(resume, { batchId: batch._id, expectedGeneration: 1 }),
|
|
103
|
+
).toEqual(result);
|
|
104
|
+
let calls = 1;
|
|
105
|
+
while (result.batch.state !== "complete") {
|
|
106
|
+
result = await t.mutation(resume, {
|
|
107
|
+
batchId: batch._id,
|
|
108
|
+
expectedGeneration: result.batch.generation,
|
|
109
|
+
});
|
|
110
|
+
calls++;
|
|
111
|
+
expect(calls).toBeLessThan(10);
|
|
112
|
+
}
|
|
113
|
+
expect(calls).toBe(6);
|
|
114
|
+
expect(result).toMatchObject({
|
|
115
|
+
coverage: "unknown",
|
|
116
|
+
hasDeferredWork: false,
|
|
117
|
+
batch: {
|
|
118
|
+
referenceCount: 101,
|
|
119
|
+
continuation: {
|
|
120
|
+
state: "complete",
|
|
121
|
+
nextReference: 101,
|
|
122
|
+
validatedReferences: 101,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const first = await t.query(references, {
|
|
127
|
+
batchId: batch._id,
|
|
128
|
+
paginationOpts: { numItems: 100, cursor: null },
|
|
129
|
+
});
|
|
130
|
+
const second = await t.query(references, {
|
|
131
|
+
batchId: batch._id,
|
|
132
|
+
paginationOpts: { numItems: 100, cursor: first.continueCursor },
|
|
133
|
+
});
|
|
134
|
+
const all = [...first.page, ...second.page];
|
|
135
|
+
expect(all).toHaveLength(101);
|
|
136
|
+
expect(new Set(all.map((r) => r.transferId)).size).toBe(101);
|
|
137
|
+
expect(all.map((r) => r.position)).toEqual(
|
|
138
|
+
Array.from({ length: 101 }, (_, i) => i),
|
|
139
|
+
);
|
|
140
|
+
expect(second.isDone).toBe(true);
|
|
141
|
+
expect(await t.run((ctx) => ctx.db.query("transfers").take(102))).toEqual(
|
|
142
|
+
financial,
|
|
143
|
+
);
|
|
144
|
+
expect(
|
|
145
|
+
await t.run((ctx) => ctx.db.query("currencyTotals").take(2)),
|
|
146
|
+
).toEqual(totals);
|
|
147
|
+
expect(
|
|
148
|
+
await t.mutation(resume, {
|
|
149
|
+
batchId: batch._id,
|
|
150
|
+
expectedGeneration: result.batch.generation,
|
|
151
|
+
}),
|
|
152
|
+
).toEqual(result);
|
|
153
|
+
},
|
|
154
|
+
);
|