Fix editing author

no issue
- author_id is converted to author for API responses but was never
converted back for requests
This commit is contained in:
Sebastian Gierlinger 2014-07-18 10:48:48 +02:00
parent 48cbf371a2
commit 62c1ce128e
2 changed files with 15 additions and 3 deletions

View File

@ -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);
}
};

View File

@ -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();