mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added GET /collections to Admin API
refs https://github.com/TryGhost/Team/issues/3167 - This is scaffolding for collections API. Contains wiring for service wrapper, e2e test, and a browse endpoint - Adds basic implementation of the GET /collections endpoint to build up upon - Note, there are no permissions in this version as they will be added in later stages of development with migrations etc
This commit is contained in:
parent
d4a5dac758
commit
36eff3a481
7 changed files with 93 additions and 0 deletions
18
ghost/core/core/server/api/endpoints/collections.js
Normal file
18
ghost/core/core/server/api/endpoints/collections.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
const collectionsService = require('../../services/collections');
|
||||
|
||||
module.exports = {
|
||||
docName: 'collections',
|
||||
|
||||
browse: {
|
||||
options: [
|
||||
'limit',
|
||||
'order',
|
||||
'page'
|
||||
],
|
||||
// @NOTE: should have permissions when moving out of Alpha
|
||||
permissions: false,
|
||||
query(frame) {
|
||||
return collectionsService.api.browse(frame.options);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -12,6 +12,10 @@ module.exports = {
|
|||
return apiFramework.pipeline(require('./authentication'), localUtils);
|
||||
},
|
||||
|
||||
get collections() {
|
||||
return apiFramework.pipeline(require('./collections'), localUtils);
|
||||
},
|
||||
|
||||
get db() {
|
||||
return apiFramework.pipeline(require('./db'), localUtils);
|
||||
},
|
||||
|
|
18
ghost/core/core/server/services/collections/index.js
Normal file
18
ghost/core/core/server/services/collections/index.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
const {CollectionsService, CollectionsRepositoryInMemory} = require('@tryghost/collections');
|
||||
|
||||
class CollectionsServiceWrapper {
|
||||
api;
|
||||
|
||||
constructor() {
|
||||
const inMemoryCollectionsRepository = new CollectionsRepositoryInMemory();
|
||||
const collectionsService = new CollectionsService({
|
||||
repository: inMemoryCollectionsRepository
|
||||
});
|
||||
|
||||
this.api = {
|
||||
browse: collectionsService.getAll.bind(collectionsService)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new CollectionsServiceWrapper();
|
|
@ -18,6 +18,9 @@ module.exports = function apiRoutes() {
|
|||
// ## Public
|
||||
router.get('/site', mw.publicAdminApi, http(api.site.read));
|
||||
|
||||
// ## Collections
|
||||
router.get('/collections', mw.authAdminApi, labs.enabledMiddleware('collections'), http(api.collections.browse));
|
||||
|
||||
// ## Configuration
|
||||
router.get('/config', mw.authAdminApi, http(api.config.read));
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
"@tryghost/audience-feedback": "0.0.0",
|
||||
"@tryghost/bookshelf-plugins": "0.6.7",
|
||||
"@tryghost/bootstrap-socket": "0.0.0",
|
||||
"@tryghost/collections": "0.0.0",
|
||||
"@tryghost/color-utils": "0.1.24",
|
||||
"@tryghost/config-url-helpers": "1.0.6",
|
||||
"@tryghost/constants": "0.0.0",
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Collections API Can browse Collections 1: [body] 1`] = `
|
||||
Object {
|
||||
"collections": Array [
|
||||
Array [],
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Collections API Can browse Collections 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "20",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"content-version": "v5.47",
|
||||
"etag": "W/\\"14-8OY9ZEqoQYKIwHgKOLz+0dUdl7A\\"",
|
||||
"vary": "Accept-Version, Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
27
ghost/core/test/e2e-api/admin/collections.test.js
Normal file
27
ghost/core/test/e2e-api/admin/collections.test.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
const {
|
||||
agentProvider,
|
||||
fixtureManager,
|
||||
mockManager
|
||||
} = require('../../utils/e2e-framework');
|
||||
|
||||
describe.only('Collections API', function () {
|
||||
let agent;
|
||||
|
||||
before(async function () {
|
||||
agent = await agentProvider.getAdminAPIAgent();
|
||||
await fixtureManager.init('users');
|
||||
await agent.loginAsOwner();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
mockManager.restore();
|
||||
});
|
||||
|
||||
it('Can browse Collections', async function () {
|
||||
await agent
|
||||
.get('/collections/')
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot()
|
||||
.matchBodySnapshot();
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue