/api/administrator/subscriptions/delete-product (DELETE)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.subscriptions.DeleteProduct.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-productid | missing querystring productid |
invalid querystring productid |
NodeJS source (view on github)
const subscriptions = require('../../../../../index.js')
module.exports = {
delete: async (req) => {
if (!req.query || !req.query.productid) {
throw new Error('invalid-productid')
}
const product = await global.api.administrator.subscriptions.Product.get(req)
if (!product) {
throw new Error('invalid-productid')
}
// TODO: products with prices attached cannot currently be deleted
// 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.Product.destroy({
where: {
productid: req.query.productid,
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')
describe('/api/administrator/subscriptions/delete-product', function () {
before(TestHelper.disableMetrics)
after(TestHelper.enableMetrics)
describe('exceptions', () => {
describe('invalid-productid', () => {
it('missing querystring productid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/delete-product')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.delete()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-productid')
})
it('invalid querystring productid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/subscriptions/delete-product?productid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.delete()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-productid')
})
})
})
describe('returns', () => {
it('boolean', async () => {
const administrator = await TestHelper.createOwner()
await TestHelper.createProduct(administrator, {
active: 'true'
})
const req = TestHelper.createRequest(`/api/administrator/subscriptions/delete-product?productid=${administrator.product.productid}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const deleted = await req.delete()
assert.strictEqual(deleted, true)
})
})
})