0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Removed primary_tag & primary_author if null from Admin API v2

refs #10438

- "null" means the resource does not exist (it was sett to "null"), which is not true
- we won't serve primary_tag and primary_author by default
- TODO: add the same change to the Content API v2 (raise issue)
This commit is contained in:
kirrg001 2019-02-24 13:06:08 +01:00
parent 377d7e4271
commit 0665c72dda
4 changed files with 17 additions and 12 deletions

View file

@ -100,6 +100,14 @@ const post = (attrs, frame) => {
}
} else {
delete attrs.page;
if (!attrs.tags) {
delete attrs.primary_tag;
}
if (!attrs.authors) {
delete attrs.primary_author;
}
}
delete attrs.locale;

View file

@ -45,7 +45,7 @@ describe('Pages API', function () {
localUtils.API.checkResponse(jsonResponse, 'pages');
jsonResponse.pages.should.have.length(2);
localUtils.API.checkResponse(jsonResponse.pages[0], 'page');
localUtils.API.checkResponse(jsonResponse.pages[0], 'page', null, ['primary_tag', 'primary_author']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.pages[0].featured).should.eql(true);
@ -72,7 +72,7 @@ describe('Pages API', function () {
.expect(201)
.then((res) => {
res.body.pages.length.should.eql(1);
localUtils.API.checkResponse(res.body.pages[0], 'page');
localUtils.API.checkResponse(res.body.pages[0], 'page', null, ['primary_tag', 'primary_author']);
should.exist(res.headers['x-cache-invalidate']);
return models.Post.findOne({
@ -108,7 +108,7 @@ describe('Pages API', function () {
})
.then((res) => {
should.exist(res.headers['x-cache-invalidate']);
localUtils.API.checkResponse(res.body.pages[0], 'page');
localUtils.API.checkResponse(res.body.pages[0], 'page', null, ['primary_tag', 'primary_author']);
return models.Post.findOne({
id: res.body.pages[0].id

View file

@ -44,7 +44,7 @@ describe('Posts API', function () {
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(13);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', null, ['primary_tag', 'primary_author']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
@ -77,7 +77,7 @@ describe('Posts API', function () {
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(3);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html', 'primary_tag', 'primary_author']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
@ -138,7 +138,7 @@ describe('Posts API', function () {
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(2);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', null, ['primary_tag', 'primary_author']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
@ -196,7 +196,7 @@ describe('Posts API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', null, ['primary_tag', 'primary_author']);
jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id);
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
@ -223,7 +223,7 @@ describe('Posts API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', null, ['primary_tag', 'primary_author']);
jsonResponse.posts[0].slug.should.equal('welcome');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
@ -282,7 +282,7 @@ describe('Posts API', function () {
.expect(201)
.then((res) => {
res.body.posts.length.should.eql(1);
localUtils.API.checkResponse(res.body.posts[0], 'post');
localUtils.API.checkResponse(res.body.posts[0], 'post', null, ['primary_tag', 'primary_author']);
should.not.exist(res.headers['x-cache-invalidate']);
return models.Post.findOne({

View file

@ -139,7 +139,6 @@ describe('Posts API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(res.body.posts);
should.exist(res.body.posts[0].published_at);
localUtils.API.checkResponse(res.body.posts[0], 'post');
});
});
@ -162,8 +161,6 @@ describe('Posts API', function () {
// @NOTE: you cannot modify these fields above manually, that's why the resource won't change.
should.not.exist(res.headers['x-cache-invalidate']);
localUtils.API.checkResponse(res.body.posts[0], 'post');
return models.Post.findOne({
id: res.body.posts[0].id
}, testUtils.context.internal);