Skip to content

Commit

Permalink
Merge pull request #358 from SockDrawer/feature-makeTopics
Browse files Browse the repository at this point in the history
Feature make topics
  • Loading branch information
AccaliaDeElementia authored Aug 30, 2016
2 parents cbe9407 + 8abf237 commit 1a282e1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/api/providers/nodebb/category.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ NodeBB provider module Category class
* [.url()](#sockbot.providers.nodebb.module_Category..Category+url) ⇒ <code>Promise.&lt;string&gt;</code>
* [.getAllTopics(eachTopic)](#sockbot.providers.nodebb.module_Category..Category+getAllTopics) ⇒ <code>Promise</code>
* [.getRecentTopics(eachTopic)](#sockbot.providers.nodebb.module_Category..Category+getRecentTopics) ⇒ <code>Promise</code>
* [.addTopic(title, body)](#sockbot.providers.nodebb.module_Category..Category+addTopic) ⇒ <code>Promise.&lt;Topic&gt;</code>
* [.watch()](#sockbot.providers.nodebb.module_Category..Category+watch) ⇒ <code>Promise.&lt;Category&gt;</code>
* [.unwatch()](#sockbot.providers.nodebb.module_Category..Category+unwatch) ⇒ <code>Promise.&lt;Category&gt;</code>
* [.mute()](#sockbot.providers.nodebb.module_Category..Category+mute) ⇒ <code>Promise.&lt;Category&gt;</code>
Expand Down Expand Up @@ -66,6 +67,7 @@ Represents a forum category.
* [.url()](#sockbot.providers.nodebb.module_Category..Category+url) ⇒ <code>Promise.&lt;string&gt;</code>
* [.getAllTopics(eachTopic)](#sockbot.providers.nodebb.module_Category..Category+getAllTopics) ⇒ <code>Promise</code>
* [.getRecentTopics(eachTopic)](#sockbot.providers.nodebb.module_Category..Category+getRecentTopics) ⇒ <code>Promise</code>
* [.addTopic(title, body)](#sockbot.providers.nodebb.module_Category..Category+addTopic) ⇒ <code>Promise.&lt;Topic&gt;</code>
* [.watch()](#sockbot.providers.nodebb.module_Category..Category+watch) ⇒ <code>Promise.&lt;Category&gt;</code>
* [.unwatch()](#sockbot.providers.nodebb.module_Category..Category+unwatch) ⇒ <code>Promise.&lt;Category&gt;</code>
* [.mute()](#sockbot.providers.nodebb.module_Category..Category+mute) ⇒ <code>Promise.&lt;Category&gt;</code>
Expand Down Expand Up @@ -170,6 +172,20 @@ Get all recently active Topics in the category
| --- | --- | --- |
| eachTopic | <code>TopicProcessor</code> | A function to process each topic |

<a name="sockbot.providers.nodebb.module_Category..Category+addTopic"></a>

#### category.addTopic(title, body) ⇒ <code>Promise.&lt;Topic&gt;</code>
Add a topic to this category

**Kind**: instance method of <code>[Category](#sockbot.providers.nodebb.module_Category..Category)</code>
**Returns**: <code>Promise.&lt;Topic&gt;</code> - Resolves to the newly created topic
**Access:** public

| Param | Type | Description |
| --- | --- | --- |
| title | <code>string</code> | The title of the topic |
| body | <code>string</code> | The body of the first post of the topic |

<a name="sockbot.providers.nodebb.module_Category..Category+watch"></a>

#### category.watch() ⇒ <code>Promise.&lt;Category&gt;</code>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "sockbot",
"version": "0.0.0-semantic-release",
"description": "A sockpuppet bot to use on http://what.thedailywtf.com.",
"repository": {
"type": "git",
Expand Down
24 changes: 24 additions & 0 deletions providers/nodebb/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,29 @@ exports.bindCategory = function bindCategory(forum) {
return forum._emit(action, payload)
.then(() => this);
}

/**
* Add a topic to this category
*
* @public
*
* @param {string} title The title of the topic
* @param {string} body The body of the first post of the topic
*
* @returns {Promise<Topic>} Resolves to the newly created topic
*/
addTopic(title, body) {
const payload = {
'category_id': this.id,
title: title,
content: body,
tags: [],
'topic_thumb': ''
};

return forum._emit('topics.post', payload)
.then((results) => forum.Topic.parse(results));
}

/**
* Watch this category for new activity
Expand Down Expand Up @@ -286,6 +309,7 @@ exports.bindCategory = function bindCategory(forum) {
return forum.fetchObject('categories.getCategory', categoryId, Category.parse);
}


/**
* Parse a category from payload data
*
Expand Down
15 changes: 15 additions & 0 deletions test/providers/nodebb/categoryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe('providers/nodebb/categor', () => {
const Category = categoryModule.bindCategory(forum);
beforeEach(() => {
forum._emit = sinon.stub().resolves();
forum.Topic = {
parse: sinon.stub().resolves()
};
forum.fetchObject = sinon.stub().resolves();
});
describe('ctor()', () => {
Expand Down Expand Up @@ -94,6 +97,18 @@ describe('providers/nodebb/categor', () => {
return category.url().should.become(expected);
});
});

describe('addTopic()', () => {
let category;
beforeEach(() => {
category = new Category({});
});
it('should emit `topics.post`', () => {
return category.addTopic('title', 'body').then(() => {
forum._emit.should.have.been.calledWith('topics.post').once;
});
});
});
describe('getAllTopics()', () => {
let category, data, spy;
beforeEach(() => {
Expand Down

0 comments on commit 1a282e1

Please sign in to comment.