mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
735edf5f87
refs https://github.com/TryGhost/Team/issues/3167 - When editing collection that does not exist the API should be returning a 404 instead of creating a new collection
131 lines
3.5 KiB
JavaScript
131 lines
3.5 KiB
JavaScript
const assert = require('assert');
|
|
const {
|
|
agentProvider,
|
|
fixtureManager,
|
|
mockManager,
|
|
matchers
|
|
} = require('../../utils/e2e-framework');
|
|
const {
|
|
anyContentVersion,
|
|
anyEtag,
|
|
anyErrorId,
|
|
anyLocationFor,
|
|
anyObjectId
|
|
} = matchers;
|
|
|
|
const matchCollection = {
|
|
id: anyObjectId
|
|
};
|
|
|
|
describe('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 add a Collection', async function () {
|
|
const collection = {
|
|
title: 'Test Collection',
|
|
description: 'Test Collection Description'
|
|
};
|
|
|
|
await agent
|
|
.post('/collections/')
|
|
.body({
|
|
collections: [collection]
|
|
})
|
|
.expectStatus(201)
|
|
.matchHeaderSnapshot({
|
|
'content-version': anyContentVersion,
|
|
etag: anyEtag,
|
|
location: anyLocationFor('collections')
|
|
})
|
|
.matchBodySnapshot({
|
|
collections: [matchCollection]
|
|
});
|
|
});
|
|
|
|
it('Can browse Collections', async function () {
|
|
await agent
|
|
.get('/collections/')
|
|
.expectStatus(200)
|
|
.matchHeaderSnapshot({
|
|
'content-version': anyContentVersion,
|
|
etag: anyEtag
|
|
})
|
|
.matchBodySnapshot({
|
|
collections: [matchCollection]
|
|
});
|
|
});
|
|
|
|
it('Can edit a Collection', async function () {
|
|
const collection = {
|
|
title: 'Test Collection to Edit'
|
|
};
|
|
|
|
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;
|
|
|
|
const editResponse = await agent
|
|
.put(`/collections/${collectionId}/`)
|
|
.body({
|
|
collections: [{
|
|
title: 'Test Collection Edited'
|
|
}]
|
|
})
|
|
.expectStatus(200)
|
|
.matchHeaderSnapshot({
|
|
'content-version': anyContentVersion,
|
|
etag: anyEtag
|
|
})
|
|
.matchBodySnapshot({
|
|
collections: [matchCollection]
|
|
});
|
|
|
|
assert.equal(editResponse.body.collections[0].title, 'Test Collection Edited');
|
|
});
|
|
|
|
it('Fails to edit unexistent Collection', async function () {
|
|
const unexistentID = '5951f5fca366002ebd5dbef7';
|
|
await agent
|
|
.put(`/collections/${unexistentID}/`)
|
|
.body({
|
|
collections: [{
|
|
id: unexistentID,
|
|
title: 'Editing unexistent Collection'
|
|
}]
|
|
})
|
|
.expectStatus(404)
|
|
.matchBodySnapshot({
|
|
errors: [{
|
|
id: anyErrorId
|
|
}]
|
|
})
|
|
.matchHeaderSnapshot({
|
|
'content-version': anyContentVersion,
|
|
etag: anyEtag
|
|
});
|
|
});
|
|
});
|