mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
4cd210c29c
- copied over and rewrote the deletion test from the legacy file - added a new test that checks that we get a 404 when attempting to delete an unknown post - this is a guard to protect and futureproof the API whilst we do refactoring to improve 404 handling from bookshelf - in turn this is aimed at helping to get rid of a bunch of catch predicates from the API
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
const assert = require('assert');
|
|
const {agentProvider, fixtureManager, mockManager, matchers} = require('../../utils/e2e-framework');
|
|
const {anyEtag, anyErrorId} = matchers;
|
|
|
|
describe('Posts API', function () {
|
|
let agent;
|
|
|
|
before(async function () {
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
await fixtureManager.init('posts');
|
|
await agent.loginAsOwner();
|
|
});
|
|
|
|
afterEach(function () {
|
|
mockManager.restore();
|
|
});
|
|
|
|
describe('Delete', function () {
|
|
it('Can destroy a post', async function () {
|
|
await agent
|
|
.delete(`posts/${fixtureManager.get('posts', 0).id}/`)
|
|
.expectStatus(204)
|
|
.expectEmptyBody()
|
|
.matchHeaderSnapshot({
|
|
etag: anyEtag
|
|
});
|
|
});
|
|
|
|
it('Cannot delete a non-existent posts', async function () {
|
|
// This error message from the API is not really what I would expect
|
|
// Adding this as a guard to demonstrate how future refactoring improves the output
|
|
await agent
|
|
.delete('/posts/abcd1234abcd1234abcd1234/')
|
|
.expectStatus(404)
|
|
.matchHeaderSnapshot({
|
|
etag: anyEtag
|
|
})
|
|
.matchBodySnapshot({
|
|
errors: [{
|
|
id: anyErrorId
|
|
}]
|
|
});
|
|
});
|
|
});
|
|
});
|