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:
parent
16e0736379
commit
9ad45ee5be
1 changed files with 64 additions and 0 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue