-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstripe-example.test.ts
More file actions
84 lines (72 loc) · 1.91 KB
/
stripe-example.test.ts
File metadata and controls
84 lines (72 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { test, expect, afterAll, beforeAll, afterEach } from "vitest";
import { Stripe } from "stripe";
import { EckoServer, type EckoApi } from "../src/index.js";
const PORT = 3005;
let ecko: EckoApi;
let eckoServer: EckoServer;
let stripe: Stripe;
beforeAll(() => {
eckoServer = EckoServer();
const startResult = eckoServer.start({ port: PORT, logLevel: "error" });
ecko = startResult.ecko;
const url = new URL(startResult.baseUrl);
stripe = new Stripe("does_not_matter", {
apiVersion: "2025-02-24.acacia",
host: url.hostname,
port: url.port,
protocol: "http",
});
});
afterEach(() => {
eckoServer.reset();
});
afterAll(() => {
eckoServer.stop();
});
test("Should fetch a balance from the mocked Stripe API", async () => {
ecko.register("/v1/balance", "get", {
frequency: "always",
status: 200,
headers: {
"Content-Type": "application/json",
},
payload: JSON.stringify({
object: "balance",
available: [
{
amount: 666670,
currency: "usd",
source_types: {
card: 666670,
},
},
],
connect_reserved: [
{
amount: 0,
currency: "usd",
},
],
livemode: false,
pending: [
{
amount: 61414,
currency: "usd",
source_types: {
card: 61414,
},
},
],
}),
});
const balance = await stripe.balance.retrieve();
expect(balance).toBeDefined();
expect(balance.object).toBe("balance");
expect(balance.available).toBeDefined();
expect(balance.available[0].amount).toBe(666670);
expect(balance.available[0].currency).toBe("usd");
expect(balance?.available?.[0]?.source_types?.card).toBe(666670);
expect(balance.connect_reserved).toBeDefined();
expect(balance?.connect_reserved?.[0]?.amount).toBe(0);
expect(balance?.connect_reserved?.[0]?.currency).toBe("usd");
});