0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added /tiers endpoint to Content API

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

When adding the tiers endpoint the Content API was missed, this is
needed so that themes can access Tiers via the `{{#get}}` helper.
This commit is contained in:
Fabien "egg" O'Carroll 2022-03-01 10:38:48 +02:00 committed by Fabien 'egg' O'Carroll
parent c00b398abf
commit 1b96ce2794
5 changed files with 135 additions and 0 deletions

View file

@ -207,5 +207,9 @@ module.exports = {
get productsPublic() {
return shared.pipeline(require('./products-public'), localUtils, 'content');
},
get tiersPublic() {
return shared.pipeline(require('./tiers-public'), localUtils, 'content');
}
};

View file

@ -0,0 +1,34 @@
// NOTE: We must not cache references to membersService.api
// as it is a getter and may change during runtime.
const membersService = require('../../services/members');
const allowedIncludes = ['monthly_price', 'yearly_price', 'benefits'];
module.exports = {
docName: 'tiers',
browse: {
options: [
'limit',
'fields',
'include',
'filter',
'order',
'debug',
'page'
],
permissions: true,
validation: {
options: {
include: {
values: allowedIncludes
}
}
},
async query(frame) {
const page = await membersService.api.productRepository.list(frame.options);
return page;
}
}
};

View file

@ -34,6 +34,7 @@ module.exports = function apiRoutes() {
router.get('/settings', mw.authenticatePublic, http(api.publicSettings.browse));
router.get('/products', mw.authenticatePublic, http(api.productsPublic.browse));
router.get('/tiers', mw.authenticatePublic, http(api.tiersPublic.browse));
return router;
};

View file

@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Tiers Content API Can request tiers 1: [body] 1`] = `
Object {
"meta": Object {
"pagination": Object {
"limit": 15,
"next": null,
"page": 1,
"pages": 1,
"prev": null,
"total": 2,
},
},
"tiers": Array [
Object {
"active": true,
"benefits": null,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/,
"description": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"name": "Free",
"slug": "free",
"stripe_prices": null,
"type": "free",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/,
"visible": false,
"welcome_page_url": "/welcome-free",
},
Object {
"active": true,
"benefits": null,
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/,
"description": null,
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"name": "Default Product",
"slug": "default-product",
"stripe_prices": null,
"type": "paid",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/,
"visible": false,
"welcome_page_url": "/welcome-paid",
},
],
}
`;
exports[`Tiers Content API Can request tiers 1: [headers] 1`] = `
Object {
"access-control-allow-origin": "*",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "643",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Accept-Encoding",
"x-powered-by": "Express",
}
`;
exports[`Tiers Content API Can request tiers 2: [headers] 1`] = `
Object {
"access-control-allow-origin": "*",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "675",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Accept-Encoding",
"x-powered-by": "Express",
}
`;

View file

@ -0,0 +1,26 @@
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
describe('Tiers Content API', function () {
let agent;
before(async function () {
agent = await agentProvider.getContentAPIAgent();
await fixtureManager.init('members', 'api_keys');
agent.authenticate();
});
it('Can request tiers', async function () {
await agent.get('/tiers/')
.expectStatus(200)
.matchHeaderSnapshot({
etag: matchers.anyEtag
})
.matchBodySnapshot({
tiers: Array(2).fill({
id: matchers.anyObjectId,
created_at: matchers.anyISODate,
updated_at: matchers.anyISODate
})
});
});
});