diff --git a/core/server/api/utils.js b/core/server/api/utils.js index 6c2ee9603d..d31cdae9f4 100644 --- a/core/server/api/utils.js +++ b/core/server/api/utils.js @@ -18,6 +18,15 @@ utils = { if (_.isEmpty(object) || _.isEmpty(object[docName]) || _.isEmpty(object[docName][0])) { return when.reject(new errors.BadRequestError('No root key (\'' + docName + '\') provided.')); } + + // convert author property to author_id to match the name in the database + // TODO: rename object in database + if (docName === 'posts') { + if (object.posts[0].hasOwnProperty('author')) { + object.posts[0].author_id = object.posts[0].author; + delete object.posts[0].author; + } + } return when.resolve(object); } }; diff --git a/core/test/functional/routes/api/posts_test.js b/core/test/functional/routes/api/posts_test.js index 904e68a46a..7b0bcdf563 100644 --- a/core/test/functional/routes/api/posts_test.js +++ b/core/test/functional/routes/api/posts_test.js @@ -438,9 +438,11 @@ describe('Post API', function () { } var jsonResponse = res.body, - changedValue = 'My new Title'; + changedTitle = 'My new Title', + changedAuthor = 2; jsonResponse.posts[0].should.exist; - jsonResponse.posts[0].title = changedValue; + jsonResponse.posts[0].title = changedTitle; + jsonResponse.posts[0].author = changedAuthor; request.put(testUtils.API.getApiQuery('posts/1/')) .set('Authorization', 'Bearer ' + accesstoken) @@ -455,7 +457,8 @@ describe('Post API', function () { var putBody = res.body; _.has(res.headers, 'x-cache-invalidate').should.equal(true); putBody.should.exist; - putBody.posts[0].title.should.eql(changedValue); + putBody.posts[0].title.should.eql(changedTitle); + putBody.posts[0].author.should.eql(changedAuthor); testUtils.API.checkResponse(putBody.posts[0], 'post'); done();