@fantastic.dev/better-stripe 0.34.0 → 0.35.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 +35 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +486 -2
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +243 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +486 -2
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +243 -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/publicTypes.d.ts +5 -0
- package/dist/client/publicTypes.d.ts.map +1 -1
- package/dist/client/readContracts.d.ts +29 -0
- package/dist/client/readContracts.d.ts.map +1 -1
- package/dist/client/readContracts.js +10 -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 +506 -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/triggers.d.ts +426 -2
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/earnings/triggers.js +7 -1
- 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/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- 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 +54 -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/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 +243 -1
- package/dist/component/schema.js +12 -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 +159 -0
- package/docs/financial-ownership.md +54 -0
- package/docs/refund-command-evidence.md +49 -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/publicTypes.ts +37 -0
- package/src/client/readContracts.ts +21 -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 +44 -0
- package/src/component/_generated/component.ts +590 -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/triggers.ts +9 -1
- 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/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 +71 -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/queries.ts +15 -0
- package/src/component/schema.ts +22 -0
- package/src/component/settlement/mutations.ts +5 -1
- package/src/shared/refundCommandScope.ts +19 -0
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import { makeFunctionReference } from "convex/server";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { api } from "../_generated/api.js";
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
6
|
+
|
|
7
|
+
const normalize = makeFunctionReference<
|
|
8
|
+
"mutation",
|
|
9
|
+
{ limit: number },
|
|
10
|
+
{ normalized: number; hasMore: boolean }
|
|
11
|
+
>("refundHistory/mutations:normalizeRefundCommandBindings");
|
|
12
|
+
const scope = {
|
|
13
|
+
commandKey: "dojo-refund:legacy_command:v1",
|
|
14
|
+
accountId: "acct_original",
|
|
15
|
+
stripePaymentIntentId: "pi_original",
|
|
16
|
+
stripeChargeId: "ch_original",
|
|
17
|
+
currency: "jpy",
|
|
18
|
+
};
|
|
19
|
+
const refund = {
|
|
20
|
+
stripeRefundId: "re_legacy",
|
|
21
|
+
accountId: scope.accountId,
|
|
22
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
23
|
+
stripeChargeId: scope.stripeChargeId,
|
|
24
|
+
currency: scope.currency,
|
|
25
|
+
amount: 500,
|
|
26
|
+
status: "pending" as const,
|
|
27
|
+
metadata: { betterStripeRefundCommand: scope.commandKey },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
it("drains only the bounded pending rows across multiple invocations", async () => {
|
|
31
|
+
const t = convexTest(schema, modules);
|
|
32
|
+
const ids = await t.run(async (ctx) => {
|
|
33
|
+
const ids = [];
|
|
34
|
+
for (let i = 0; i < 3; i++)
|
|
35
|
+
ids.push(
|
|
36
|
+
await ctx.db.insert("refunds", {
|
|
37
|
+
...refund,
|
|
38
|
+
stripeRefundId: `re_legacy${i}`,
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
return ids;
|
|
42
|
+
});
|
|
43
|
+
expect(await t.mutation(normalize, { limit: 2 })).toEqual({
|
|
44
|
+
normalized: 2,
|
|
45
|
+
hasMore: true,
|
|
46
|
+
});
|
|
47
|
+
const rows = await t.run(async (ctx) =>
|
|
48
|
+
Promise.all(ids.map((id) => ctx.db.get("refunds", id))),
|
|
49
|
+
);
|
|
50
|
+
expect(
|
|
51
|
+
rows.filter((row) => row?.refundCommandNormalizationVersion === 1),
|
|
52
|
+
).toHaveLength(2);
|
|
53
|
+
expect(await t.mutation(normalize, { limit: 2 })).toEqual({
|
|
54
|
+
normalized: 1,
|
|
55
|
+
hasMore: false,
|
|
56
|
+
});
|
|
57
|
+
expect(await t.mutation(normalize, { limit: 2 })).toEqual({
|
|
58
|
+
normalized: 0,
|
|
59
|
+
hasMore: false,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it.each([0, -1, 101, 1.5, NaN, Infinity])(
|
|
64
|
+
"rejects invalid limit %s before modifying rows",
|
|
65
|
+
async (limit) => {
|
|
66
|
+
const t = convexTest(schema, modules);
|
|
67
|
+
const id = await t.run((ctx) => ctx.db.insert("refunds", refund));
|
|
68
|
+
const before = await t.run((ctx) => ctx.db.get("refunds", id));
|
|
69
|
+
await expect(t.mutation(normalize, { limit })).rejects.toThrow();
|
|
70
|
+
expect(await t.run((ctx) => ctx.db.get("refunds", id))).toEqual(before);
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
it("keeps old plus new duplicates held until normalization, then ambiguous", async () => {
|
|
75
|
+
const t = convexTest(schema, modules);
|
|
76
|
+
await t.run((ctx) => ctx.db.insert("refunds", refund));
|
|
77
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
78
|
+
...refund,
|
|
79
|
+
stripeRefundId: "re_new",
|
|
80
|
+
});
|
|
81
|
+
expect(
|
|
82
|
+
await t.query(api.refundHistory.queries.getRefundCommandEvidence, scope),
|
|
83
|
+
).toEqual({ status: "unavailable", reason: "normalization_incomplete" });
|
|
84
|
+
expect(await t.mutation(normalize, { limit: 1 })).toEqual({
|
|
85
|
+
normalized: 1,
|
|
86
|
+
hasMore: false,
|
|
87
|
+
});
|
|
88
|
+
expect(
|
|
89
|
+
await t.query(api.refundHistory.queries.getRefundCommandEvidence, scope),
|
|
90
|
+
).toEqual({ status: "unavailable", reason: "ambiguous" });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it.each([
|
|
94
|
+
undefined,
|
|
95
|
+
{},
|
|
96
|
+
{ betterStripeRefundCommand: 123 },
|
|
97
|
+
{ betterStripeRefundCommand: scope.commandKey },
|
|
98
|
+
])(
|
|
99
|
+
"normalizes current legacy metadata without touching original financial fields: %j",
|
|
100
|
+
async (metadata) => {
|
|
101
|
+
const t = convexTest(schema, modules);
|
|
102
|
+
const id = await t.run((ctx) =>
|
|
103
|
+
ctx.db.insert("refunds", { ...refund, metadata }),
|
|
104
|
+
);
|
|
105
|
+
const before = await t.run((ctx) => ctx.db.get("refunds", id));
|
|
106
|
+
const started = Date.now();
|
|
107
|
+
await t.mutation(normalize, { limit: 1 });
|
|
108
|
+
const after = await t.run((ctx) => ctx.db.get("refunds", id));
|
|
109
|
+
const {
|
|
110
|
+
refundCommandNormalizationVersion,
|
|
111
|
+
refundCommandKey,
|
|
112
|
+
refundCommandConflict,
|
|
113
|
+
refundCommandObservedAt,
|
|
114
|
+
...raw
|
|
115
|
+
} = after!;
|
|
116
|
+
expect(raw).toEqual(before);
|
|
117
|
+
expect(refundCommandNormalizationVersion).toBe(1);
|
|
118
|
+
expect(refundCommandConflict).toBe(
|
|
119
|
+
metadata?.betterStripeRefundCommand === 123,
|
|
120
|
+
);
|
|
121
|
+
if (typeof metadata?.betterStripeRefundCommand === "string") {
|
|
122
|
+
expect(refundCommandKey).toBe(scope.commandKey);
|
|
123
|
+
expect(refundCommandObservedAt).toBeGreaterThanOrEqual(started);
|
|
124
|
+
expect(refundCommandObservedAt).toBeLessThanOrEqual(Date.now());
|
|
125
|
+
} else {
|
|
126
|
+
expect(refundCommandKey).toBeUndefined();
|
|
127
|
+
expect(refundCommandObservedAt).toBeUndefined();
|
|
128
|
+
}
|
|
129
|
+
await t.mutation(normalize, { limit: 1 });
|
|
130
|
+
expect(await t.run((ctx) => ctx.db.get("refunds", id))).toEqual(after);
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
it("preserves first-known projection and latches contradictory legacy raw metadata", async () => {
|
|
135
|
+
const t = convexTest(schema, modules);
|
|
136
|
+
const id = await t.run((ctx) =>
|
|
137
|
+
ctx.db.insert("refunds", {
|
|
138
|
+
...refund,
|
|
139
|
+
refundCommandKey: "dojo-refund:older_command:v1",
|
|
140
|
+
refundCommandObservedAt: 42,
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
await t.mutation(normalize, { limit: 1 });
|
|
144
|
+
expect(await t.run((ctx) => ctx.db.get("refunds", id))).toMatchObject({
|
|
145
|
+
refundCommandKey: "dojo-refund:older_command:v1",
|
|
146
|
+
refundCommandObservedAt: 42,
|
|
147
|
+
refundCommandConflict: true,
|
|
148
|
+
metadata: refund.metadata,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("retains late enrichment and conflict behavior after a missing-metadata legacy drain", async () => {
|
|
153
|
+
const t = convexTest(schema, modules);
|
|
154
|
+
await t.run((ctx) => ctx.db.insert("refunds", { ...refund, metadata: {} }));
|
|
155
|
+
await t.mutation(normalize, { limit: 1 });
|
|
156
|
+
expect(
|
|
157
|
+
await t.query(api.refundHistory.queries.getRefundCommandEvidence, scope),
|
|
158
|
+
).toEqual({ status: "unavailable", reason: "missing" });
|
|
159
|
+
await t.mutation(api.connect.mutations.upsertRefund, refund);
|
|
160
|
+
expect(
|
|
161
|
+
await t.query(api.refundHistory.queries.getRefundCommandEvidence, scope),
|
|
162
|
+
).toMatchObject({ status: "observed" });
|
|
163
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
164
|
+
...refund,
|
|
165
|
+
metadata: {},
|
|
166
|
+
});
|
|
167
|
+
expect(
|
|
168
|
+
await t.query(api.refundHistory.queries.getRefundCommandEvidence, scope),
|
|
169
|
+
).toEqual({ status: "unavailable", reason: "correlation_conflict" });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("serializes concurrent bounded drains and never rewrites normalized rows", async () => {
|
|
173
|
+
const t = convexTest(schema, modules);
|
|
174
|
+
const ids = await t.run(async (ctx) => {
|
|
175
|
+
const ids = [];
|
|
176
|
+
for (let i = 0; i < 3; i++)
|
|
177
|
+
ids.push(
|
|
178
|
+
await ctx.db.insert("refunds", {
|
|
179
|
+
...refund,
|
|
180
|
+
stripeRefundId: `re_concurrent${i}`,
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
return ids;
|
|
184
|
+
});
|
|
185
|
+
const results = await Promise.all([
|
|
186
|
+
t.mutation(normalize, { limit: 2 }),
|
|
187
|
+
t.mutation(normalize, { limit: 2 }),
|
|
188
|
+
]);
|
|
189
|
+
expect(results.reduce((total, result) => total + result.normalized, 0)).toBe(
|
|
190
|
+
3,
|
|
191
|
+
);
|
|
192
|
+
for (const id of ids)
|
|
193
|
+
expect(await t.run((ctx) => ctx.db.get("refunds", id))).toMatchObject({
|
|
194
|
+
refundCommandNormalizationVersion: 1,
|
|
195
|
+
});
|
|
196
|
+
expect(await t.mutation(normalize, { limit: 1 })).toEqual({
|
|
197
|
+
normalized: 0,
|
|
198
|
+
hasMore: false,
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("accepts the maximum batch and continues one remaining row without a lifetime cap", async () => {
|
|
203
|
+
const t = convexTest(schema, modules);
|
|
204
|
+
await t.run(async (ctx) => {
|
|
205
|
+
for (let i = 0; i < 101; i++)
|
|
206
|
+
await ctx.db.insert("refunds", {
|
|
207
|
+
...refund,
|
|
208
|
+
stripeRefundId: `re_max${i}`,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
expect(await t.mutation(normalize, { limit: 100 })).toEqual({
|
|
212
|
+
normalized: 100,
|
|
213
|
+
hasMore: true,
|
|
214
|
+
});
|
|
215
|
+
expect(await t.mutation(normalize, { limit: 1 })).toEqual({
|
|
216
|
+
normalized: 1,
|
|
217
|
+
hasMore: false,
|
|
218
|
+
});
|
|
219
|
+
await t.run((ctx) =>
|
|
220
|
+
ctx.db.insert("refunds", { ...refund, stripeRefundId: "re_late" }),
|
|
221
|
+
);
|
|
222
|
+
expect(
|
|
223
|
+
await t.query(api.refundHistory.queries.getRefundCommandEvidence, scope),
|
|
224
|
+
).toEqual({ status: "unavailable", reason: "normalization_incomplete" });
|
|
225
|
+
expect(await t.mutation(normalize, { limit: 1 })).toEqual({
|
|
226
|
+
normalized: 1,
|
|
227
|
+
hasMore: false,
|
|
228
|
+
});
|
|
229
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { api } from "../_generated/api.js";
|
|
4
|
+
import { schema, modules } from "../../test.js";
|
|
5
|
+
import { refundCommandBinding } from "./commandBinding.js";
|
|
6
|
+
const key = "dojo-refund:provenance_command:v1";
|
|
7
|
+
const metadata = { betterStripeRefundCommand: key };
|
|
8
|
+
const scope = {
|
|
9
|
+
commandKey: key,
|
|
10
|
+
accountId: "acct_original",
|
|
11
|
+
stripePaymentIntentId: "pi_original",
|
|
12
|
+
stripeChargeId: "ch_original",
|
|
13
|
+
currency: "jpy",
|
|
14
|
+
};
|
|
15
|
+
const read = api.refundHistory.queries.getRefundCommandEvidence;
|
|
16
|
+
|
|
17
|
+
it("preserves first observed binding time without treating legacy insertion as provider creation", () => {
|
|
18
|
+
const first = refundCommandBinding({ metadata }, {}, 2000);
|
|
19
|
+
expect(first.refundCommandObservedAt).toBe(2000);
|
|
20
|
+
const later = refundCommandBinding(
|
|
21
|
+
{ ...first, metadata },
|
|
22
|
+
{ metadata },
|
|
23
|
+
3000,
|
|
24
|
+
);
|
|
25
|
+
expect(later.refundCommandObservedAt).toBe(2000);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it.each([-1, NaN, Infinity, Number.MAX_SAFE_INTEGER])(
|
|
29
|
+
"holds malformed or future observed binding time %s",
|
|
30
|
+
async (observedAt) => {
|
|
31
|
+
const t = convexTest(schema, modules);
|
|
32
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
33
|
+
stripeRefundId: "re_original",
|
|
34
|
+
accountId: scope.accountId,
|
|
35
|
+
stripePaymentIntentId: scope.stripePaymentIntentId,
|
|
36
|
+
stripeChargeId: scope.stripeChargeId,
|
|
37
|
+
currency: "jpy",
|
|
38
|
+
amount: 125,
|
|
39
|
+
status: "succeeded",
|
|
40
|
+
metadata,
|
|
41
|
+
});
|
|
42
|
+
await t.run(async (ctx) => {
|
|
43
|
+
const row = await ctx.db
|
|
44
|
+
.query("refunds")
|
|
45
|
+
.withIndex("by_stripe_refund_id", (q) =>
|
|
46
|
+
q.eq("stripeRefundId", "re_original"),
|
|
47
|
+
)
|
|
48
|
+
.unique();
|
|
49
|
+
if (!row) throw new Error("Missing QA refund");
|
|
50
|
+
await ctx.db.patch("refunds", row._id, {
|
|
51
|
+
refundCommandObservedAt: observedAt,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
expect(await t.query(read, scope)).toEqual({
|
|
55
|
+
status: "unavailable",
|
|
56
|
+
reason: "invalid_receipt",
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
);
|