mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 14:43:08 +03:00
Added DELETE /collections/id to Admin API
refs https://github.com/TryGhost/Team/issues/3167 - This is part of scaffolding for collections API. Allows to delete collection resource
This commit is contained in:
parent
e82fcbfc5e
commit
e302f8cc1d
@ -89,5 +89,27 @@ module.exports = {
|
||||
|
||||
return model;
|
||||
}
|
||||
},
|
||||
|
||||
destroy: {
|
||||
statusCode: 204,
|
||||
headers: {
|
||||
cacheInvalidate: true
|
||||
},
|
||||
options: [
|
||||
'id'
|
||||
],
|
||||
validation: {
|
||||
options: {
|
||||
id: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
},
|
||||
// @NOTE: should have permissions when moving out of Alpha
|
||||
permissions: false,
|
||||
async query(frame) {
|
||||
return await collectionsService.api.destroy(frame.options.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -13,7 +13,8 @@ class CollectionsServiceWrapper {
|
||||
browse: collectionsService.getAll.bind(collectionsService),
|
||||
read: collectionsService.getById.bind(collectionsService),
|
||||
add: collectionsService.save.bind(collectionsService),
|
||||
edit: collectionsService.edit.bind(collectionsService)
|
||||
edit: collectionsService.edit.bind(collectionsService),
|
||||
destroy: collectionsService.destroy.bind(collectionsService)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ module.exports = function apiRoutes() {
|
||||
router.get('/collections/:id', mw.authAdminApi, labs.enabledMiddleware('collections'), http(api.collections.read));
|
||||
router.post('/collections', mw.authAdminApi, labs.enabledMiddleware('collections'), http(api.collections.add));
|
||||
router.put('/collections/:id', mw.authAdminApi, labs.enabledMiddleware('collections'), http(api.collections.edit));
|
||||
router.del('/collections/:id', mw.authAdminApi, labs.enabledMiddleware('collections'), http(api.collections.destroy));
|
||||
|
||||
// ## Configuration
|
||||
router.get('/config', mw.authAdminApi, http(api.config.read));
|
||||
|
@ -64,6 +64,78 @@ Object {
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Collections API Can delete a Collection 1: [body] 1`] = `
|
||||
Object {
|
||||
"collections": Array [
|
||||
Object {
|
||||
"deleted": false,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"title": "Test Collection to Delete",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Collections API Can delete a Collection 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": "103",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/collections\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Accept-Version, Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Collections API Can delete a Collection 3: [body] 1`] = `Object {}`;
|
||||
|
||||
exports[`Collections API Can delete a Collection 4: [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-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Accept-Version, Origin",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Collections API Can delete a Collection 5: [body] 1`] = `
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"code": null,
|
||||
"context": "Collection not found.",
|
||||
"details": null,
|
||||
"ghostErrorCode": null,
|
||||
"help": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||
"message": "Resource not found error, cannot read collection.",
|
||||
"property": null,
|
||||
"type": "NotFoundError",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Collections API Can delete a Collection 6: [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": "254",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Accept-Version, Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Collections API Can edit a Collection 1: [body] 1`] = `
|
||||
Object {
|
||||
"collections": Array [
|
||||
|
@ -163,4 +163,49 @@ describe('Collections API', function () {
|
||||
etag: anyEtag
|
||||
});
|
||||
});
|
||||
|
||||
it('Can delete a Collection', async function () {
|
||||
const collection = {
|
||||
title: 'Test Collection to Delete'
|
||||
};
|
||||
|
||||
const addResponse = await agent
|
||||
.post('/collections/')
|
||||
.body({
|
||||
collections: [collection]
|
||||
})
|
||||
.expectStatus(201)
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
etag: anyEtag,
|
||||
location: anyLocationFor('collections')
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
collections: [matchCollection]
|
||||
});
|
||||
|
||||
const collectionId = addResponse.body.collections[0].id;
|
||||
|
||||
await agent
|
||||
.delete(`/collections/${collectionId}/`)
|
||||
.expectStatus(204)
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot();
|
||||
|
||||
await agent
|
||||
.get(`/collections/${collectionId}/`)
|
||||
.expectStatus(404)
|
||||
.matchHeaderSnapshot({
|
||||
'content-version': anyContentVersion,
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
errors: [{
|
||||
id: anyErrorId
|
||||
}]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user