-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-helper-routes.js
42 lines (41 loc) · 1.42 KB
/
test-helper-routes.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
const connect = require('./index.js')
const stripeCache = require('./src/stripe-cache.js')
module.exports = {
fakePayout: {
api: {
get: async (req) => {
if (process.env.NODE_ENV !== 'testing') {
throw new Error('invalid-route')
}
if (!req.query || !req.query.stripeid) {
throw new Error('invalid-stripeid')
}
const stripeAccount = await global.api.administrator.connect.StripeAccount.get(req)
if (!stripeAccount.stripeObject.payouts_enabled) {
throw new Error('invalid-stripe-account')
}
req.stripeKey.stripeAccount = req.query.stripeid
const chargeInfo = {
amount: 2500,
currency: stripeAccount.stripeObject.default_currency,
source: 'tok_bypassPending',
description: 'Test charge'
}
await stripeCache.execute('charges', 'create', chargeInfo, req.stripeKey)
const payoutInfo = {
amount: 2000,
currency: stripeAccount.stripeObject.default_currency
}
const payout = await stripeCache.execute('payouts', 'create', payoutInfo, req.stripeKey)
await connect.Storage.Payout.create({
payoutid: payout.id,
stripeid: stripeAccount.stripeid,
appid: req.appid || global.appid,
accountid: stripeAccount.accountid,
stripeObject: payout
})
return payout
}
}
}
}