/api/administrator/subscriptions/set-tax-rate-inactive (PATCH)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.subscriptions.SetTaxRateInactive.patch(req)Returns object
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-taxrate | invalid taxrate is already inactive |
invalid-taxrateid | missing querystring taxrateid |
invalid querystring taxrateid |
NodeJS source (view on github)
const subscriptions = require('../../../../../index.js')
const stripeCache = require('../../../../stripe-cache.js')
module.exports = {
patch: async (req) => {
if (!req.query || !req.query.taxrateid) {
throw new Error('invalid-taxrateid')
}
const taxRate = await global.api.administrator.subscriptions.TaxRate.get(req)
if (!taxRate) {
throw new Error('invalid-taxrateid')
}
if (!taxRate.stripeObject.active) {
throw new Error('invalid-taxrate')
}
const taxRateInfo = {
active: 'false'
}
const taxRateNow = await stripeCache.execute('taxRates', 'update', req.query.taxrateid, taxRateInfo, req.stripeKey)
await subscriptions.Storage.TaxRate.update({
stripeObject: taxRateNow
}, {
where: {
taxrateid: req.query.taxrateid,
appid: req.appid || global.appid
}
})
return global.api.administrator.subscriptions.TaxRate.get(req)
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
describe('/api/administrator/subscriptions/set-tax-rate-inactive', function () {
before(TestHelper.disableMetrics)
after(TestHelper.enableMetrics)
describe('exceptions', () => {
describe('invalid-taxrateid', () => {
it('missing querystring taxrateid', async function () {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/set-tax-rate-inactive')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.patch()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-taxrateid')
})
it('invalid querystring taxrateid', async function () {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/set-tax-rate-inactive?taxrateid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.patch()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-taxrateid')
})
})
describe('invalid-taxrate', () => {
it('invalid taxrate is already inactive', async function () {
const administrator = await TestHelper.createOwner()
await TestHelper.createTaxRate(administrator, {
active: 'false'
})
const req = TestHelper.createRequest(`/api/administrator/subscriptions/set-tax-rate-inactive?taxrateid=${administrator.taxRate.taxrateid}`)
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.patch()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-taxrate')
})
})
})
describe('returns', () => {
it('object', async function () {
const administrator = await TestHelper.createOwner()
await TestHelper.createTaxRate(administrator, {
active: true
})
const req = TestHelper.createRequest(`/api/administrator/subscriptions/set-tax-rate-inactive?taxrateid=${administrator.taxRate.taxrateid}`)
req.account = administrator.account
req.session = administrator.session
const taxRateNow = await req.patch()
assert.strictEqual(taxRateNow.stripeObject.active, false)
})
})
})