Ghost/test/e2e-api/admin/tiers.test.js
Fabien 'egg' O'Carroll fa1165de6a
Support tier visibility editing Allowed Tiers Admin API to set visibility
refs https://github.com/TryGhost/Team/issues/1387

This will allow us to move from the portal_products and portal_plans
settings to using the visibility property on tiers to determine whether
or not a tier should be visible in Portal.

This also fixes a bug with the Tiers Admin API read method permissions.
2022-03-07 14:46:42 +00:00

121 lines
3.1 KiB
JavaScript

const assert = require('assert');
const {
agentProvider,
fixtureManager,
mockManager,
matchers
} = require('../../utils/e2e-framework');
describe('Tiers API', function () {
let agent;
before(async function () {
agent = await agentProvider.getAdminAPIAgent();
await fixtureManager.init('members');
await agent.loginAsOwner();
});
beforeEach(function () {
mockManager.mockLabsEnabled('multipleProducts');
});
afterEach(function () {
mockManager.restore();
});
it('Can browse Tiers', async function () {
await agent
.get('/tiers/')
.expectStatus(200)
.matchBodySnapshot({
tiers: Array(2).fill({
id: matchers.anyObjectId,
created_at: matchers.anyISODateTime,
updated_at: matchers.anyISODateTime
})
});
});
it('Errors when price is non-integer', async function () {
const tier = {
name: 'Blah',
monthly_price: {
amount: 99.99
}
};
await agent
.post('/tiers/')
.body({tiers: [tier]})
.expectStatus(422)
.matchBodySnapshot({
errors: [{
id: matchers.anyUuid
}]
});
});
it('Errors when price is negative', async function () {
const tier = {
name: 'Blah',
monthly_price: {
amount: -100
}
};
await agent
.post('/tiers/')
.body({tiers: [tier]})
.expectStatus(422)
.matchBodySnapshot({
errors: [{
id: matchers.anyUuid
}]
});
});
it('Errors when price is too large', async function () {
const tier = {
name: 'Blah',
monthly_price: {
amount: Number.MAX_SAFE_INTEGER
}
};
await agent
.post('/tiers/')
.body({tiers: [tier]})
.expectStatus(422)
.matchBodySnapshot({
errors: [{
id: matchers.anyUuid
}]
});
});
it('Can read Tiers', async function () {
const {body: {tiers: [tier]}} = await agent.get('/tiers/');
await agent.get(`/tiers/${tier.id}/`)
.expectStatus(200);
});
it('Can edit visibility', async function () {
const {body: {tiers: [tier]}} = await agent.get('/tiers/?type:paid&limit=1');
const visibility = tier.visibility === 'none' ? 'public' : 'none';
await agent.put(`/tiers/${tier.id}/`)
.body({
tiers: [{
visibility
}]
})
.expectStatus(200);
const {body: {tiers: [updatedTier]}} = await agent.get(`/tiers/${tier.id}/`);
assert(updatedTier.visibility === visibility, `The visibility of the Tier should have been updated to ${visibility}`);
});
});