0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added tests for creating product benefits without name (#14217)

refs https://github.com/TryGhost/Team/issues/1188

The products API did return a 500 error when you tried to store product benefits with an empty name. This should throw a 422 Validation Error instead. This change includes some tests for this error. The error itself has been solved by updating the bookshelf-relations dependency earlier.

- Added test when creating a new product with an empty benefit name
- Added test when updating an existing product with new benefits, with an empty name
- Added a test that creates a tier with benefits
This commit is contained in:
Simon Backx 2022-03-10 10:10:35 +01:00 committed by GitHub
parent 16e0736379
commit 9ad45ee5be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
const should = require('should');
const sinon = require('sinon');
const {agentProvider, fixtureManager, mockManager} = require('../../utils/e2e-framework');
@ -15,6 +16,22 @@ describe('Tiers API', function () {
mockManager.mockLabsDisabled('multipleProducts');
const stripeService = require('../../../core/server/services/stripe');
stripeService.api._configured = true;
mockManager.mockStripe();
sinon
.stub(stripeService.api, 'createProduct')
.resolves({
id: 'prod_LFPlH9BDDwXcZ1'
});
sinon
.stub(stripeService.api, 'createPrice')
.resolves({
id: 'price_1KYpK92eZvKYlo2C86IrYSPM',
currency: 'usd',
nickname: null,
unit_amount: 299
});
});
afterEach(function () {
@ -64,4 +81,51 @@ describe('Tiers API', function () {
.body({products: [tier]})
.expectStatus(422);
});
it('Create a new tier with benefits', async function () {
const tier = {
name: 'Blah',
monthly_price: {
amount: 10
},
benefits: [{
name: 'This is a benefit'
}]
};
await agent
.post('/products/')
.body({products: [tier]})
.expectStatus(201);
});
it('Errors when a benefit has an empty name', async function () {
const tier = {
name: 'Blah',
monthly_price: {
amount: 10
},
benefits: [{
name: ''
}]
};
await agent
.post('/products/')
.body({products: [tier]})
.expectStatus(422);
});
it('Errors when a product is edited with a benefit that has an empty name', async function () {
const tier = {
benefits: [{
name: ''
}]
};
await agent
.put('/products/' + fixtureManager.get('products', 0).id)
.body({products: [tier]})
.expectStatus(422);
});
});