Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #193 from cnpm/issue189-search-api
Browse files Browse the repository at this point in the history
support json result in search, fixed #189
  • Loading branch information
fengmk2 committed Feb 19, 2014
2 parents 666d98d + 0f6b6a2 commit 90959ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion controllers/web/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ exports.search = function (req, res, next) {
if (err) {
return next(err);
}

// return a json result
if (req.query && req.query.type === 'json') {
return res.json({
keyword: word,
packages: result.searchMatchs,
keywords: result.keywordMatchs
});
}
res.render('search', {
title: 'Keyword - ' + word,
keyword: word,
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/web/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ describe('controllers/web/package.test.js', function () {
.expect(/Packages match/, done);
});

it('should list by keyword with json ok', function (done) {
request(app)
.get('/browse/keyword/cnpm?type=json')
.expect(200)
.expect('content-type', 'application/json; charset=utf-8', done);
});

it('should list no match ok', function (done) {
request(app)
.get('/browse/keyword/notexistpackage')
Expand Down

0 comments on commit 90959ba

Please sign in to comment.