mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Return new tags when posts are created via API
closes #2680 - added include options when adding a post - added functional and integrational tests
This commit is contained in:
parent
0c252fb687
commit
66a046b00b
3 changed files with 48 additions and 11 deletions
|
@ -129,11 +129,17 @@ posts = {
|
|||
// #### Add
|
||||
// **takes:** a json object representing a post,
|
||||
add: function add(postData) {
|
||||
var self = this;
|
||||
var self = this,
|
||||
include;
|
||||
|
||||
// **returns:** a promise for the resulting post in a json object
|
||||
return canThis(this.user).create.post().then(function () {
|
||||
return checkPostData(postData).then(function (checkedPostData) {
|
||||
return dataProvider.Post.add(checkedPostData.posts[0], {user: self.user});
|
||||
if (postData.include) {
|
||||
include = prepareInclude(postData.include);
|
||||
}
|
||||
|
||||
return dataProvider.Post.add(checkedPostData.posts[0], {user: self.user, include: include});
|
||||
}).then(function (result) {
|
||||
var omitted = result.toJSON();
|
||||
if (!_.isNumber(omitted.author)) {
|
||||
|
|
|
@ -318,11 +318,12 @@ describe('Post API', function () {
|
|||
describe('Add', function () {
|
||||
it('can create a new draft, publish post, update post', function (done) {
|
||||
var newTitle = 'My Post',
|
||||
changedTitle = 'My Post changed',
|
||||
newTagName = 'My Tag',
|
||||
publishedState = 'published',
|
||||
newPost = {posts: [{status: 'draft', title: newTitle, markdown: 'my post'}]};
|
||||
newTag = {id: null, name: newTagName},
|
||||
newPost = {posts: [{status: 'draft', title: newTitle, markdown: 'my post', tags: [newTag]}]};
|
||||
|
||||
request.post(testUtils.API.getApiQuery('posts/'))
|
||||
request.post(testUtils.API.getApiQuery('posts/?include=tags'))
|
||||
.set('X-CSRF-Token', csrfToken)
|
||||
.send(newPost)
|
||||
.expect(200)
|
||||
|
@ -334,11 +335,17 @@ describe('Post API', function () {
|
|||
res.should.be.json;
|
||||
var draftPost = res.body;
|
||||
draftPost.posts.should.exist;
|
||||
draftPost.posts.length.should.be.above(0);
|
||||
draftPost.posts[0].title.should.eql(newTitle);
|
||||
draftPost.posts[0].status = publishedState;
|
||||
testUtils.API.checkResponse(draftPost.posts[0], 'post');
|
||||
|
||||
request.put(testUtils.API.getApiQuery('posts/' + draftPost.posts[0].id + '/'))
|
||||
draftPost.posts[0].tags.should.exist;
|
||||
draftPost.posts[0].tags.length.should.be.above(0);
|
||||
draftPost.posts[0].tags[0].name.should.eql(newTagName);
|
||||
testUtils.API.checkResponse(draftPost.posts[0].tags[0], 'tag');
|
||||
|
||||
request.put(testUtils.API.getApiQuery('posts/' + draftPost.posts[0].id + '/?include=tags'))
|
||||
.set('X-CSRF-Token', csrfToken)
|
||||
.send(draftPost)
|
||||
.expect(200)
|
||||
|
@ -351,13 +358,20 @@ describe('Post API', function () {
|
|||
_.has(res.headers, 'x-cache-invalidate').should.equal(true);
|
||||
res.headers['x-cache-invalidate'].should.eql('/, /page/*, /rss/, /rss/*, /tag/*, /' + publishedPost.posts[0].slug + '/');
|
||||
res.should.be.json;
|
||||
|
||||
publishedPost.should.exist;
|
||||
publishedPost.posts.should.exist;
|
||||
publishedPost.posts.length.should.be.above(0);
|
||||
publishedPost.posts[0].title.should.eql(newTitle);
|
||||
publishedPost.posts[0].status.should.eql(publishedState);
|
||||
testUtils.API.checkResponse(publishedPost.posts[0], 'post');
|
||||
|
||||
request.put(testUtils.API.getApiQuery('posts/' + publishedPost.posts[0].id + '/'))
|
||||
publishedPost.posts[0].tags.should.exist;
|
||||
publishedPost.posts[0].tags.length.should.be.above(0);
|
||||
publishedPost.posts[0].tags[0].name.should.eql(newTagName);
|
||||
testUtils.API.checkResponse(publishedPost.posts[0].tags[0], 'tag');
|
||||
|
||||
request.put(testUtils.API.getApiQuery('posts/' + publishedPost.posts[0].id + '/?include=tags'))
|
||||
.set('X-CSRF-Token', csrfToken)
|
||||
.send(publishedPost)
|
||||
.expect(200)
|
||||
|
@ -369,10 +383,18 @@ describe('Post API', function () {
|
|||
var updatedPost = res.body;
|
||||
_.has(res.headers, 'x-cache-invalidate').should.equal(false);
|
||||
res.should.be.json;
|
||||
|
||||
updatedPost.should.exist;
|
||||
updatedPost.posts.should.exist;
|
||||
updatedPost.posts.length.should.be.above(0);
|
||||
updatedPost.posts[0].title.should.eql(newTitle);
|
||||
testUtils.API.checkResponse(updatedPost.posts[0], 'post');
|
||||
|
||||
updatedPost.posts[0].tags.should.exist;
|
||||
updatedPost.posts[0].tags.length.should.be.above(0);
|
||||
updatedPost.posts[0].tags[0].name.should.eql(newTagName);
|
||||
testUtils.API.checkResponse(updatedPost.posts[0].tags[0], 'tag');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,10 +30,10 @@ describe('Post API', function () {
|
|||
}, done);
|
||||
});
|
||||
|
||||
it('browse', function (done) {
|
||||
it('can browse', function (done) {
|
||||
PostAPI.browse().then(function (results) {
|
||||
should.exist(results);
|
||||
testUtils.API.checkResponse(results, 'posts');
|
||||
testUtils.API.checkResponse(results, 'posts');
|
||||
should.exist(results.posts);
|
||||
results.posts.length.should.be.above(0);
|
||||
testUtils.API.checkResponse(results.posts[0], 'post');
|
||||
|
@ -41,7 +41,7 @@ describe('Post API', function () {
|
|||
}).then(null, done);
|
||||
});
|
||||
|
||||
it('read', function (done) {
|
||||
it('can read', function (done) {
|
||||
var firstPost;
|
||||
|
||||
PostAPI.browse().then(function (results) {
|
||||
|
@ -49,10 +49,19 @@ describe('Post API', function () {
|
|||
should.exist(results.posts);
|
||||
results.posts.length.should.be.above(0);
|
||||
firstPost = results.posts[0];
|
||||
return PostAPI.read({slug: firstPost.slug});
|
||||
return PostAPI.read({slug: firstPost.slug, include: 'tags'});
|
||||
}).then(function (found) {
|
||||
var post;
|
||||
|
||||
should.exist(found);
|
||||
testUtils.API.checkResponse(found.posts[0], 'post');
|
||||
|
||||
post = found.posts[0];
|
||||
|
||||
should.exist(post.tags);
|
||||
post.tags.length.should.be.above(0);
|
||||
testUtils.API.checkResponse(post.tags[0], 'tag');
|
||||
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue