2022-08-22 19:35:37 +03:00
|
|
|
const assert = require('assert');
|
|
|
|
const {agentProvider, fixtureManager, mockManager, matchers} = require('../../utils/e2e-framework');
|
2022-09-13 15:30:17 +03:00
|
|
|
const {anyEtag, anyErrorId, anyObjectId} = matchers;
|
2022-08-22 19:35:37 +03:00
|
|
|
|
|
|
|
describe('Posts API', function () {
|
|
|
|
let agent;
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
|
|
await fixtureManager.init('posts');
|
|
|
|
await agent.loginAsOwner();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
mockManager.restore();
|
|
|
|
});
|
|
|
|
|
2022-09-13 15:30:17 +03:00
|
|
|
it('Can browse', async function () {
|
|
|
|
const res = await agent.get('posts/?limit=2')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
posts: new Array(2).fill({
|
|
|
|
id: anyObjectId
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can browse with formats', async function () {
|
|
|
|
const res = await agent.get('posts/?formats=mobiledoc,lexical,html,plaintext&limit=2')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
posts: new Array(2).fill({
|
|
|
|
id: anyObjectId
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-08-22 19:35:37 +03:00
|
|
|
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
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|