@gr4vy/sdk 2.1.2 → 2.1.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/README.md +8 -2
- package/jsr.json +1 -1
- package/lib/config.d.ts +2 -2
- package/lib/config.js +2 -2
- package/package.json +4 -2
- package/scripts/endpoint-coverage.mjs +136 -0
- package/src/lib/config.ts +2 -2
- package/tests/backoffice/account-updater.test.ts +24 -0
- package/tests/backoffice/audit-logs.test.ts +20 -0
- package/tests/backoffice/merchant-accounts.test.ts +77 -0
- package/tests/backoffice/payment-services.test.ts +95 -0
- package/tests/backoffice/payouts.test.ts +49 -0
- package/tests/backoffice/reports.test.ts +69 -0
- package/tests/backoffice/three-ds-scenarios.test.ts +34 -0
- package/tests/flows/buyer-lifecycle.test.ts +74 -0
- package/tests/flows/transaction-lifecycle.test.ts +151 -0
- package/tests/processing/buyers.test.ts +119 -0
- package/tests/processing/checkout-sessions.test.ts +99 -0
- package/tests/processing/digital-wallets.test.ts +154 -0
- package/tests/processing/gift-cards.test.ts +45 -0
- package/tests/processing/payment-links.test.ts +34 -0
- package/tests/processing/payment-methods.test.ts +121 -0
- package/tests/processing/transactions.test.ts +118 -0
- package/tests/utils/arbitraries.ts +87 -0
- package/tests/utils/fields.ts +65 -0
- package/tests/utils/fixtures.ts +84 -0
- package/tests/utils/poll.ts +40 -0
- package/tests/utils/setup.ts +66 -10
- package/tests/utils/transactions.ts +26 -0
- package/vitest.config.ts +31 -0
- package/tests/checkout-sessions.test.ts +0 -109
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
// E2E suites talk to the real sandbox at api.sandbox.e2e.gr4vy.app. Each test
|
|
4
|
+
// file provisions its own merchant account (see tests/utils/setup.ts), so files
|
|
5
|
+
// are fully isolated and safe to run in parallel across worker threads. CI shards
|
|
6
|
+
// the files across jobs with `vitest run --shard=$i/$n`.
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
test: {
|
|
9
|
+
// Run test files concurrently across worker threads. Tests *within* a file
|
|
10
|
+
// still run sequentially, which keeps each file's merchant-scoped flow ordered.
|
|
11
|
+
fileParallelism: true,
|
|
12
|
+
// Network calls to a shared sandbox occasionally blip; a couple of retries
|
|
13
|
+
// keeps the auto-merge SDK-regen pipeline from flaking on transient errors.
|
|
14
|
+
retry: 2,
|
|
15
|
+
// Generous timeouts for the real network + eventually-consistent endpoints
|
|
16
|
+
// (capture settling, report execution). Mirrors the CI invocation flags.
|
|
17
|
+
testTimeout: 30_000,
|
|
18
|
+
hookTimeout: 30_000,
|
|
19
|
+
// Keep the offline unit tests (auth, webhook) and the live E2E suites together.
|
|
20
|
+
include: ["tests/**/*.test.{ts,js}"],
|
|
21
|
+
coverage: {
|
|
22
|
+
provider: "v8",
|
|
23
|
+
// `src/funcs/*` is one file per API operation, so coverage over this
|
|
24
|
+
// directory doubles as an "endpoints reached" metric (see
|
|
25
|
+
// scripts/endpoint-coverage.mjs). `src/sdk/*` are the namespace wrappers.
|
|
26
|
+
include: ["src/funcs/**", "src/sdk/**"],
|
|
27
|
+
reporter: ["text-summary", "json-summary", "json"],
|
|
28
|
+
reportsDirectory: "coverage",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
|
|
2
|
-
import { CardPaymentMethodCreate } from '../src/models/components';
|
|
3
|
-
import { cleanupEnvironment, setupEnvironment } from './utils/setup';
|
|
4
|
-
|
|
5
|
-
let gr4vy;
|
|
6
|
-
|
|
7
|
-
beforeAll(async () => {
|
|
8
|
-
gr4vy = await setupEnvironment()
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
afterAll(async () => {
|
|
12
|
-
await cleanupEnvironment()
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe("Checkout Sessions", () => {
|
|
16
|
-
test("should process a payment with a checkout session", async () => {
|
|
17
|
-
const checkoutSession = await gr4vy.checkoutSessions.create()
|
|
18
|
-
expect(checkoutSession.id).toBeDefined();
|
|
19
|
-
|
|
20
|
-
// We do not use the SDK here as we don't want to make this feature public
|
|
21
|
-
const response = await fetch(`https://api.sandbox.e2e.gr4vy.app/checkout/sessions/${checkoutSession.id}/fields`, {
|
|
22
|
-
method: "PUT",
|
|
23
|
-
headers: {
|
|
24
|
-
'content-type': 'application/json',
|
|
25
|
-
},
|
|
26
|
-
body: JSON.stringify({
|
|
27
|
-
"payment_method": {
|
|
28
|
-
"method": "card",
|
|
29
|
-
"number": "4111111111111111",
|
|
30
|
-
"expiration_date": "11/25",
|
|
31
|
-
"security_code": "123",
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
expect(response.status).toBe(204);
|
|
36
|
-
|
|
37
|
-
const transaction = await gr4vy.transactions.create({
|
|
38
|
-
amount: 1299,
|
|
39
|
-
currency: "USD",
|
|
40
|
-
paymentMethod: {
|
|
41
|
-
method: "checkout-session",
|
|
42
|
-
id: checkoutSession.id
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
expect(transaction.id).toBeDefined();
|
|
47
|
-
expect(transaction.status).toBe("authorization_succeeded");
|
|
48
|
-
expect(transaction.amount).toBe(1299);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("should handle the error raised on missing card data", async () => {
|
|
52
|
-
const checkoutSession = await gr4vy.checkoutSessions.create()
|
|
53
|
-
expect(checkoutSession.id).toBeDefined();
|
|
54
|
-
|
|
55
|
-
const request = {
|
|
56
|
-
amount: 1299,
|
|
57
|
-
currency: "USD",
|
|
58
|
-
paymentMethod: {
|
|
59
|
-
method: "checkout-session",
|
|
60
|
-
id: checkoutSession.id
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
await expect(() => gr4vy.transactions.create(request)).rejects.toThrowError("Request failed validation")
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("should handle a stored payment method", async () => {
|
|
67
|
-
const request: CardPaymentMethodCreate = {
|
|
68
|
-
method: "card",
|
|
69
|
-
number: "4111111111111111",
|
|
70
|
-
expirationDate: "11/25",
|
|
71
|
-
securityCode: "123",
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const paymentMethod = await gr4vy.paymentMethods.create(request)
|
|
75
|
-
expect(paymentMethod.id).toBeDefined()
|
|
76
|
-
|
|
77
|
-
const checkoutSession = await gr4vy.checkoutSessions.create()
|
|
78
|
-
expect(checkoutSession.id).toBeDefined();
|
|
79
|
-
|
|
80
|
-
// We do not use the SDK here as we don't want to make this feature public
|
|
81
|
-
const response = await fetch(`https://api.sandbox.e2e.gr4vy.app/checkout/sessions/${checkoutSession.id}/fields`, {
|
|
82
|
-
method: "PUT",
|
|
83
|
-
headers: {
|
|
84
|
-
'content-type': 'application/json',
|
|
85
|
-
},
|
|
86
|
-
body: JSON.stringify({
|
|
87
|
-
"payment_method": {
|
|
88
|
-
"method": "id",
|
|
89
|
-
"id": paymentMethod.id,
|
|
90
|
-
"security_code": "123",
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
expect(response.status).toBe(204);
|
|
95
|
-
|
|
96
|
-
const transaction = await gr4vy.transactions.create({
|
|
97
|
-
amount: 1299,
|
|
98
|
-
currency: "USD",
|
|
99
|
-
paymentMethod: {
|
|
100
|
-
method: "checkout-session",
|
|
101
|
-
id: checkoutSession.id
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
expect(transaction.id).toBeDefined();
|
|
106
|
-
expect(transaction.status).toBe("authorization_succeeded");
|
|
107
|
-
expect(transaction.amount).toBe(1299);
|
|
108
|
-
});
|
|
109
|
-
});
|