Skip to content

Commit

Permalink
Merge pull request #6 from ClemDelp/add-topics
Browse files Browse the repository at this point in the history
Add topics
  • Loading branch information
Sung Won Cho authored Aug 12, 2017
2 parents 4a7d474 + ff8c509 commit 9266a00
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/v1.0.0/topics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var request = require('request');
/** @namespace */
var topics = {};

module.exports = function (client) {
/**
* @summary List of all topics
* @memberof topics
* @param {done} done - Callback
*
* @see https://api.producthunt.com/v1/docs/topics/topics_index_list_topics
*/
topics.index = function (done) {
client.httpGet('/topics', {}, done);
};

return topics;
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Client.prototype.setupAPI = function () {
this.currentUser = require(`./api/v${this.version}/current_user`)(this);
this.categories = require(`./api/v${this.version}/categories`)(this);
this.live = require(`./api/v${this.version}/live`)(this);
this.topics = require(`./api/v${this.version}/topics`)(this);
};

Client.prototype.getEndpoint = function(path) {
Expand Down
35 changes: 35 additions & 0 deletions test/v1.0.0/topics_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var expect = require('chai').expect;
var nock = require('nock');
var sinon = require('sinon');

var Client = require('../../index');
var c = new Client();
var topics = require('../../api/v1.0.0/topics')(c);

describe("topics", function() {
beforeEach(function() {
// Stub authenticate to be always successful
sinon.stub(Client.prototype, 'authenticate', function (done) {
done(null, 'test_access_token');
});
});

afterEach(function() {
// Remove the stub
Client.prototype.authenticate.restore();
});

describe("#index", function() {
it("is successful", function(done) {
nock('https://api.producthunt.com/v1')
.get('/topics')
.reply(200);

topics.index(function (err, res) {
expect(err).to.equal(null);
expect(res.statusCode).to.equal(200);
done();
});
});
});
});

0 comments on commit 9266a00

Please sign in to comment.