-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
51 lines (41 loc) · 1.53 KB
/
index.test.js
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
import Stripe1114 from "stripe1114";
import Stripe1117 from "stripe1117";
import nock from "nock";
import * as assert from "node:assert";
describe("stripe SDK", ()=> {
const falsePublicKey = 'pk_test_bogusPublicKeyForUnitTests'
const STRIPE_API_BASE_URL = 'https://api.stripe.com';
const StripeScope = nock(STRIPE_API_BASE_URL).matchHeader('Authorization', /Bearer pk_test_*/);
const defaultCard = {
type: 'card',
card: {
number: '4242424242424242',
cvc: '567',
exp_month: 12,
exp_year: 34,
},
}
function setupInterceptPostPaymentMethod() {
StripeScope.post('/v1/payment_methods').reply(201, { id: 'pm_myPM' });
}
context("Version 11.14", ()=> {
const StripeSDK = new Stripe1114(falsePublicKey)
before(()=> {
setupInterceptPostPaymentMethod()
})
it("should have its request intercepted by nock", async ()=> {
const postPaymentMeanResult = await StripeSDK.paymentMethods.create(defaultCard)
assert.equal(postPaymentMeanResult.id, 'pm_myPM')
})
})
context("Version 11.15+", ()=> {
const StripeSDK = new Stripe1117(falsePublicKey)
before(()=> {
setupInterceptPostPaymentMethod()
})
it("should have its request intercepted by nock", async ()=> {
const postPaymentMeanResult = await StripeSDK.paymentMethods.create(defaultCard)
assert.equal(postPaymentMeanResult.id, 'pm_myPM')
})
})
})