@fantastic.dev/better-stripe 0.29.0 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/MIGRATION.md +8 -0
  3. package/README.md +10 -1
  4. package/dist/client/connect/payoutActivationProof.d.ts.map +1 -1
  5. package/dist/client/connect/payoutActivationProof.js +88 -42
  6. package/dist/client/connect/payoutActivationProof.js.map +1 -1
  7. package/dist/client/connect/payoutAdoption.d.ts +3 -0
  8. package/dist/client/connect/payoutAdoption.d.ts.map +1 -1
  9. package/dist/client/connect/payoutAdoption.js +218 -183
  10. package/dist/client/connect/payoutAdoption.js.map +1 -1
  11. package/dist/client/connect/payoutAdoptionCollection.d.ts +21 -0
  12. package/dist/client/connect/payoutAdoptionCollection.d.ts.map +1 -0
  13. package/dist/client/connect/payoutAdoptionCollection.js +44 -0
  14. package/dist/client/connect/payoutAdoptionCollection.js.map +1 -0
  15. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +26 -6
  16. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  17. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +13 -3
  18. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  19. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +3745 -0
  20. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -0
  21. package/dist/client/connect/payoutLargeAdoptionTestHelpers.js +55 -0
  22. package/dist/client/connect/payoutLargeAdoptionTestHelpers.js.map +1 -0
  23. package/dist/client/connect/payoutOutcomeBatches.d.ts +5 -0
  24. package/dist/client/connect/payoutOutcomeBatches.d.ts.map +1 -0
  25. package/dist/client/connect/payoutOutcomeBatches.js +21 -0
  26. package/dist/client/connect/payoutOutcomeBatches.js.map +1 -0
  27. package/dist/client/connect/payoutPolicyState.d.ts +14 -0
  28. package/dist/client/connect/payoutPolicyState.d.ts.map +1 -0
  29. package/dist/client/connect/payoutPolicyState.js +19 -0
  30. package/dist/client/connect/payoutPolicyState.js.map +1 -0
  31. package/dist/client/connect/payoutQualification.js +1 -1
  32. package/dist/client/connect/payoutQualification.js.map +1 -1
  33. package/dist/client/connect/payoutReconciliation.d.ts +11 -6
  34. package/dist/client/connect/payoutReconciliation.d.ts.map +1 -1
  35. package/dist/client/connect/payoutReconciliation.js +62 -16
  36. package/dist/client/connect/payoutReconciliation.js.map +1 -1
  37. package/dist/client/connect/payoutResumableProof.d.ts +17 -0
  38. package/dist/client/connect/payoutResumableProof.d.ts.map +1 -0
  39. package/dist/client/connect/payoutResumableProof.js +25 -0
  40. package/dist/client/connect/payoutResumableProof.js.map +1 -0
  41. package/dist/client/connect/payoutSyncTestHelpers.d.ts +13 -3
  42. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  43. package/dist/client/connect/transferReceipt.d.ts +6 -2
  44. package/dist/client/connect/transferReceipt.d.ts.map +1 -1
  45. package/dist/client/connect/transferReceipt.js +3 -3
  46. package/dist/client/connect/transferReceipt.js.map +1 -1
  47. package/dist/client/payoutPolicy.d.ts.map +1 -1
  48. package/dist/client/payoutPolicy.js +24 -14
  49. package/dist/client/payoutPolicy.js.map +1 -1
  50. package/dist/component/_generated/component.d.ts +72 -0
  51. package/dist/component/_generated/component.d.ts.map +1 -1
  52. package/dist/component/earnings/triggers.d.ts +12 -4
  53. package/dist/component/earnings/triggers.d.ts.map +1 -1
  54. package/dist/component/payoutPolicy/adoption.d.ts.map +1 -1
  55. package/dist/component/payoutPolicy/adoption.js +12 -7
  56. package/dist/component/payoutPolicy/adoption.js.map +1 -1
  57. package/dist/component/payoutPolicy/mutations.d.ts +12 -0
  58. package/dist/component/payoutPolicy/mutations.d.ts.map +1 -1
  59. package/dist/component/payoutPolicy/queries.d.ts +2 -0
  60. package/dist/component/payoutPolicy/queries.d.ts.map +1 -1
  61. package/dist/component/payoutPolicy/schema.d.ts +31 -7
  62. package/dist/component/payoutPolicy/schema.d.ts.map +1 -1
  63. package/dist/component/payoutPolicy/schema.js +2 -0
  64. package/dist/component/payoutPolicy/schema.js.map +1 -1
  65. package/dist/component/payoutRelease/adoption.d.ts +3 -1
  66. package/dist/component/payoutRelease/adoption.d.ts.map +1 -1
  67. package/dist/component/payoutRelease/adoption.js +33 -16
  68. package/dist/component/payoutRelease/adoption.js.map +1 -1
  69. package/dist/component/payoutRelease/fees.d.ts.map +1 -1
  70. package/dist/component/payoutRelease/fees.js +7 -0
  71. package/dist/component/payoutRelease/fees.js.map +1 -1
  72. package/dist/component/payoutRelease/mutations.d.ts +59 -0
  73. package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
  74. package/dist/component/payoutRelease/mutations.js +25 -80
  75. package/dist/component/payoutRelease/mutations.js.map +1 -1
  76. package/dist/component/payoutRelease/outcome.d.ts +69 -0
  77. package/dist/component/payoutRelease/outcome.d.ts.map +1 -0
  78. package/dist/component/payoutRelease/outcome.js +94 -0
  79. package/dist/component/payoutRelease/outcome.js.map +1 -0
  80. package/dist/component/payoutRelease/planning.d.ts.map +1 -1
  81. package/dist/component/payoutRelease/planning.js +5 -2
  82. package/dist/component/payoutRelease/planning.js.map +1 -1
  83. package/dist/component/payoutRelease/queries.d.ts +2 -2
  84. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  85. package/dist/component/payoutRelease/queries.js +2 -0
  86. package/dist/component/payoutRelease/queries.js.map +1 -1
  87. package/dist/component/payoutSnapshots/adoption.d.ts +88 -0
  88. package/dist/component/payoutSnapshots/adoption.d.ts.map +1 -0
  89. package/dist/component/payoutSnapshots/adoption.js +49 -0
  90. package/dist/component/payoutSnapshots/adoption.js.map +1 -0
  91. package/dist/component/payoutSnapshots/financial.d.ts +31 -19
  92. package/dist/component/payoutSnapshots/financial.d.ts.map +1 -1
  93. package/dist/component/payoutSnapshots/financial.js +28 -14
  94. package/dist/component/payoutSnapshots/financial.js.map +1 -1
  95. package/dist/component/payoutSnapshots/localState.d.ts +20 -16
  96. package/dist/component/payoutSnapshots/localState.d.ts.map +1 -1
  97. package/dist/component/payoutSnapshots/localState.js +13 -4
  98. package/dist/component/payoutSnapshots/localState.js.map +1 -1
  99. package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -1
  100. package/dist/component/payoutSnapshots/mutations.js +1 -1
  101. package/dist/component/payoutSnapshots/mutations.js.map +1 -1
  102. package/dist/component/payoutSnapshots/queries.d.ts.map +1 -1
  103. package/dist/component/payoutSnapshots/queries.js +6 -4
  104. package/dist/component/payoutSnapshots/queries.js.map +1 -1
  105. package/dist/component/payoutSnapshots/schema.d.ts +5 -1
  106. package/dist/component/payoutSnapshots/schema.d.ts.map +1 -1
  107. package/dist/component/payoutSnapshots/schema.js +2 -0
  108. package/dist/component/payoutSnapshots/schema.js.map +1 -1
  109. package/dist/component/schema.d.ts +13 -3
  110. package/dist/react/index.d.ts +1 -0
  111. package/dist/react/index.d.ts.map +1 -1
  112. package/dist/react/index.js +1 -0
  113. package/dist/react/index.js.map +1 -1
  114. package/dist/react/lib/payout-format.d.ts +5 -0
  115. package/dist/react/lib/payout-format.d.ts.map +1 -0
  116. package/dist/react/lib/payout-format.js +13 -0
  117. package/dist/react/lib/payout-format.js.map +1 -0
  118. package/dist/react/workflows/Payouts.js +4 -4
  119. package/dist/react/workflows/Payouts.js.map +1 -1
  120. package/docs/react-workflows.md +9 -4
  121. package/docs/settlement.md +61 -8
  122. package/package.json +1 -1
  123. package/src/client/connect/payoutActivationProof.ts +123 -53
  124. package/src/client/connect/payoutAdoption.ts +299 -215
  125. package/src/client/connect/payoutAdoptionCollection.ts +78 -0
  126. package/src/client/connect/payoutAdoptionConcurrency.test.ts +266 -0
  127. package/src/client/connect/payoutCacheIdentity.test.ts +93 -0
  128. package/src/client/connect/payoutLargeAdoption.test.ts +541 -0
  129. package/src/client/connect/payoutLargeAdoptionTestHelpers.ts +74 -0
  130. package/src/client/connect/payoutOutcomeBatches.test.ts +40 -0
  131. package/src/client/connect/payoutOutcomeBatches.ts +24 -0
  132. package/src/client/connect/payoutPolicyState.ts +36 -0
  133. package/src/client/connect/payoutQualification.ts +10 -4
  134. package/src/client/connect/payoutReconciliation.ts +86 -7
  135. package/src/client/connect/payoutResumableProof.ts +41 -0
  136. package/src/client/connect/transferReceipt.ts +3 -2
  137. package/src/client/connect/transferReceiptBaseline.test.ts +55 -0
  138. package/src/client/payoutPolicy.ts +37 -23
  139. package/src/component/_generated/api.ts +4 -0
  140. package/src/component/_generated/component.ts +85 -0
  141. package/src/component/payout-snapshots.test.ts +45 -1
  142. package/src/component/payoutPolicy/adoption.ts +20 -7
  143. package/src/component/payoutPolicy/schema.ts +2 -0
  144. package/src/component/payoutRelease/adoption.ts +57 -27
  145. package/src/component/payoutRelease/fees.ts +9 -0
  146. package/src/component/payoutRelease/mutations.ts +26 -96
  147. package/src/component/payoutRelease/outcome.ts +119 -0
  148. package/src/component/payoutRelease/planning.ts +5 -2
  149. package/src/component/payoutRelease/queries.ts +2 -0
  150. package/src/component/payoutSnapshots/adoption.ts +73 -0
  151. package/src/component/payoutSnapshots/financial.ts +33 -20
  152. package/src/component/payoutSnapshots/localState.ts +17 -3
  153. package/src/component/payoutSnapshots/mutations.ts +8 -1
  154. package/src/component/payoutSnapshots/queries.ts +8 -6
  155. package/src/component/payoutSnapshots/schema.ts +2 -0
  156. package/src/react/index.ts +1 -0
  157. package/src/react/lib/payout-format.ts +16 -0
  158. package/src/react/workflows/Payouts.tsx +7 -5
