@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,140 @@
|
|
|
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 type { Doc } from "../_generated/dataModel.js";
|
|
6
|
+
const capture = makeFunctionReference<"mutation">(
|
|
7
|
+
"operationEvidence/mutations:capture",
|
|
8
|
+
);
|
|
9
|
+
const resolve = makeFunctionReference<"query">(
|
|
10
|
+
"operationEvidence/queries:resolve",
|
|
11
|
+
);
|
|
12
|
+
const headers = makeFunctionReference<"query">(
|
|
13
|
+
"operationEvidence/queries:headers",
|
|
14
|
+
);
|
|
15
|
+
const original = makeFunctionReference<"query">(
|
|
16
|
+
"operationEvidence/queries:original",
|
|
17
|
+
);
|
|
18
|
+
const latest = makeFunctionReference<"query">(
|
|
19
|
+
"operationEvidence/queries:latest",
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
it("pages compact references without hydrating absent payloads and reports current generation", async () => {
|
|
23
|
+
const t = convexTest(schema, modules);
|
|
24
|
+
const ids = await t.run(async (ctx) => {
|
|
25
|
+
const result = [];
|
|
26
|
+
for (let i = 0; i < 3; i++)
|
|
27
|
+
result.push(
|
|
28
|
+
await ctx.db.insert("transferReversalOps", {
|
|
29
|
+
operationId: `operation_${i}`,
|
|
30
|
+
sourceChargeId: `charge_${i}`,
|
|
31
|
+
slices: [],
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
return result;
|
|
35
|
+
});
|
|
36
|
+
const evidence: Array<{ header: Doc<"operationEvidenceHeaders"> }> = [];
|
|
37
|
+
for (const sourceId of ids)
|
|
38
|
+
evidence.push(await t.mutation(capture, { sourceId }));
|
|
39
|
+
await t.run(async (ctx) => {
|
|
40
|
+
for (const item of evidence) {
|
|
41
|
+
await ctx.db.delete(
|
|
42
|
+
"operationEvidencePayloads",
|
|
43
|
+
item.header.originalPayloadId,
|
|
44
|
+
);
|
|
45
|
+
await ctx.db.delete(
|
|
46
|
+
"operationEvidencePayloads",
|
|
47
|
+
item.header.latestPayloadId,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const first = await t.query(headers, {
|
|
52
|
+
paginationOpts: { numItems: 2, cursor: null },
|
|
53
|
+
});
|
|
54
|
+
expect(first).toMatchObject({
|
|
55
|
+
coverage: "unknown",
|
|
56
|
+
evidenceGeneration: 3,
|
|
57
|
+
isDone: false,
|
|
58
|
+
});
|
|
59
|
+
expect(first.page).toHaveLength(2);
|
|
60
|
+
expect(first.page[0]).not.toHaveProperty("slices");
|
|
61
|
+
expect(first.page[0]).not.toHaveProperty("operationId");
|
|
62
|
+
const next = await t.query(headers, {
|
|
63
|
+
paginationOpts: { numItems: 2, cursor: first.continueCursor },
|
|
64
|
+
});
|
|
65
|
+
expect([...first.page, ...next.page]).toHaveLength(3);
|
|
66
|
+
expect(
|
|
67
|
+
new Set([...first.page, ...next.page].map((row) => row._id)).size,
|
|
68
|
+
).toBe(3);
|
|
69
|
+
expect(
|
|
70
|
+
(await t.query(original, { headerId: evidence[0].header._id })).payload,
|
|
71
|
+
).toBeNull();
|
|
72
|
+
expect(
|
|
73
|
+
(await t.query(latest, { headerId: evidence[0].header._id })).payload,
|
|
74
|
+
).toBeNull();
|
|
75
|
+
for (const numItems of [0, 101, 1.5])
|
|
76
|
+
await expect(
|
|
77
|
+
t.query(headers, { paginationOpts: { numItems, cursor: null } }),
|
|
78
|
+
).rejects.toThrow();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("resolves an admitted large selector exactly and rejects reuse and forced unequal digest collision", async () => {
|
|
82
|
+
const t = convexTest(schema, modules);
|
|
83
|
+
const large = "\u0000".repeat(5000);
|
|
84
|
+
const ids = await t.run(async (ctx) => {
|
|
85
|
+
const one = await ctx.db.insert("transferReversalOps", {
|
|
86
|
+
operationId: large,
|
|
87
|
+
sourceChargeId: "charge",
|
|
88
|
+
slices: [],
|
|
89
|
+
});
|
|
90
|
+
const two = await ctx.db.insert("transferReversalOps", {
|
|
91
|
+
operationId: "different",
|
|
92
|
+
sourceChargeId: "other_charge",
|
|
93
|
+
slices: [],
|
|
94
|
+
});
|
|
95
|
+
return { one, two };
|
|
96
|
+
});
|
|
97
|
+
const one = await t.mutation(capture, { sourceId: ids.one });
|
|
98
|
+
const two = await t.mutation(capture, { sourceId: ids.two });
|
|
99
|
+
expect(
|
|
100
|
+
await t.query(resolve, { selector: "operationId", value: large }),
|
|
101
|
+
).toMatchObject({
|
|
102
|
+
coverage: "unknown",
|
|
103
|
+
evidenceGeneration: 2,
|
|
104
|
+
header: one.header,
|
|
105
|
+
});
|
|
106
|
+
expect(
|
|
107
|
+
await t.query(resolve, { selector: "sourceChargeId", value: "charge" }),
|
|
108
|
+
).toMatchObject({ header: one.header });
|
|
109
|
+
expect(
|
|
110
|
+
await t.query(resolve, { selector: "operationId", value: "missing" }),
|
|
111
|
+
).toMatchObject({ header: null });
|
|
112
|
+
await t.run((ctx) =>
|
|
113
|
+
ctx.db.patch("operationEvidenceHeaders", one.header._id, {
|
|
114
|
+
operationDigest: two.header.operationDigest,
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
expect(
|
|
118
|
+
await t.query(resolve, { selector: "operationId", value: "different" }),
|
|
119
|
+
).toMatchObject({ header: null });
|
|
120
|
+
await t.run((ctx) =>
|
|
121
|
+
ctx.db.delete("operationEvidenceHeaders", two.header._id),
|
|
122
|
+
);
|
|
123
|
+
expect(
|
|
124
|
+
await t.query(resolve, { selector: "operationId", value: "different" }),
|
|
125
|
+
).toMatchObject({ header: null });
|
|
126
|
+
expect(
|
|
127
|
+
(await t.query(original, { headerId: one.header._id })).payload.operationId,
|
|
128
|
+
).toBe(large);
|
|
129
|
+
const duplicateSource = await t.run((ctx) =>
|
|
130
|
+
ctx.db.insert("transferReversalOps", {
|
|
131
|
+
operationId: large,
|
|
132
|
+
sourceChargeId: "charge",
|
|
133
|
+
slices: [],
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
await t.mutation(capture, { sourceId: duplicateSource });
|
|
137
|
+
expect(
|
|
138
|
+
await t.query(resolve, { selector: "sourceChargeId", value: "charge" }),
|
|
139
|
+
).toMatchObject({ header: null });
|
|
140
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { transferReversalOpFields } from "../connect/validators.js";
|
|
4
|
+
|
|
5
|
+
// Deliberately EXACT source fields. Adding even small annotations can exceed 1 MiB.
|
|
6
|
+
export const payloadsTable = defineTable(transferReversalOpFields);
|
|
7
|
+
export const payloadDoc = v.object({
|
|
8
|
+
...transferReversalOpFields,
|
|
9
|
+
_id: v.id("operationEvidencePayloads"),
|
|
10
|
+
_creationTime: v.number(),
|
|
11
|
+
});
|
|
12
|
+
export const headerFields = {
|
|
13
|
+
sourceId: v.id("transferReversalOps"),
|
|
14
|
+
originalPayloadId: v.id("operationEvidencePayloads"),
|
|
15
|
+
latestPayloadId: v.id("operationEvidencePayloads"),
|
|
16
|
+
producer: v.literal("trusted_host_maintenance"),
|
|
17
|
+
producerVersion: v.literal(1),
|
|
18
|
+
firstObservedAt: v.number(),
|
|
19
|
+
sourceCreatedAt: v.number(),
|
|
20
|
+
originalFingerprint: v.string(),
|
|
21
|
+
latestFingerprint: v.string(),
|
|
22
|
+
originalIdentityFingerprint: v.string(),
|
|
23
|
+
operationDigest: v.string(),
|
|
24
|
+
sourceChargeDigest: v.string(),
|
|
25
|
+
generation: v.number(),
|
|
26
|
+
isContradictory: v.boolean(),
|
|
27
|
+
};
|
|
28
|
+
export const headerDoc = v.object({
|
|
29
|
+
...headerFields,
|
|
30
|
+
_id: v.id("operationEvidenceHeaders"),
|
|
31
|
+
_creationTime: v.number(),
|
|
32
|
+
});
|
|
33
|
+
export const headersTable = defineTable(headerFields)
|
|
34
|
+
.index("by_source_id", ["sourceId"])
|
|
35
|
+
.index("by_operation_digest", ["operationDigest"])
|
|
36
|
+
.index("by_source_charge_digest", ["sourceChargeDigest"]);
|
|
37
|
+
export const readFields = {
|
|
38
|
+
coverage: v.literal("unknown"),
|
|
39
|
+
evidenceGeneration: v.union(v.number(), v.null()),
|
|
40
|
+
};
|
|
41
|
+
export const headerResult = v.object({
|
|
42
|
+
...readFields,
|
|
43
|
+
header: v.union(headerDoc, v.null()),
|
|
44
|
+
});
|
|
45
|
+
export const payloadResult = v.object({
|
|
46
|
+
...headerResult.fields,
|
|
47
|
+
payload: v.union(payloadDoc, v.null()),
|
|
48
|
+
});
|
|
49
|
+
export const captureResult = v.object({
|
|
50
|
+
...headerResult.fields,
|
|
51
|
+
status: v.union(
|
|
52
|
+
v.literal("captured"),
|
|
53
|
+
v.literal("updated"),
|
|
54
|
+
v.literal("unchanged"),
|
|
55
|
+
v.literal("unavailable"),
|
|
56
|
+
v.literal("source_unavailable"),
|
|
57
|
+
),
|
|
58
|
+
});
|
|
59
|
+
export const selectorValidator = v.union(
|
|
60
|
+
v.literal("operationId"),
|
|
61
|
+
v.literal("sourceChargeId"),
|
|
62
|
+
);
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import { makeFunctionReference } from "convex/server";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { api } from "../_generated/api.js";
|
|
6
|
+
import { schema, modules } from "../../test.js";
|
|
7
|
+
|
|
8
|
+
const read = makeFunctionReference<
|
|
9
|
+
"query",
|
|
10
|
+
{
|
|
11
|
+
commandKey: string;
|
|
12
|
+
accountId: string;
|
|
13
|
+
stripePaymentIntentId: string;
|
|
14
|
+
stripeChargeId: string;
|
|
15
|
+
currency: string;
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
status: string;
|
|
19
|
+
reason?: string;
|
|
20
|
+
refund?: {
|
|
21
|
+
stripeRefundId: string;
|
|
22
|
+
amount: number;
|
|
23
|
+
currency: string;
|
|
24
|
+
status: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
>("refundHistory/queries:getRefundCommandEvidence");
|
|
28
|
+
const scope = {
|
|
29
|
+
commandKey: "dojo-refund:original_command:v1",
|
|
30
|
+
accountId: "acct_original",
|
|
31
|
+
stripePaymentIntentId: "pi_original",
|
|
32
|
+
stripeChargeId: "ch_original",
|
|
33
|
+
currency: "jpy",
|
|
34
|
+
};
|
|
35
|
+
const refund = {
|
|
36
|
+
stripeRefundId: "re_original",
|
|
37
|
+
accountId: scope.accountId,
|
|
38
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
39
|
+
stripeChargeId: scope.stripeChargeId,
|
|
40
|
+
amount: 500,
|
|
41
|
+
currency: scope.currency,
|
|
42
|
+
status: "pending" as const,
|
|
43
|
+
metadata: {
|
|
44
|
+
betterStripeRefundCommand: scope.commandKey,
|
|
45
|
+
betterStripeRefundFingerprint: "a".repeat(64),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
it("observes original units and pending state through exact command evidence without declaring completed money", async () => {
|
|
50
|
+
const t = convexTest(schema, modules);
|
|
51
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
52
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
53
|
+
status: "observed",
|
|
54
|
+
refund: {
|
|
55
|
+
stripeRefundId: "re_original",
|
|
56
|
+
amount: 500,
|
|
57
|
+
currency: "jpy",
|
|
58
|
+
status: "pending",
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("holds exact-key uniqueness when an unnormalized legacy metadata duplicate exists", async () => {
|
|
64
|
+
const t = convexTest(schema, modules);
|
|
65
|
+
await t.run((ctx) =>
|
|
66
|
+
ctx.db.insert("refunds", { ...refund, stripeRefundId: "re_legacy" }),
|
|
67
|
+
);
|
|
68
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
69
|
+
expect(await t.query(read, scope)).toEqual({
|
|
70
|
+
status: "unavailable",
|
|
71
|
+
reason: "normalization_incomplete",
|
|
72
|
+
});
|
|
73
|
+
const actual = await t.run((ctx) => ctx.db.query("refunds").take(3));
|
|
74
|
+
expect(actual).toHaveLength(2);
|
|
75
|
+
expect(
|
|
76
|
+
actual.every(
|
|
77
|
+
(row) => row.metadata.betterStripeRefundCommand === scope.commandKey,
|
|
78
|
+
),
|
|
79
|
+
).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("observes metadata enrichment of an already-read row independently of a history cursor", async () => {
|
|
83
|
+
const t = convexTest(schema, modules);
|
|
84
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
85
|
+
...refund,
|
|
86
|
+
metadata: {},
|
|
87
|
+
});
|
|
88
|
+
const first = await t.query(api.refundHistory.queries.paginateRefunds, {
|
|
89
|
+
accountId: scope.accountId,
|
|
90
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
91
|
+
paginationOpts: { numItems: 1, cursor: null },
|
|
92
|
+
});
|
|
93
|
+
expect(first.page[0]?.metadata).toEqual({});
|
|
94
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
95
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
96
|
+
status: "observed",
|
|
97
|
+
refund: { stripeRefundId: refund.stripeRefundId },
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("observes a later refund without restarting an exhausted historical scan", async () => {
|
|
102
|
+
const t = convexTest(schema, modules);
|
|
103
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
104
|
+
...refund,
|
|
105
|
+
stripeRefundId: "re_earlier",
|
|
106
|
+
metadata: {},
|
|
107
|
+
});
|
|
108
|
+
const first = await t.query(api.refundHistory.queries.paginateRefunds, {
|
|
109
|
+
accountId: scope.accountId,
|
|
110
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
111
|
+
paginationOpts: { numItems: 1, cursor: null },
|
|
112
|
+
});
|
|
113
|
+
const terminal = first.isDone
|
|
114
|
+
? first
|
|
115
|
+
: await t.query(api.refundHistory.queries.paginateRefunds, {
|
|
116
|
+
accountId: scope.accountId,
|
|
117
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
118
|
+
paginationOpts: { numItems: 1, cursor: first.continueCursor },
|
|
119
|
+
});
|
|
120
|
+
expect(terminal.isDone).toBe(true);
|
|
121
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
122
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
123
|
+
status: "observed",
|
|
124
|
+
refund: { stripeRefundId: refund.stripeRefundId },
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("detects duplicates before filtering foreign scope into apparent unique evidence", async () => {
|
|
129
|
+
const t = convexTest(schema, modules);
|
|
130
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
131
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
132
|
+
...refund,
|
|
133
|
+
stripeRefundId: "re_foreign",
|
|
134
|
+
accountId: "acct_foreign",
|
|
135
|
+
});
|
|
136
|
+
expect(await t.query(read, scope)).toEqual({
|
|
137
|
+
status: "unavailable",
|
|
138
|
+
reason: "ambiguous",
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it.each([
|
|
143
|
+
"accountId",
|
|
144
|
+
"stripePaymentIntentId",
|
|
145
|
+
"stripeChargeId",
|
|
146
|
+
"currency",
|
|
147
|
+
] as const)("reports foreign %s evidence instead of missing", async (field) => {
|
|
148
|
+
const t = convexTest(schema, modules);
|
|
149
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
150
|
+
...refund,
|
|
151
|
+
[field]: field === "currency" ? "usd" : "foreign",
|
|
152
|
+
});
|
|
153
|
+
expect(await t.query(read, scope)).toEqual({
|
|
154
|
+
status: "unavailable",
|
|
155
|
+
reason: "scope_mismatch",
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("preserves the known key on an omitted-metadata partial upsert", async () => {
|
|
160
|
+
const t = convexTest(schema, modules);
|
|
161
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
162
|
+
const { metadata, ...partial } = refund;
|
|
163
|
+
void metadata;
|
|
164
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
165
|
+
...partial,
|
|
166
|
+
status: "succeeded",
|
|
167
|
+
});
|
|
168
|
+
expect(await t.query(read, scope)).toMatchObject({
|
|
169
|
+
status: "observed",
|
|
170
|
+
refund: { status: "succeeded" },
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it.each([
|
|
175
|
+
{},
|
|
176
|
+
null,
|
|
177
|
+
{ betterStripeRefundCommand: "changed_command_key_123" },
|
|
178
|
+
{ betterStripeRefundCommand: false },
|
|
179
|
+
])("latches conflicting explicit metadata enrichment %#", async (metadata) => {
|
|
180
|
+
const t = convexTest(schema, modules);
|
|
181
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
182
|
+
await t.mutation(api.connect.mutations.upsertRefund, { ...refund, metadata });
|
|
183
|
+
expect(await t.query(read, scope)).toEqual({
|
|
184
|
+
status: "unavailable",
|
|
185
|
+
reason: "correlation_conflict",
|
|
186
|
+
});
|
|
187
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
188
|
+
expect(await t.query(read, scope)).toEqual({
|
|
189
|
+
status: "unavailable",
|
|
190
|
+
reason: "correlation_conflict",
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("keeps absent indexed evidence explicitly unavailable", async () => {
|
|
195
|
+
const t = convexTest(schema, modules);
|
|
196
|
+
expect(await t.query(read, scope)).toEqual({
|
|
197
|
+
status: "unavailable",
|
|
198
|
+
reason: "missing",
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("normalizes legacy first-known metadata before applying contradictory new metadata", async () => {
|
|
203
|
+
const t = convexTest(schema, modules);
|
|
204
|
+
await t.run((ctx) => ctx.db.insert("refunds", refund));
|
|
205
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
206
|
+
...refund,
|
|
207
|
+
metadata: { betterStripeRefundCommand: "different_command_key_123" },
|
|
208
|
+
});
|
|
209
|
+
expect(await t.query(read, scope)).toEqual({
|
|
210
|
+
status: "unavailable",
|
|
211
|
+
reason: "correlation_conflict",
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("normalizes legacy metadata on a partial upsert without inventing provider-creation provenance", async () => {
|
|
216
|
+
const t = convexTest(schema, modules);
|
|
217
|
+
await t.run((ctx) => ctx.db.insert("refunds", refund));
|
|
218
|
+
const { metadata, ...partial } = refund;
|
|
219
|
+
void metadata;
|
|
220
|
+
await t.mutation(api.connect.mutations.upsertRefund, partial);
|
|
221
|
+
expect(await t.query(read, scope)).toMatchObject({ status: "observed" });
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("holds global legacy coverage even for an unrelated unnormalized refund", async () => {
|
|
225
|
+
const t = convexTest(schema, modules);
|
|
226
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
227
|
+
await t.run((ctx) =>
|
|
228
|
+
ctx.db.insert("refunds", {
|
|
229
|
+
...refund,
|
|
230
|
+
stripeRefundId: "re_legacy_unrelated",
|
|
231
|
+
metadata: {},
|
|
232
|
+
}),
|
|
233
|
+
);
|
|
234
|
+
expect(await t.query(read, scope)).toEqual({
|
|
235
|
+
status: "unavailable",
|
|
236
|
+
reason: "normalization_incomplete",
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("reports actual legacy duplicates after both records have been re-observed", async () => {
|
|
241
|
+
const t = convexTest(schema, modules);
|
|
242
|
+
await t.run((ctx) =>
|
|
243
|
+
ctx.db.insert("refunds", { ...refund, stripeRefundId: "re_legacy" }),
|
|
244
|
+
);
|
|
245
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
246
|
+
expect(await t.query(read, scope)).toEqual({
|
|
247
|
+
status: "unavailable",
|
|
248
|
+
reason: "normalization_incomplete",
|
|
249
|
+
});
|
|
250
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
251
|
+
...refund,
|
|
252
|
+
stripeRefundId: "re_legacy",
|
|
253
|
+
});
|
|
254
|
+
expect(await t.query(read, scope)).toEqual({
|
|
255
|
+
status: "unavailable",
|
|
256
|
+
reason: "ambiguous",
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it.each([0, -1, 0.5, NaN, Number.MAX_SAFE_INTEGER + 1])(
|
|
261
|
+
"keeps malformed observed amount %s unavailable",
|
|
262
|
+
async (amount) => {
|
|
263
|
+
const t = convexTest(schema, modules);
|
|
264
|
+
await t.mutation(api.connect.mutations.upsertRefund, { ...refund, amount });
|
|
265
|
+
expect(await t.query(read, scope)).toEqual({
|
|
266
|
+
status: "unavailable",
|
|
267
|
+
reason: "invalid_receipt",
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
it("rejects duplicated provider receipt identity even when its indexed command keys differ", async () => {
|
|
273
|
+
const t = convexTest(schema, modules);
|
|
274
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
275
|
+
await t.run((ctx) =>
|
|
276
|
+
ctx.db.insert("refunds", {
|
|
277
|
+
...refund,
|
|
278
|
+
metadata: { betterStripeRefundCommand: "legacy_other_command_123" },
|
|
279
|
+
refundCommandNormalizationVersion: 1,
|
|
280
|
+
refundCommandKey: "legacy_other_command_123",
|
|
281
|
+
refundCommandObservedAt: Date.now(),
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
expect(await t.query(read, scope)).toEqual({
|
|
285
|
+
status: "unavailable",
|
|
286
|
+
reason: "ambiguous",
|
|
287
|
+
});
|
|
288
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import { makeFunctionReference } from "convex/server";
|
|
3
|
+
import { expect, it, vi } from "vitest";
|
|
4
|
+
import type { MutationCtx } from "../_generated/server.js";
|
|
5
|
+
import { api } from "../_generated/api.js";
|
|
6
|
+
import { schema, modules } from "../../test.js";
|
|
7
|
+
import { normalizeRefundCommandBindings } from "./mutations.js";
|
|
8
|
+
|
|
9
|
+
it("propagates a simulated resource failure atomically and keeps the legacy coverage hold", async () => {
|
|
10
|
+
const t = convexTest(schema, modules);
|
|
11
|
+
const scope = {
|
|
12
|
+
commandKey: "dojo-refund:resource_command:v1",
|
|
13
|
+
accountId: "acct_original",
|
|
14
|
+
stripePaymentIntentId: "pi_original",
|
|
15
|
+
stripeChargeId: "ch_original",
|
|
16
|
+
currency: "jpy",
|
|
17
|
+
};
|
|
18
|
+
const rows = await t.run(async (ctx) => {
|
|
19
|
+
const ids = [];
|
|
20
|
+
for (let i = 0; i < 2; i++)
|
|
21
|
+
ids.push(
|
|
22
|
+
await ctx.db.insert("refunds", {
|
|
23
|
+
stripeRefundId: `re_resource${i}`,
|
|
24
|
+
accountId: scope.accountId,
|
|
25
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
26
|
+
stripeChargeId: scope.stripeChargeId,
|
|
27
|
+
currency: scope.currency,
|
|
28
|
+
amount: 100,
|
|
29
|
+
status: "pending",
|
|
30
|
+
metadata: { betterStripeRefundCommand: scope.commandKey },
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
return Promise.all(ids.map((id) => ctx.db.get("refunds", id)));
|
|
34
|
+
});
|
|
35
|
+
const failure = new Error(
|
|
36
|
+
"Simulated native resource limit; no real capacity claim",
|
|
37
|
+
);
|
|
38
|
+
const handler = (
|
|
39
|
+
normalizeRefundCommandBindings as unknown as {
|
|
40
|
+
_handler: (
|
|
41
|
+
ctx: MutationCtx,
|
|
42
|
+
args: { limit: number },
|
|
43
|
+
) => Promise<{ normalized: number; hasMore: boolean }>;
|
|
44
|
+
}
|
|
45
|
+
)._handler;
|
|
46
|
+
await expect(
|
|
47
|
+
t.mutation(async (ctx) => {
|
|
48
|
+
const originalPatch = ctx.db.patch.bind(ctx.db);
|
|
49
|
+
const patch = vi
|
|
50
|
+
.spyOn(ctx.db, "patch")
|
|
51
|
+
.mockImplementationOnce(originalPatch)
|
|
52
|
+
.mockRejectedValueOnce(failure);
|
|
53
|
+
try {
|
|
54
|
+
return await handler(ctx, { limit: 2 });
|
|
55
|
+
} finally {
|
|
56
|
+
patch.mockRestore();
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
).rejects.toBe(failure);
|
|
60
|
+
expect(
|
|
61
|
+
await t.run((ctx) =>
|
|
62
|
+
Promise.all(rows.map((row) => ctx.db.get("refunds", row!._id))),
|
|
63
|
+
),
|
|
64
|
+
).toEqual(rows);
|
|
65
|
+
expect(
|
|
66
|
+
await t.query(api.refundHistory.queries.getRefundCommandEvidence, scope),
|
|
67
|
+
).toEqual({ status: "unavailable", reason: "normalization_incomplete" });
|
|
68
|
+
const normalize = makeFunctionReference<
|
|
69
|
+
"mutation",
|
|
70
|
+
{ limit: number },
|
|
71
|
+
{ normalized: number; hasMore: boolean }
|
|
72
|
+
>("refundHistory/mutations:normalizeRefundCommandBindings");
|
|
73
|
+
expect(await t.mutation(normalize, { limit: 1 })).toEqual({
|
|
74
|
+
normalized: 1,
|
|
75
|
+
hasMore: true,
|
|
76
|
+
});
|
|
77
|
+
});
|