@fantastic.dev/better-stripe 0.30.2 → 0.30.3
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 +6 -0
- package/README.md +10 -1
- package/docs/affiliate-clawbacks.md +5 -5
- package/docs/settlement.md +1 -1
- package/package.json +2 -2
- package/src/component/{affiliate-direct-payout.test.ts → affiliatePayouts/affiliate-direct-payout.test.ts} +6 -7
- package/src/component/{affiliate-component-pagination.test.ts → affiliateRecovery/affiliate-component-pagination.test.ts} +7 -10
- package/src/component/{affiliate-recovery-lifecycle.test.ts → affiliateRecovery/affiliate-recovery-lifecycle.test.ts} +6 -7
- package/src/component/billing/checkout.test.ts +89 -0
- package/src/component/billing/invoices.test.ts +294 -0
- package/src/component/{store-subscriptions.test.ts → billing/store-subscriptions.test.ts} +2 -3
- package/src/component/{subscription-scoping.test.ts → billing/subscription-scoping.test.ts} +2 -4
- package/src/component/billing/subscriptions.test.ts +477 -0
- package/src/component/{connect.test.ts → connect/connect.test.ts} +2 -4
- package/src/component/{fee-routing.test.ts → connect/fee-routing.test.ts} +2 -4
- package/src/component/connect/payments.test.ts +88 -0
- package/src/component/connect/payouts.test.ts +173 -0
- package/src/component/{reversal-races.test.ts → connect/reversal-races.test.ts} +4 -6
- package/src/component/{seller-case-ownership.test.ts → connect/seller-case-ownership.test.ts} +2 -3
- package/src/component/{transfers.test.ts → connect/transfers.test.ts} +3 -5
- package/src/component/core/accounts.test.ts +266 -0
- package/src/component/{config-queries.test.ts → core/config-queries.test.ts} +2 -4
- package/src/component/{payout-reset-safety.test.ts → core/payout-reset-safety.test.ts} +1 -2
- package/src/component/core/reset.test.ts +124 -0
- package/src/component/{cost-recovery.test.ts → costRecovery/cost-recovery.test.ts} +1 -2
- package/src/component/{currency-migration.test.ts → earnings/currency-migration.test.ts} +2 -3
- package/src/component/{currency-totals.test.ts → earnings/currency-totals.test.ts} +2 -3
- package/src/component/{earnings-totals.test.ts → earnings/earnings-totals.test.ts} +3 -5
- package/src/component/{summary-arithmetic.test.ts → earnings/summary-arithmetic.test.ts} +2 -3
- package/src/component/{payout-policy-adoption.test.ts → payoutPolicy/payout-policy-adoption.test.ts} +2 -3
- package/src/component/{payout-policy.test.ts → payoutPolicy/payout-policy.test.ts} +1 -2
- package/src/component/{payout-adoption.test.ts → payoutRelease/payout-adoption.test.ts} +2 -6
- package/src/component/{payout-fees.test.ts → payoutRelease/payout-fees.test.ts} +2 -3
- package/src/component/{payout-recovery-integration.test.ts → payoutRelease/payout-recovery-integration.test.ts} +3 -4
- package/src/component/{payout-release-snapshot.test.ts → payoutRelease/payout-release-snapshot.test.ts} +1 -2
- package/src/component/{payout-release.test.ts → payoutRelease/payout-release.test.ts} +2 -3
- package/src/component/{payout-revisions.test.ts → payoutSnapshots/payout-revisions.test.ts} +1 -2
- package/src/component/{payout-snapshots.test.ts → payoutSnapshots/payout-snapshots.test.ts} +4 -5
- package/src/component/{payout-sync.test.ts → payoutSync/payout-sync.test.ts} +1 -2
- package/src/component/{payout-component-pagination.test.ts → payoutWorker/payout-component-pagination.test.ts} +8 -9
- package/src/component/{payout-worker.test.ts → payoutWorker/payout-worker.test.ts} +1 -2
- package/src/component/products/products.test.ts +239 -0
- package/src/component/{read-pagination.test.ts → products/read-pagination.test.ts} +2 -3
- package/src/component/{refund-history.test.ts → refundHistory/refund-history.test.ts} +2 -3
- package/src/component/{affiliate-clawbacks.test.ts → settlement/affiliate-clawbacks.test.ts} +3 -4
- package/src/component/{settlement-claims.test.ts → settlement/settlement-claims.test.ts} +2 -3
- package/src/component/webhooks/events.test.ts +121 -0
- package/src/component/{triggers.test.ts → webhooks/triggers.test.ts} +2 -4
- package/src/component/public.test.ts +0 -1858
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { convexTest } from "convex-test";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { api } from "../_generated/api.js";
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
6
|
+
|
|
7
|
+
describe("connect — payout mutations and queries", () => {
|
|
8
|
+
it("upsertPayout + getPayout round trip", async () => {
|
|
9
|
+
const t = convexTest(schema, modules);
|
|
10
|
+
|
|
11
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
12
|
+
stripePayoutId: "po_001",
|
|
13
|
+
accountId: "acct_po_001",
|
|
14
|
+
amount: 10000,
|
|
15
|
+
currency: "usd",
|
|
16
|
+
status: "pending",
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const payouts = await t.run(async (ctx) => {
|
|
20
|
+
return await ctx.db.query("payouts").collect();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(payouts).toHaveLength(1);
|
|
24
|
+
|
|
25
|
+
const payout = await t.query(api.connect.queries.getPayout, {
|
|
26
|
+
payoutId: payouts[0]._id,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
expect(payout).toMatchObject({
|
|
30
|
+
stripePayoutId: "po_001",
|
|
31
|
+
amount: 10000,
|
|
32
|
+
status: "pending",
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("upsertPayout updates existing payout", async () => {
|
|
37
|
+
const t = convexTest(schema, modules);
|
|
38
|
+
|
|
39
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
40
|
+
stripePayoutId: "po_002",
|
|
41
|
+
accountId: "acct_po_002",
|
|
42
|
+
amount: 7500,
|
|
43
|
+
currency: "usd",
|
|
44
|
+
status: "pending",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
48
|
+
stripePayoutId: "po_002",
|
|
49
|
+
accountId: "acct_po_002",
|
|
50
|
+
amount: 7500,
|
|
51
|
+
currency: "usd",
|
|
52
|
+
status: "paid",
|
|
53
|
+
arrivalDate: "2030-01-15",
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const payouts = await t.run(async (ctx) => {
|
|
57
|
+
return await ctx.db.query("payouts").collect();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(payouts).toHaveLength(1);
|
|
61
|
+
expect(payouts[0].status).toBe("paid");
|
|
62
|
+
expect(payouts[0].arrivalDate).toBe("2030-01-15");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("listPayouts: filters by accountId", async () => {
|
|
66
|
+
const t = convexTest(schema, modules);
|
|
67
|
+
|
|
68
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
69
|
+
stripePayoutId: "po_acct_a",
|
|
70
|
+
accountId: "acct_a",
|
|
71
|
+
amount: 1000,
|
|
72
|
+
currency: "usd",
|
|
73
|
+
status: "paid",
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
77
|
+
stripePayoutId: "po_acct_b",
|
|
78
|
+
accountId: "acct_b",
|
|
79
|
+
amount: 2000,
|
|
80
|
+
currency: "usd",
|
|
81
|
+
status: "paid",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const payouts = await t.query(api.connect.queries.listPayouts, {
|
|
85
|
+
accountId: "acct_a",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(payouts).toHaveLength(1);
|
|
89
|
+
expect(payouts[0].stripePayoutId).toBe("po_acct_a");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("listPayouts: filters by status", async () => {
|
|
93
|
+
const t = convexTest(schema, modules);
|
|
94
|
+
|
|
95
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
96
|
+
stripePayoutId: "po_pending",
|
|
97
|
+
accountId: "acct_st",
|
|
98
|
+
amount: 500,
|
|
99
|
+
currency: "usd",
|
|
100
|
+
status: "pending",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
104
|
+
stripePayoutId: "po_paid",
|
|
105
|
+
accountId: "acct_st",
|
|
106
|
+
amount: 1500,
|
|
107
|
+
currency: "usd",
|
|
108
|
+
status: "paid",
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const pending = await t.query(api.connect.queries.listPayouts, {
|
|
112
|
+
status: "pending",
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(pending).toHaveLength(1);
|
|
116
|
+
expect(pending[0].stripePayoutId).toBe("po_pending");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("listPayouts: returns all when no filter", async () => {
|
|
120
|
+
const t = convexTest(schema, modules);
|
|
121
|
+
|
|
122
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
123
|
+
stripePayoutId: "po_all_1",
|
|
124
|
+
accountId: "acct_all",
|
|
125
|
+
amount: 100,
|
|
126
|
+
currency: "usd",
|
|
127
|
+
status: "pending",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
131
|
+
stripePayoutId: "po_all_2",
|
|
132
|
+
accountId: "acct_all",
|
|
133
|
+
amount: 200,
|
|
134
|
+
currency: "eur",
|
|
135
|
+
status: "paid",
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const all = await t.query(api.connect.queries.listPayouts, {});
|
|
139
|
+
|
|
140
|
+
expect(all).toHaveLength(2);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("getPayoutByStripeId: returns matching payout", async () => {
|
|
144
|
+
const t = convexTest(schema, modules);
|
|
145
|
+
|
|
146
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
147
|
+
stripePayoutId: "po_by_stripe_001",
|
|
148
|
+
accountId: "acct_po_stripe",
|
|
149
|
+
amount: 8800,
|
|
150
|
+
currency: "usd",
|
|
151
|
+
status: "paid",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const payout = await t.query(api.connect.queries.getPayoutByStripeId, {
|
|
155
|
+
stripePayoutId: "po_by_stripe_001",
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
expect(payout).not.toBeNull();
|
|
159
|
+
expect(payout!.stripePayoutId).toBe("po_by_stripe_001");
|
|
160
|
+
expect(payout!.accountId).toBe("acct_po_stripe");
|
|
161
|
+
expect(payout!.amount).toBe(8800);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("getPayoutByStripeId: returns null for unknown id", async () => {
|
|
165
|
+
const t = convexTest(schema, modules);
|
|
166
|
+
|
|
167
|
+
const payout = await t.query(api.connect.queries.getPayoutByStripeId, {
|
|
168
|
+
stripePayoutId: "po_does_not_exist",
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(payout).toBeNull();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -16,17 +16,15 @@
|
|
|
16
16
|
import { convexTest } from "convex-test";
|
|
17
17
|
import { describe, expect, it, vi } from "vitest";
|
|
18
18
|
|
|
19
|
-
import type { Component, RunCtx } from "
|
|
19
|
+
import type { Component, RunCtx } from "../../client/helpers.js";
|
|
20
20
|
import {
|
|
21
21
|
listWedgedReversalClaims,
|
|
22
22
|
reclaimReversalClaim,
|
|
23
23
|
reverseTransfers,
|
|
24
24
|
reverseTransfersForRefund,
|
|
25
|
-
} from "
|
|
26
|
-
import { api } from "
|
|
27
|
-
import schema from "
|
|
28
|
-
|
|
29
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
25
|
+
} from "../../client/connect/transfers.js";
|
|
26
|
+
import { api } from "../_generated/api.js";
|
|
27
|
+
import { schema, modules } from "../../test.js";
|
|
30
28
|
|
|
31
29
|
const TO_REF = Symbol.for("toReferencePath");
|
|
32
30
|
|
package/src/component/{seller-case-ownership.test.ts → connect/seller-case-ownership.test.ts}
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { convexTest } from "convex-test";
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
|
-
import { api } from "
|
|
4
|
-
import schema from "
|
|
5
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
3
|
+
import { api } from "../_generated/api";
|
|
4
|
+
import { schema, modules } from "../../test.js";
|
|
6
5
|
const payment = {
|
|
7
6
|
stripePaymentIntentId: "pi_sale",
|
|
8
7
|
userId: "customer",
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
import { convexTest } from "convex-test";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
|
|
5
|
-
import { createUseSplitBreakdown } from "
|
|
5
|
+
import { createUseSplitBreakdown } from "../../react/hooks/useSplitBreakdown.js";
|
|
6
6
|
|
|
7
|
-
import { api } from "
|
|
8
|
-
import schema from "
|
|
9
|
-
|
|
10
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
7
|
+
import { api } from "../_generated/api.js";
|
|
8
|
+
import { schema, modules } from "../../test.js";
|
|
11
9
|
|
|
12
10
|
describe("complete split-leg reads", () => {
|
|
13
11
|
it("returns every original leg beyond the former 50-row cap and filters audit rows before limiting", async () => {
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { convexTest } from "convex-test";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { api } from "../_generated/api.js";
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
6
|
+
|
|
7
|
+
describe("core — account mutations and queries", () => {
|
|
8
|
+
it("upsertAccount: inserts new account", async () => {
|
|
9
|
+
const t = convexTest(schema, modules);
|
|
10
|
+
|
|
11
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
12
|
+
stripeAccountId: "acct_001",
|
|
13
|
+
userId: "user_001",
|
|
14
|
+
name: "Test Account",
|
|
15
|
+
email: "test@example.com",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const account = await t.query(api.core.queries.getAccountByUserId, {
|
|
19
|
+
userId: "user_001",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
expect(account).not.toBeNull();
|
|
23
|
+
expect(account!.stripeAccountId).toBe("acct_001");
|
|
24
|
+
expect(account!.userId).toBe("user_001");
|
|
25
|
+
expect(account!.name).toBe("Test Account");
|
|
26
|
+
expect(account!.onboardingStatus).toBe("pending");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("upsertAccount: updates existing account by stripeAccountId", async () => {
|
|
30
|
+
const t = convexTest(schema, modules);
|
|
31
|
+
|
|
32
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
33
|
+
stripeAccountId: "acct_002",
|
|
34
|
+
userId: "user_002",
|
|
35
|
+
name: "Original Name",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
39
|
+
stripeAccountId: "acct_002",
|
|
40
|
+
userId: "user_002",
|
|
41
|
+
name: "Updated Name",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const account = await t.query(api.core.queries.getAccountByUserId, {
|
|
45
|
+
userId: "user_002",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(account).not.toBeNull();
|
|
49
|
+
expect(account!.name).toBe("Updated Name");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("getAccountByUserId: returns matching account", async () => {
|
|
53
|
+
const t = convexTest(schema, modules);
|
|
54
|
+
|
|
55
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
56
|
+
stripeAccountId: "acct_003",
|
|
57
|
+
userId: "user_003",
|
|
58
|
+
email: "found@example.com",
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const account = await t.query(api.core.queries.getAccountByUserId, {
|
|
62
|
+
userId: "user_003",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(account).not.toBeNull();
|
|
66
|
+
expect(account!.userId).toBe("user_003");
|
|
67
|
+
expect(account!.email).toBe("found@example.com");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("getAccountByUserId: returns null for unknown user", async () => {
|
|
71
|
+
const t = convexTest(schema, modules);
|
|
72
|
+
|
|
73
|
+
const account = await t.query(api.core.queries.getAccountByUserId, {
|
|
74
|
+
userId: "user_nonexistent",
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(account).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("getAccountOnboardingStatus reflects missingRequirements and readiness", async () => {
|
|
81
|
+
const t = convexTest(schema, modules);
|
|
82
|
+
|
|
83
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
84
|
+
stripeAccountId: "acct_004",
|
|
85
|
+
userId: "user_004",
|
|
86
|
+
onboardingStatus: "complete",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const account = await t.query(api.core.queries.getAccountByStripeId, {
|
|
90
|
+
stripeAccountId: "acct_004",
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const status = await t.query(api.core.queries.getAccountOnboardingStatus, {
|
|
94
|
+
accountId: account!._id,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
expect(status).not.toBeNull();
|
|
98
|
+
expect(status!.isReady).toBe(true);
|
|
99
|
+
expect(status!.onboardingStatus).toBe("complete");
|
|
100
|
+
expect(status!.missingRequirements).toEqual([]);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("core — getAccountByOrgId", () => {
|
|
105
|
+
it("returns account matching orgId", async () => {
|
|
106
|
+
const t = convexTest(schema, modules);
|
|
107
|
+
|
|
108
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
109
|
+
stripeAccountId: "acct_org_001",
|
|
110
|
+
userId: "user_org_001",
|
|
111
|
+
orgId: "org_001",
|
|
112
|
+
name: "Org Account",
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const account = await t.query(api.core.queries.getAccountByOrgId, {
|
|
116
|
+
orgId: "org_001",
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(account).not.toBeNull();
|
|
120
|
+
expect(account!.orgId).toBe("org_001");
|
|
121
|
+
expect(account!.stripeAccountId).toBe("acct_org_001");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("returns null for unknown orgId", async () => {
|
|
125
|
+
const t = convexTest(schema, modules);
|
|
126
|
+
|
|
127
|
+
const account = await t.query(api.core.queries.getAccountByOrgId, {
|
|
128
|
+
orgId: "org_nonexistent",
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(account).toBeNull();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("core — deleteAccountByStripeId", () => {
|
|
136
|
+
it("deletes existing account and returns true", async () => {
|
|
137
|
+
const t = convexTest(schema, modules);
|
|
138
|
+
|
|
139
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
140
|
+
stripeAccountId: "acct_del_001",
|
|
141
|
+
userId: "user_del_001",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const result = await t.mutation(
|
|
145
|
+
api.core.mutations.deleteAccountByStripeId,
|
|
146
|
+
{
|
|
147
|
+
stripeAccountId: "acct_del_001",
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
expect(result).toBe(true);
|
|
152
|
+
|
|
153
|
+
const account = await t.query(api.core.queries.getAccountByStripeId, {
|
|
154
|
+
stripeAccountId: "acct_del_001",
|
|
155
|
+
});
|
|
156
|
+
expect(account).toBeNull();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("returns false for nonexistent account", async () => {
|
|
160
|
+
const t = convexTest(schema, modules);
|
|
161
|
+
|
|
162
|
+
const result = await t.mutation(
|
|
163
|
+
api.core.mutations.deleteAccountByStripeId,
|
|
164
|
+
{
|
|
165
|
+
stripeAccountId: "acct_nonexistent",
|
|
166
|
+
},
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
expect(result).toBe(false);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("core — upsertAccountInternal", () => {
|
|
174
|
+
it("inserts account with required onboardingStatus", async () => {
|
|
175
|
+
const t = convexTest(schema, modules);
|
|
176
|
+
|
|
177
|
+
await t.mutation(api.core.mutations.upsertAccountInternal, {
|
|
178
|
+
stripeAccountId: "acct_int_001",
|
|
179
|
+
userId: "user_int_001",
|
|
180
|
+
onboardingStatus: "in_progress",
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const account = await t.query(api.core.queries.getAccountByStripeId, {
|
|
184
|
+
stripeAccountId: "acct_int_001",
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
expect(account).not.toBeNull();
|
|
188
|
+
expect(account!.onboardingStatus).toBe("in_progress");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("updates existing account onboardingStatus", async () => {
|
|
192
|
+
const t = convexTest(schema, modules);
|
|
193
|
+
|
|
194
|
+
await t.mutation(api.core.mutations.upsertAccountInternal, {
|
|
195
|
+
stripeAccountId: "acct_int_002",
|
|
196
|
+
userId: "user_int_002",
|
|
197
|
+
onboardingStatus: "pending",
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
await t.mutation(api.core.mutations.upsertAccountInternal, {
|
|
201
|
+
stripeAccountId: "acct_int_002",
|
|
202
|
+
userId: "user_int_002",
|
|
203
|
+
onboardingStatus: "complete",
|
|
204
|
+
missingRequirements: [],
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const account = await t.query(api.core.queries.getAccountByStripeId, {
|
|
208
|
+
stripeAccountId: "acct_int_002",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
expect(account!.onboardingStatus).toBe("complete");
|
|
212
|
+
expect(account!.missingRequirements).toEqual([]);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("core — onboarding status edge cases", () => {
|
|
217
|
+
it("getAccountOnboardingStatus returns null for nonexistent account", async () => {
|
|
218
|
+
const t = convexTest(schema, modules);
|
|
219
|
+
|
|
220
|
+
// Insert then delete to get a valid but missing ID
|
|
221
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
222
|
+
stripeAccountId: "acct_ghost",
|
|
223
|
+
userId: "user_ghost",
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const account = await t.query(api.core.queries.getAccountByStripeId, {
|
|
227
|
+
stripeAccountId: "acct_ghost",
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
await t.mutation(api.core.mutations.deleteAccountByStripeId, {
|
|
231
|
+
stripeAccountId: "acct_ghost",
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const status = await t.query(api.core.queries.getAccountOnboardingStatus, {
|
|
235
|
+
accountId: account!._id,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
expect(status).toBeNull();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("incomplete account has isReady false and missingRequirements", async () => {
|
|
242
|
+
const t = convexTest(schema, modules);
|
|
243
|
+
|
|
244
|
+
await t.mutation(api.core.mutations.upsertAccountInternal, {
|
|
245
|
+
stripeAccountId: "acct_incomplete",
|
|
246
|
+
userId: "user_incomplete",
|
|
247
|
+
onboardingStatus: "restricted",
|
|
248
|
+
missingRequirements: ["external_account", "tos_acceptance"],
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const account = await t.query(api.core.queries.getAccountByStripeId, {
|
|
252
|
+
stripeAccountId: "acct_incomplete",
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const status = await t.query(api.core.queries.getAccountOnboardingStatus, {
|
|
256
|
+
accountId: account!._id,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
expect(status!.isReady).toBe(false);
|
|
260
|
+
expect(status!.onboardingStatus).toBe("restricted");
|
|
261
|
+
expect(status!.missingRequirements).toEqual([
|
|
262
|
+
"external_account",
|
|
263
|
+
"tos_acceptance",
|
|
264
|
+
]);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
import { convexTest } from "convex-test";
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
4
4
|
|
|
5
|
-
import { api } from "
|
|
6
|
-
import schema from "
|
|
7
|
-
|
|
8
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
5
|
+
import { api } from "../_generated/api.js";
|
|
6
|
+
import { schema, modules } from "../../test.js";
|
|
9
7
|
|
|
10
8
|
// Both keys are declared in the component environment and passed by the app.
|
|
11
9
|
describe("core/queries — Stripe config from declared env", () => {
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import { convexTest } from "convex-test";
|
|
3
3
|
import { makeFunctionReference } from "convex/server";
|
|
4
4
|
import { expect, it } from "vitest";
|
|
5
|
-
import schema from "
|
|
6
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
7
6
|
const reset = makeFunctionReference<"mutation">(
|
|
8
7
|
"core/mutations:clearAllTables",
|
|
9
8
|
);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { convexTest } from "convex-test";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import type { TableNames } from "../_generated/dataModel";
|
|
5
|
+
import { api } from "../_generated/api.js";
|
|
6
|
+
import { schema, modules } from "../../test.js";
|
|
7
|
+
|
|
8
|
+
describe("core — clearAllTables", () => {
|
|
9
|
+
it("clearAllTables: removes all records from every table", async () => {
|
|
10
|
+
const t = convexTest(schema, modules);
|
|
11
|
+
|
|
12
|
+
// Seed one row in every schema table so a drifted clear list is caught.
|
|
13
|
+
await t.mutation(api.core.mutations.upsertAccount, {
|
|
14
|
+
stripeAccountId: "acct_clear",
|
|
15
|
+
userId: "user_clear",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await t.mutation(api.products.mutations.upsertProduct, {
|
|
19
|
+
stripeProductId: "prod_clear",
|
|
20
|
+
name: "To Be Cleared",
|
|
21
|
+
active: true,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await t.mutation(api.products.mutations.upsertPrice, {
|
|
25
|
+
stripePriceId: "price_clear",
|
|
26
|
+
productId: "internal_prod_clear",
|
|
27
|
+
stripeProductId: "prod_clear",
|
|
28
|
+
unitAmount: 1000,
|
|
29
|
+
currency: "usd",
|
|
30
|
+
active: true,
|
|
31
|
+
type: "one_time",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await t.mutation(api.billing.mutations.upsertSubscription, {
|
|
35
|
+
stripeSubscriptionId: "sub_clear",
|
|
36
|
+
userId: "user_clear",
|
|
37
|
+
status: "active",
|
|
38
|
+
cancelAtPeriodEnd: false,
|
|
39
|
+
isTrialing: false,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await t.mutation(api.billing.mutations.upsertCheckoutSession, {
|
|
43
|
+
stripeSessionId: "cs_clear",
|
|
44
|
+
userId: "user_clear",
|
|
45
|
+
mode: "subscription",
|
|
46
|
+
status: "open",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await t.mutation(api.billing.mutations.upsertInvoice, {
|
|
50
|
+
stripeInvoiceId: "inv_clear",
|
|
51
|
+
userId: "user_clear",
|
|
52
|
+
status: "paid",
|
|
53
|
+
currency: "usd",
|
|
54
|
+
amountDue: 1000,
|
|
55
|
+
amountPaid: 1000,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
await t.mutation(api.connect.mutations.upsertPayment, {
|
|
59
|
+
stripePaymentIntentId: "pi_clear",
|
|
60
|
+
userId: "user_clear",
|
|
61
|
+
amount: 1000,
|
|
62
|
+
currency: "usd",
|
|
63
|
+
status: "succeeded",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
await t.mutation(api.connect.mutations.upsertPayout, {
|
|
67
|
+
stripePayoutId: "po_clear",
|
|
68
|
+
accountId: "acct_clear",
|
|
69
|
+
amount: 1000,
|
|
70
|
+
currency: "usd",
|
|
71
|
+
status: "paid",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await t.mutation(api.connect.mutations.upsertRefund, {
|
|
75
|
+
stripeRefundId: "re_clear",
|
|
76
|
+
amount: 1000,
|
|
77
|
+
currency: "usd",
|
|
78
|
+
status: "succeeded",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await t.mutation(api.connect.mutations.upsertDispute, {
|
|
82
|
+
stripeDisputeId: "dp_clear",
|
|
83
|
+
amount: 1000,
|
|
84
|
+
currency: "usd",
|
|
85
|
+
status: "needs_response",
|
|
86
|
+
reason: "product_not_received",
|
|
87
|
+
isChargeRefundable: true,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
await t.mutation(api.connect.mutations.upsertTransfer, {
|
|
91
|
+
stripeTransferId: "tr_clear",
|
|
92
|
+
destinationAccountId: "acct_dest_clear",
|
|
93
|
+
amount: 1000,
|
|
94
|
+
currency: "usd",
|
|
95
|
+
status: "paid",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
await t.run(async (ctx) => {
|
|
99
|
+
await ctx.db.insert("transferReversalOps", {
|
|
100
|
+
operationId: "op_clear",
|
|
101
|
+
sourceChargeId: "ch_clear",
|
|
102
|
+
slices: [],
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await t.mutation(api.webhooks.mutations.insertWebhookEvent, {
|
|
107
|
+
stripeEventId: "evt_clear",
|
|
108
|
+
eventType: "invoice.paid",
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const result = await t.mutation(api.core.mutations.clearAllTables, {});
|
|
112
|
+
const tableCount = Object.keys(schema.tables).length;
|
|
113
|
+
|
|
114
|
+
expect(result.cleared).toBe(20);
|
|
115
|
+
expect(result.tables).toHaveLength(tableCount);
|
|
116
|
+
|
|
117
|
+
for (const tableName of Object.keys(schema.tables) as TableNames[]) {
|
|
118
|
+
const remaining = await t.run(async (ctx) =>
|
|
119
|
+
ctx.db.query(tableName).collect(),
|
|
120
|
+
);
|
|
121
|
+
expect(remaining).toHaveLength(0);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import { convexTest } from "convex-test";
|
|
3
3
|
import { makeFunctionReference } from "convex/server";
|
|
4
4
|
import { expect, it } from "vitest";
|
|
5
|
-
import schema from "
|
|
6
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
7
6
|
const m = (name: string) =>
|
|
8
7
|
makeFunctionReference<"mutation">(`costRecovery/${name}`);
|
|
9
8
|
const q = (name: string) =>
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// @vitest-environment edge-runtime
|
|
2
2
|
import { convexTest } from "convex-test";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
|
-
import { api } from "
|
|
5
|
-
import schema from "
|
|
6
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
4
|
+
import { api } from "../_generated/api.js";
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
7
6
|
it("backfills legacy rows in bounded pages, safely interleaved with updates and replay", async () => {
|
|
8
7
|
const t = convexTest(schema, modules);
|
|
9
8
|
await t.run(async (ctx) => {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// @vitest-environment edge-runtime
|
|
2
2
|
import { convexTest } from "convex-test";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
|
-
import { api } from "
|
|
5
|
-
import schema from "
|
|
6
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
4
|
+
import { api } from "../_generated/api.js";
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
7
6
|
it("keeps exact per-currency totals across previews, reversals, reinstatements and payout failures", async () => {
|
|
8
7
|
const t = convexTest(schema, modules);
|
|
9
8
|
for (let i = 0; i < 120; i++) {
|
|
@@ -10,11 +10,9 @@
|
|
|
10
10
|
import { convexTest } from "convex-test";
|
|
11
11
|
import { describe, expect, it } from "vitest";
|
|
12
12
|
|
|
13
|
-
import { api } from "
|
|
14
|
-
import schema from "
|
|
15
|
-
import { getAccountEarnings, getAccountPayouts } from "
|
|
16
|
-
|
|
17
|
-
const modules = import.meta.glob("./**/*.*s");
|
|
13
|
+
import { api } from "../_generated/api.js";
|
|
14
|
+
import { schema, modules } from "../../test.js";
|
|
15
|
+
import { getAccountEarnings, getAccountPayouts } from "../connect/queries.js";
|
|
18
16
|
|
|
19
17
|
describe("getAccountEarnings — exact totals past the 50-row cap (BTS-64)", () => {
|
|
20
18
|
it("sums gross and reversed over ALL transfers for an account, not just the first 50", async () => {
|