@@ -0,0 +1,266 @@
1
+ import { runAdoptionMutation } from "./payoutAdoptionCollection.js";
2
+ // @vitest-environment edge-runtime
3
+ import { expect, it } from "vitest";
4
+ import type Stripe from "stripe";
5
+ import type { RunCtx } from "../helpers.js";
6
+ import { PayoutPolicyClient } from "../payoutPolicy.js";
7
+ import { setup, scope, component } from "./payoutAdoptionTestHelpers.js";
8
+ it.each(["proof read", "begin attempt"] as const)(
9
+ "reconciles an identical activation completed while another caller was delayed at %s",
10
+ async (boundary) => {
11
+ const s = await setup(Array.from({ length: 101 }, () => 10));
12
+ const now = Math.floor(Date.now() / 1000);
13
+ s.setTransactions(
14
+ s
15
+ .transactions()
16
+ .map((t) => ({ ...t, created: now - 100, available_on: now - 50 })),
17
+ );
18
+ s.provider.balanceTransactions.list.mockImplementation(async (params) => {
19
+ const p = params as typeof params & {
20
+ currency?: string;
21
+ starting_after?: string;
22
+ };
23
+ const rows = s
24
+ .transactions()
25
+ .filter(
26
+ (t) =>
27
+ (!p.source || t.source === p.source) &&
28
+ (!p.currency || t.currency === p.currency),
29
+ );
30
+ const start = p.starting_after
31
+ ? rows.findIndex((t) => t.id === p.starting_after) + 1
32
+ : 0;
33
+ const data = rows.slice(start, start + (p.limit ?? 100));
34
+ return { data, has_more: start + data.length < rows.length };
35
+ });
36
+ const client = clientFor(s);
37
+ const operationKey = "concurrent-activate";
38
+ expect(
39
+ await client.prepare(s.ctx, {
40
+ accountId: scope.accountId,
41
+ ownerKey: scope.ownerKey,
42
+ operationKey,
43
+ expectedRevision: 0,
44
+ mode: "custom",
45
+ thresholds: [{ currency: "usd", amount: 1000 }],
46
+ consent: true,
47
+ adoptExistingBalance: true,
48
+ }),
49
+ ).toMatchObject({ status: "prepared" });
50
+ let unblockFirst!: () => void, unblockSecond!: () => void;
51
+ const secondIsReading = new Promise<void>((resolve) => {
52
+ unblockFirst = resolve;
53
+ });
54
+ const firstCompleted = new Promise<void>((resolve) => {
55
+ unblockSecond = resolve;
56
+ });
57
+ const query = s.ctx.runQuery,
58
+ mutation = s.ctx.runMutation!;
59
+ const path = (ref: unknown) =>
60
+ (ref as Record<symbol, string>)[Symbol.for("toReferencePath")];
61
+ const firstCtx: RunCtx = {
62
+ ...s.ctx,
63
+ runMutation: async (ref, ...args) => {
64
+ if (path(ref).endsWith("payoutPolicy/mutations/beginAttempt"))
65
+ await secondIsReading;
66
+ return mutation(ref, ...args);
67
+ },
68
+ };
69
+ let delayed = false;
70
+ const secondCtx: RunCtx = {
71
+ ...s.ctx,
72
+ runQuery: async (ref, ...args) => {
73
+ if (
74
+ boundary === "proof read" &&
75
+ !delayed &&
76
+ path(ref).endsWith("payoutSnapshots/queries/sources")
77
+ ) {
78
+ delayed = true;
79
+ unblockFirst();
80
+ await firstCompleted;
81
+ }
82
+ return query(ref, ...args);
83
+ },
84
+ runMutation: async (ref, ...args) => {
85
+ if (
86
+ boundary === "begin attempt" &&
87
+ path(ref).endsWith("payoutPolicy/mutations/beginAttempt")
88
+ ) {
89
+ delayed = true;
90
+ unblockFirst();
91
+ await firstCompleted;
92
+ }
93
+ return mutation(ref, ...args);
94
+ },
95
+ };
96
+ const args = {
97
+ accountId: scope.accountId,
98
+ ownerKey: scope.ownerKey,
99
+ operationKey,
100
+ };
101
+ const first = client.apply(firstCtx, args).finally(unblockSecond);
102
+ const second = client.apply(secondCtx, args).finally(unblockFirst);
103
+ const results = await Promise.allSettled([first, second]);
104
+ expect(delayed).toBe(true);
105
+ expect(results.map((r) => r.status)).toEqual(["fulfilled", "fulfilled"]);
106
+ for (const result of results)
107
+ if (result.status === "fulfilled")
108
+ expect(result.value).toMatchObject({ status: "ready" });
109
+ expect(await client.release(s.ctx, scope)).toMatchObject({
110
+ status: "updated",
111
+ claim: { status: "paid", amount: 1010 },
112
+ });
113
+ expect(s.provider.payouts.create).toHaveBeenCalledTimes(1);
114
+ expect(
115
+ await s.t.run((ctx) => ctx.db.query("payoutSnapshots").collect()),
116
+ ).toEqual([]);
117
+ },
118
+ 15000,
119
+ );
120
+
121
+ it("preserves proof failures while the durable activation is still unattempted", async () => {
122
+ const s = await setup([100]);
123
+ const { collectResumableAdoptionProof } =
124
+ await import("./payoutResumableProof.js");
125
+ const failure = new Error("provider proof unavailable");
126
+ s.provider.balance.retrieve.mockRejectedValueOnce(failure);
127
+ const query = s.ctx.runQuery;
128
+ const ctx: RunCtx = {
129
+ ...s.ctx,
130
+ runQuery: async (ref, ...args) => {
131
+ const path = (ref as Record<symbol, string>)[
132
+ Symbol.for("toReferencePath")
133
+ ];
134
+ if (path.endsWith("payoutPolicy/queries/operation"))
135
+ return { status: "pending", attempted: false } as never;
136
+ return query(ref, ...args);
137
+ },
138
+ };
139
+ await expect(
140
+ collectResumableAdoptionProof(
141
+ s.provider as unknown as Stripe,
142
+ component,
143
+ ctx,
144
+ { ...scope, operationKey: "still-unattempted" },
145
+ 0,
146
+ ["usd"],
147
+ "apply",
148
+ ),
149
+ ).rejects.toBe(failure);
150
+ expect(s.provider.payouts.create).not.toHaveBeenCalled();
151
+ });
152
+
153
+ function clientFor(s: Awaited<ReturnType<typeof setup>>) {
154
+ let schedule: Record<string, unknown> = {
155
+ interval: "weekly",
156
+ weekly_payout_days: ["monday"],
157
+ };
158
+ Object.assign(s.provider, {
159
+ v2: {
160
+ core: {
161
+ accounts: {
162
+ retrieve: async () => ({
163
+ id: scope.accountId,
164
+ dashboard: "none",
165
+ identity: { country: "US" },
166
+ }),
167
+ },
168
+ },
169
+ },
170
+ balanceSettings: {
171
+ retrieve: async () => ({
172
+ payments: { payouts: { status: "enabled", schedule } },
173
+ }),
174
+ update: async (args: {
175
+ payments: { payouts: { schedule: Record<string, unknown> } };
176
+ }) => {
177
+ schedule = args.payments.payouts.schedule;
178
+ return { payments: { payouts: { status: "enabled", schedule } } };
179
+ },
180
+ },
181
+ });
182
+ return new PayoutPolicyClient(
183
+ component,
184
+ () => s.provider as unknown as Stripe,
185
+ );
186
+ }
187
+
188
+ it("reconciles a lost beginAttempt response without repeating an already-attempted boundary", async () => {
189
+ const s = await setup([]),
190
+ client = clientFor(s);
191
+ const args = {
192
+ accountId: scope.accountId,
193
+ ownerKey: scope.ownerKey,
194
+ operationKey: "lost-begin-response",
195
+ };
196
+ expect(
197
+ await client.prepare(s.ctx, {
198
+ ...args,
199
+ expectedRevision: 0,
200
+ mode: "custom",
201
+ thresholds: [{ currency: "usd", amount: 100 }],
202
+ consent: true,
203
+ adoptExistingBalance: true,
204
+ }),
205
+ ).toMatchObject({ status: "prepared" });
206
+ const mutation = s.ctx.runMutation!;
207
+ let begins = 0;
208
+ const ctx: RunCtx = {
209
+ ...s.ctx,
210
+ runMutation: async (ref, ...params) => {
211
+ const result = await mutation(ref, ...params);
212
+ if (
213
+ (ref as Record<symbol, string>)[Symbol.for("toReferencePath")].endsWith(
214
+ "payoutPolicy/mutations/beginAttempt",
215
+ ) &&
216
+ ++begins === 1
217
+ )
218
+ throw Error(
219
+ "Simulated lost response after the durable attempt committed",
220
+ );
221
+ return result;
222
+ },
223
+ };
224
+ expect(await client.apply(ctx, args)).toMatchObject({
225
+ status: "ready",
226
+ operation: { attempted: true, status: "complete" },
227
+ });
228
+ expect(begins).toBe(1);
229
+ expect(s.provider.payouts.create).not.toHaveBeenCalled();
230
+ });
231
+
232
+ it("preserves a genuine beginAttempt failure while the operation is unattempted", async () => {
233
+ const s = await setup([]),
234
+ client = clientFor(s);
235
+ const args = {
236
+ accountId: scope.accountId,
237
+ ownerKey: scope.ownerKey,
238
+ operationKey: "unattempted-boundary-failure",
239
+ };
240
+ expect(
241
+ await client.prepare(s.ctx, {
242
+ ...args,
243
+ expectedRevision: 0,
244
+ mode: "custom",
245
+ thresholds: [{ currency: "usd", amount: 100 }],
246
+ consent: true,
247
+ adoptExistingBalance: true,
248
+ }),
249
+ ).toMatchObject({ status: "prepared" });
250
+ const failure = Error(
251
+ "Simulated unavailable mutation before any attempt committed",
252
+ );
253
+ const ctx: RunCtx = {
254
+ ...s.ctx,
255
+ runMutation: async () => {
256
+ throw failure;
257
+ },
258
+ };
259
+ await expect(
260
+ runAdoptionMutation(component, ctx, "beginAttempt", args),
261
+ ).rejects.toBe(failure);
262
+ const operation = await client.operation(s.ctx, args);
263
+ expect(operation).toMatchObject({ status: "pending" });
264
+ expect(operation?.attempted).not.toBe(true);
265
+ expect(s.provider.payouts.create).not.toHaveBeenCalled();
266
+ });
@@ -0,0 +1,93 @@
1
+ // @vitest-environment edge-runtime
2
+ import { expect, it } from "vitest";
3
+ import { setup, scope, component } from "./payoutAdoptionTestHelpers.js";
4
+ import { collectLargePayoutInput } from "./payoutCollectedInput.js";
5
+ import { collectedSources } from "../../component/payoutSnapshots/financial.js";
6
+ import { financialRevision } from "../../component/payoutSnapshots/revisions.js";
7
+ import {
8
+ checkSnapshot,
9
+ transferFingerprint,
10
+ } from "../../component/payoutRelease/helpers.js";
11
+ async function fixture() {
12
+ const s = await setup(Array.from({ length: 101 }, () => 10));
13
+ const result = await collectLargePayoutInput(
14
+ component,
15
+ s.ctx,
16
+ {
17
+ accountId: scope.accountId,
18
+ ownerKey: scope.ownerKey,
19
+ operationKey: "cache-proof",
20
+ },
21
+ 10,
22
+ );
23
+ if (result.status !== "ready") throw Error("Missing complete cache");
24
+ const observations = result.transfers.map((row, i) => ({
25
+ stripeTransferId: row.stripeTransferId,
26
+ currency: "usd",
27
+ matureNet: 10,
28
+ pendingCredits: 0,
29
+ ledgerFingerprint: transferFingerprint(row),
30
+ observedAt: Date.now(),
31
+ transactionIds: [`txn_${i}`],
32
+ }));
33
+ const snapshotId = result.collection.snapshotId;
34
+ const verify = () =>
35
+ s.t.run(async (ctx) => {
36
+ const revision = await financialRevision(ctx, scope.accountId);
37
+ const collected = await collectedSources(
38
+ ctx,
39
+ { ...scope, snapshotId, liabilityRevision: revision.riskRevision },
40
+ observations,
41
+ );
42
+ const rows = await checkSnapshot(
43
+ ctx,
44
+ scope.accountId,
45
+ observations,
46
+ true,
47
+ undefined,
48
+ collected?.transfers,
49
+ );
50
+ return { sources: rows.size, allocations: collected?.allocations.size };
51
+ });
52
+ const rows = await s.t.run((ctx) =>
53
+ ctx.db.query("payoutSnapshotSources").collect(),
54
+ );
55
+ return { s, rows, verify };
56
+ }
57
+ it("validates older caches without primary document IDs", async () => {
58
+ const f = await fixture();
59
+ await f.s.t.run(async (ctx) => {
60
+ for (const row of f.rows)
61
+ await ctx.db.patch("payoutSnapshotSources", row._id, {
62
+ transferDocId: undefined,
63
+ allocationDocId: undefined,
64
+ });
65
+ });
66
+ expect(await f.verify()).toEqual({ sources: 101, allocations: 101 });
67
+ });
68
+ it("rejects a cached primary ID pointing to another funding source", async () => {
69
+ const f = await fixture();
70
+ await f.s.t.run((ctx) =>
71
+ ctx.db.patch("payoutSnapshotSources", f.rows[0]._id, {
72
+ transferDocId: f.rows[1].transferDocId,
73
+ }),
74
+ );
75
+ await expect(f.verify()).rejects.toThrow("source changed");
76
+ });
77
+ it("rejects a cached primary allocation with foreign identity even when money matches", async () => {
78
+ const f = await fixture();
79
+ await f.s.t.run(async (ctx) => {
80
+ const allocationDocId = await ctx.db.insert("payoutSourceAllocations", {
81
+ accountId: "acct_foreign",
82
+ ownerKey: "foreign",
83
+ stripeTransferId: "tr_foreign",
84
+ currency: "usd",
85
+ paidAmount: 0,
86
+ reservedAmount: 0,
87
+ });
88
+ await ctx.db.patch("payoutSnapshotSources", f.rows[0]._id, {
89
+ allocationDocId,
90
+ });
91
+ });
92
+ await expect(f.verify()).rejects.toThrow("allocation changed");
93
+ });