/api/administrator/subscriptions/tax-rate (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.subscriptions.TaxRate.get(req)Returns object
{
"taxrateid": "txr_1LEOWgHHqepMFuCXYpwxqgvQ",
"object": "taxrate",
"stripeObject": {
"id": "txr_1LEOWgHHqepMFuCXYpwxqgvQ",
"object": "tax_rate",
"active": true,
"country": "US",
"created": 1656123310,
"description": "Sales tax in NY",
"display_name": "NY Sales Tax",
"inclusive": true,
"jurisdiction": "US",
"livemode": false,
"metadata": {},
"percentage": 17.5,
"state": "NY",
"tax_type": "sales_tax"
},
"appid": "tests_1656123309",
"createdAt": "2022-06-25T02:15:10.241Z",
"updatedAt": "2022-06-25T02:15:10.241Z"
}
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-taxrateid | missing querystring taxrateid |
invalid querystring taxrateid |
NodeJS source (view on github)
const dashboard = require('@layeredapps/dashboard')
const subscriptions = require('../../../../../index.js')
module.exports = {
get: async (req) => {
if (!req.query || !req.query.taxrateid) {
throw new Error('invalid-taxrateid')
}
let taxRate = await dashboard.StorageCache.get(req.query.taxrateid)
if (!taxRate) {
const taxRateInfo = await subscriptions.Storage.TaxRate.findOne({
where: {
taxrateid: req.query.taxrateid,
appid: req.appid || global.appid
}
})
if (!taxRateInfo) {
throw new Error('invalid-taxrateid')
}
taxRate = {}
for (const field of taxRateInfo._options.attributes) {
taxRate[field] = taxRateInfo.get(field)
}
await dashboard.StorageCache.set(req.query.taxrateid, taxRate)
}
return taxRate
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
describe('/api/administrator/subscriptions/tax-rate', function () {
before(TestHelper.disableMetrics)
after(TestHelper.enableMetrics)
describe('exceptions', () => {
describe('invalid-taxrateid', () => {
it('missing querystring taxrateid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/tax-rate')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-taxrateid')
})
it('invalid querystring taxrateid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/tax-rate?taxrateid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-taxrateid')
})
})
})
describe('returns', () => {
it('object', async () => {
const administrator = await TestHelper.createOwner()
await TestHelper.createTaxRate(administrator)
const req = TestHelper.createRequest(`/api/administrator/subscriptions/tax-rate?taxrateid=${administrator.taxRate.taxrateid}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const setupIntent = await req.get()
assert.strictEqual(setupIntent.object, 'taxrate')
})
})
})