0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Add support for GET /tags/slug/:slug with unit tests

closes #5371
- added new endpoint to the api routes
- created unit tests based on PostModel and PostAPI for testing slug links
This commit is contained in:
Augustus Yuan 2015-06-10 18:42:17 -07:00
parent 906504e43b
commit 05fe09293f
3 changed files with 47 additions and 0 deletions

View file

@ -39,6 +39,7 @@ apiRoutes = function apiRoutes(middleware) {
// ## Tags
router.get('/tags', api.http(api.tags.browse));
router.get('/tags/:id', api.http(api.tags.read));
router.get('/tags/slug/:slug', api.http(api.tags.read));
router.post('/tags', api.http(api.tags.add));
router.put('/tags/:id', api.http(api.tags.edit));
router.del('/tags/:id', api.http(api.tags.destroy));

View file

@ -177,6 +177,10 @@ describe('Tags API', function () {
});
describe('Read', function () {
function extractFirstTag(tags) {
return _.filter(tags, {id: 1})[0];
}
it('returns post_count with include post_count', function (done) {
TagAPI.read({context: {user: 1}, include: 'post_count', slug: 'kitchen-sink'}).then(function (results) {
should.exist(results);
@ -190,5 +194,22 @@ describe('Tags API', function () {
done();
}).catch(done);
});
it('with slug', function (done) {
TagAPI.browse({context: {user: 1}}).then(function (results) {
should.exist(results);
should.exist(results.tags);
results.tags.length.should.be.above(0);
var firstTag = extractFirstTag(results.tags);
return TagAPI.read({context: {user: 1}, slug: firstTag.slug});
}).then(function (found) {
should.exist(found);
testUtils.API.checkResponse(found.tags[0], 'tag');
done();
}).catch(done);
});
});
});

View file

@ -91,6 +91,31 @@ describe('Tag Model', function () {
});
});
describe('findOne', function () {
beforeEach(function (done) {
testUtils.fixtures.insertPosts().then(function () {
done();
}).catch(done);
});
it('with slug', function (done) {
var firstTag;
TagModel.findPage().then(function (results) {
should.exist(results);
should.exist(results.tags);
results.tags.length.should.be.above(0);
firstTag = results.tags[0];
return TagModel.findOne({slug: firstTag.slug});
}).then(function (found) {
should.exist(found);
done();
}).catch(done);
});
});
describe('a Post', function () {
it('can add a tag', function (done) {
var newPost = testUtils.DataGenerator.forModel.posts[0],