/api/administrator/connect/stripe-accounts (GET)
await global.api.administrator.connect.StripeAccounts.get(req) Located in Stripe Connect module API
Returns array
Exceptions
These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:
Exception | Circumstances |
---|---|
invalid-accountid | invalid querystring accountid |
Receives
API routes may receive parameters from the URL and POST supporting simple and multipart:
Field | Value | Required | Type |
---|---|---|---|
accountid | string | optional | URL |
all | boolean | optional | URL |
limit | integer | optional | URL |
offset | integer | optional | URL |
NodeJS source (edit on github)
If you see a problem with the source submit a pull request on Github.
const connect = require('../../../../../index.js')
module.exports = {
get: async (req) => {
req.query = req.query || {}
let stripeids
let index
if (req.query.accountid) {
const account = await global.api.administrator.Account.get(req)
if (!account) {
throw new Error('invalid-accountid')
}
index = `${req.appid}/account/stripeAccounts/${req.query.accountid}`
} else {
index = `${req.appid}/stripeAccounts`
}
if (req.query.all) {
stripeids = await connect.StorageList.listAll(index)
} else {
const offset = req.query.offset ? parseInt(req.query.offset, 10) || 0 : 0
const limit = req.query.limit ? parseInt(req.query.limit, 10) || 0 : global.pageSize
stripeids = await connect.StorageList.list(index, offset, limit)
}
if (!stripeids || !stripeids.length) {
return null
}
const stripeAccounts = []
req.query = req.query || {}
for (const stripeid of stripeids) {
req.query.stripeid = stripeid
const stripeAccount = await global.api.administrator.connect.StripeAccount.get(req)
stripeAccounts.push(stripeAccount)
}
return stripeAccounts
}
}
Test source (edit on github)
Tests perform real HTTP requests against a running Dashboard server.
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
const DashboardTestHelper = require('@userdashboard/dashboard/test-helper.js')
describe('/api/administrator/connect/stripe-accounts', function () {
this.timeout(30 * 60 * 1000)
const cachedResponses = {}
const cachedStripeAccounts = []
before(async () => {
await DashboardTestHelper.setupBeforeEach()
await TestHelper.setupBeforeEach()
global.delayDiskWrites = true
const administrator = await TestHelper.createOwner()
for (let i = 0, len = global.pageSize + 2; i < len; i++) {
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'US',
type: 'company'
})
cachedStripeAccounts.unshift(user.stripeAccount.id)
}
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'US',
type: 'individual'
})
cachedStripeAccounts.unshift(user.stripeAccount.id)
await TestHelper.createStripeAccount(user, {
country: 'US',
type: 'company'
})
cachedStripeAccounts.unshift(user.stripeAccount.id)
const req1 = TestHelper.createRequest('/api/administrator/connect/stripe-accounts')
req1.account = administrator.account
req1.session = administrator.session
cachedResponses.returns = await req1.get()
global.pageSize = 3
cachedResponses.pageSize = await req1.get()
const req2 = TestHelper.createRequest('/api/administrator/connect/stripe-accounts?offset=1')
req2.account = administrator.account
req2.session = administrator.session
cachedResponses.offset = await req2.get()
const req3 = TestHelper.createRequest('/api/administrator/connect/stripe-accounts?limit=1')
req3.account = administrator.account
req3.session = administrator.session
cachedResponses.limit = await req3.get()
const req4 = TestHelper.createRequest('/api/administrator/connect/stripe-accounts?all=true')
req4.account = administrator.account
req4.session = administrator.session
cachedResponses.all = await req4.get()
const req5 = TestHelper.createRequest(`/api/administrator/connect/stripe-accounts?accountid=${user.account.accountid}`)
req5.account = administrator.account
req5.session = administrator.session
cachedResponses.accountid = await req5.get()
})
describe('exceptions', () => {
describe('invalid-accountid', () => {
it('invalid querystring accountid', async () => {
const user = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/administrator/connect/stripe-accounts?accountid=invalid')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-accountid')
})
})
})
describe('receives', function () {
it('optional querystring offset (integer)', async () => {
const offset = 1
const stripeAccountsNow = cachedResponses.offset
for (let i = 0, len = global.pageSize; i < len; i++) {
assert.strictEqual(stripeAccountsNow[i].id, cachedStripeAccounts[offset + i])
}
})
it('optional querystring limit (integer)', async () => {
const limit = 1
const stripeAccountsNow = cachedResponses.limit
assert.strictEqual(stripeAccountsNow.length, limit)
})
it('optional querystring all (boolean)', async () => {
const stripeAccountsNow = cachedResponses.all
assert.strictEqual(stripeAccountsNow.length, cachedStripeAccounts.length)
})
it('optional querystring accountid (string)', async () => {
const stripeAccountsNow = cachedResponses.accountid
assert.strictEqual(stripeAccountsNow.length, 2)
})
})
describe('returns', function () {
it('array', async () => {
const payouts = cachedResponses.returns
assert.strictEqual(payouts.length, global.pageSize)
})
})
describe('configuration', function () {
it('environment PAGE_SIZE', async () => {
global.pageSize = 3
const payouts = cachedResponses.pageSize
assert.strictEqual(payouts.length, global.pageSize)
})
})
})