/api/administrator/subscriptions/delete-price (DELETE)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.subscriptions.DeletePrice.delete(req)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-priceid | missing querystring priceid |
invalid querystring priceid |
NodeJS source (view on github)
const subscriptions = require('../../../../../index.js')
// const stripeCache = require('../../../../stripe-cache.js')
module.exports = {
delete: async (req) => {
if (!req.query || !req.query.priceid) {
throw new Error('invalid-priceid')
}
const price = await global.api.administrator.subscriptions.Price.get(req)
if (!price) {
throw new Error('invalid-priceid')
}
// TODO: there is currently no endpoint for deleting prices including
// in test mode, except by purging all data manually in the Stripe
// dashboard, there is a GitHub issue here on the topic:
// https://github.com/stripe/stripe-python/issues/658
await subscriptions.Storage.Price.destroy({
where: {
priceid: req.query.priceid,
appid: req.appid || global.appid
}
})
return true
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
const TestStripeAccounts = require('../../../../../test-stripe-accounts.js')
describe('/api/administrator/subscriptions/delete-price', function () {
before(TestHelper.disableMetrics)
after(TestHelper.enableMetrics)
describe('exceptions', () => {
describe('invalid-priceid', () => {
it('missing querystring priceid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/delete-price')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.delete()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-priceid')
})
it('invalid querystring priceid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/delete-price?priceid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.delete()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-priceid')
})
})
})
describe('returns', () => {
it('boolean', async () => {
const administrator = await TestStripeAccounts.createOwnerWithPrice()
const req = TestHelper.createRequest(`/api/administrator/subscriptions/delete-price?priceid=${administrator.price.priceid}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const deleted = await req.delete()
assert.strictEqual(deleted, true)
})
})
})