/api/user/connect/persons-count (GET)
await global.api.user.connect.PersonsCount.get(req) Located in Stripe Connect module API
Returns integer
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 querystring stripeid | |
invalid-stripeid | missing querystring stripeid |
invalid-account | ineligible accessing account |
invalid-stripe-account | ineligible stripe account for individual |
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) => {
if (!req.query || !req.query.stripeid) {
throw new Error('invalid-stripeid')
}
const stripeAccount = await global.api.user.connect.StripeAccount.get(req)
if (!stripeAccount) {
throw new Error('invalid-stripeid')
}
if (stripeAccount.business_type !== 'company') {
throw new Error('invalid-stripe-account')
}
const ownerids = await connect.StorageList.listAll(`${req.appid}/stripeAccount/persons/${req.query.stripeid}`)
if (!ownerids) {
return 0
}
return ownerids.length
}
}
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 TestStripeAccounts = require('../../../../../test-stripe-accounts.js')
describe('/api/user/connect/persons-count', () => {
describe('exceptions', () => {
describe('invalid-stripeid', () => {
it('missing querystring stripeid', async () => {
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'US',
type: 'individual'
})
const req = TestHelper.createRequest('/api/user/connect/persons-count')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-stripeid')
})
it('invalid querystring stripeid', async () => {
const user = await TestHelper.createUser()
const req = TestHelper.createRequest('/api/user/connect/persons-count?stripeid=invalid')
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-stripeid')
})
})
describe('invalid-account', () => {
it('ineligible accessing account', async () => {
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'US',
type: 'company'
})
const user2 = await TestHelper.createUser()
const req = TestHelper.createRequest(`/api/user/connect/persons-count?stripeid=${user.stripeAccount.id}`)
req.account = user2.account
req.session = user2.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-account')
})
})
describe('invalid-stripe-account', () => {
it('ineligible stripe account for individual', async () => {
const user = await TestHelper.createUser()
await TestHelper.createStripeAccount(user, {
country: 'US',
type: 'individual'
})
const req = TestHelper.createRequest(`/api/user/connect/persons-count?stripeid=${user.stripeAccount.id}`)
req.account = user.account
req.session = user.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-stripe-account')
})
})
})
describe('returns', () => {
it('integer', async () => {
const user = await TestStripeAccounts.createCompanyWithOwners('DE', 2)
const req = TestHelper.createRequest(`/api/user/connect/persons-count?stripeid=${user.stripeAccount.id}`)
req.account = user.account
req.session = user.session
req.filename = __filename
req.saveResponse = true
const total = await req.get()
assert.strictEqual(total, 2)
})
})
})