mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
🐛 Fixed tag url field when explicitly querying fields
refs https://github.com/TryGhost/Ghost/issues/14983 The url field of tags is read dynamically from the url service, rather than from the database. The lookup requires the id of the tag, which was missing from the model when asking for explicit fields which didn't include id. By adding the id as a default column to fetch, we know for sure that we will always have the necessary data to read the url.
This commit is contained in:
parent
c6621dc17d
commit
feaf5d0c91
2 changed files with 43 additions and 0 deletions
|
@ -154,6 +154,10 @@ Tag = ghostBookshelf.Model.extend({
|
|||
actor_id: actor.id,
|
||||
actor_type: actor.type
|
||||
};
|
||||
},
|
||||
|
||||
defaultColumnsToFetch() {
|
||||
return ['id'];
|
||||
}
|
||||
}, {
|
||||
orderDefaultOptions: function orderDefaultOptions() {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const assert = require('assert');
|
||||
const should = require('should');
|
||||
const supertest = require('supertest');
|
||||
const _ = require('lodash');
|
||||
|
@ -104,4 +105,42 @@ describe('Tags Content API', function () {
|
|||
_.find(jsonResponse.tags, {name: 'bacon'}).count.posts.should.eql(2);
|
||||
_.find(jsonResponse.tags, {name: 'chorizo'}).count.posts.should.eql(1);
|
||||
});
|
||||
|
||||
it('Can use multiple fields and have valid url fields', async function () {
|
||||
const res = await request.get(localUtils.API.getApiQuery(`tags/?key=${validKey}&fields=url,name`))
|
||||
.set('Origin', testUtils.API.getURL())
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
|
||||
const jsonResponse = res.body;
|
||||
|
||||
assert(jsonResponse.tags);
|
||||
|
||||
const getTag = name => jsonResponse.tags.find(tag => tag.name === name);
|
||||
|
||||
assert(getTag('Getting Started').url.endsWith('/tag/getting-started/'));
|
||||
assert(getTag('kitchen sink').url.endsWith('/tag/kitchen-sink/'));
|
||||
assert(getTag('bacon').url.endsWith('/tag/bacon/'));
|
||||
assert(getTag('chorizo').url.endsWith('/tag/chorizo/'));
|
||||
});
|
||||
|
||||
it('Can use single url field and have valid url fields', async function () {
|
||||
const res = await request.get(localUtils.API.getApiQuery(`tags/?key=${validKey}&fields=url`))
|
||||
.set('Origin', testUtils.API.getURL())
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
|
||||
const jsonResponse = res.body;
|
||||
|
||||
assert(jsonResponse.tags);
|
||||
|
||||
const getTag = path => jsonResponse.tags.find(tag => tag.url.endsWith(path));
|
||||
|
||||
assert(getTag('/tag/getting-started/'));
|
||||
assert(getTag('/tag/kitchen-sink/'));
|
||||
assert(getTag('/tag/bacon/'));
|
||||
assert(getTag('/tag/chorizo/'));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue