2022-03-29 17:33:30 +03:00
|
|
|
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
|
|
|
const {anyEtag, anyLocationFor, anyObjectId, anyISODateTime, anyErrorId} = matchers;
|
2020-10-16 20:02:58 +03:00
|
|
|
|
2022-03-29 17:33:30 +03:00
|
|
|
const matchSnippet = {
|
|
|
|
id: anyObjectId,
|
|
|
|
created_at: anyISODateTime,
|
|
|
|
updated_at: anyISODateTime
|
|
|
|
};
|
2020-11-30 17:25:22 +03:00
|
|
|
|
2022-03-29 17:33:30 +03:00
|
|
|
describe('Snippets API', function () {
|
|
|
|
let agent;
|
2020-10-16 20:02:58 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
before(async function () {
|
2022-03-29 17:33:30 +03:00
|
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
|
|
await fixtureManager.init('snippets');
|
|
|
|
await agent.loginAsOwner();
|
2020-10-16 20:02:58 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can add', async function () {
|
2020-10-16 20:02:58 +03:00
|
|
|
const snippet = {
|
|
|
|
name: 'test',
|
|
|
|
mobiledoc: JSON.stringify({})
|
|
|
|
};
|
|
|
|
|
2022-03-29 17:33:30 +03:00
|
|
|
await agent
|
|
|
|
.post('snippets/')
|
|
|
|
.body({snippets: [snippet]})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
snippets: [matchSnippet]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('snippets')
|
|
|
|
});
|
2020-10-16 20:02:58 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can browse', async function () {
|
2022-03-29 17:33:30 +03:00
|
|
|
await agent
|
|
|
|
.get('snippets')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
snippets: new Array(2).fill(matchSnippet)
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2020-10-16 20:02:58 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can read', async function () {
|
2022-03-29 17:33:30 +03:00
|
|
|
await agent
|
|
|
|
.get(`snippets/${fixtureManager.get('snippets', 0).id}/`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
snippets: [matchSnippet]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2020-10-16 20:02:58 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can edit', async function () {
|
2020-10-16 20:02:58 +03:00
|
|
|
const snippetToChange = {
|
|
|
|
name: 'change me',
|
|
|
|
mobiledoc: '{}'
|
|
|
|
};
|
|
|
|
|
|
|
|
const snippetChanged = {
|
|
|
|
name: 'changed',
|
|
|
|
mobiledoc: '{}'
|
|
|
|
};
|
|
|
|
|
2022-03-29 17:33:30 +03:00
|
|
|
const {body} = await agent
|
|
|
|
.post(`snippets/`)
|
|
|
|
.body({snippets: [snippetToChange]})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
snippets: [matchSnippet]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('snippets')
|
|
|
|
});
|
|
|
|
|
|
|
|
const newsnippet = body.snippets[0];
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.put(`snippets/${newsnippet.id}/`)
|
|
|
|
.body({snippets: [snippetChanged]})
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
snippets: [matchSnippet]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2020-10-16 20:02:58 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can destroy', async function () {
|
2020-10-16 20:02:58 +03:00
|
|
|
const snippet = {
|
|
|
|
name: 'destroy test',
|
|
|
|
mobiledoc: '{}'
|
|
|
|
};
|
|
|
|
|
2022-03-29 17:33:30 +03:00
|
|
|
const {body} = await agent
|
|
|
|
.post(`snippets/`)
|
|
|
|
.body({snippets: [snippet]})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
snippets: [matchSnippet]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('snippets')
|
|
|
|
});
|
2020-11-30 17:25:22 +03:00
|
|
|
|
2022-03-29 17:33:30 +03:00
|
|
|
const newSnippet = body.snippets[0];
|
2020-11-30 17:25:22 +03:00
|
|
|
|
2022-03-29 17:33:30 +03:00
|
|
|
await agent
|
|
|
|
.delete(`snippets/${newSnippet.id}`)
|
|
|
|
.expectStatus(204)
|
2022-03-31 20:55:46 +03:00
|
|
|
.expectEmptyBody()
|
2022-03-29 17:33:30 +03:00
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
2022-03-17 18:23:29 +03:00
|
|
|
});
|
2020-11-30 17:25:22 +03:00
|
|
|
|
2022-03-29 17:33:30 +03:00
|
|
|
await agent
|
|
|
|
.get(`snippets/${newSnippet.id}/`)
|
|
|
|
.expectStatus(404)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2020-10-16 20:02:58 +03:00
|
|
|
});
|
|
|
|
});
|