Skip to content

Commit

Permalink
Merge pull request #416 from SockDrawer/feat-lock-topics
Browse files Browse the repository at this point in the history
feat(topic): Added lock and unlock
  • Loading branch information
AccaliaDeElementia authored Apr 11, 2017
2 parents d0373a9 + b2bb573 commit 2dcf223
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
38 changes: 38 additions & 0 deletions providers/nodebb/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,44 @@ exports.bindTopic = function bindTopic(forum) {
unmute() {
return Promise.resolve(this);
}

/**
* Locks the topic. Will reject if you're not a moderator.
*
* @public
*
* @returns {Promise<Topic>} Resolves to self on completion
*
* @promise
* @fulfill {Topic} Source Topic
* @reject {Error} An Error that occured while posting
*/
lock() {
return forum._emit('topics.lock', {
tids: [this.id],
cid: this.categoryId
})
.then(() => this);
}

/**
* Unlocks the topic. Will reject if you're not a moderator.
*
* @public
*
* @returns {Promise<Topic>} Resolves to self on completion
*
* @promise
* @fulfill {Topic} Source Topic
* @reject {Error} An Error that occured while posting
*/
unlock() {
return forum._emit('topics.unlock', {
tids: [this.id],
cid: this.categoryId
})
.then(() => this);
}

/**
* Retrieve a topic by topic id
Expand Down
52 changes: 52 additions & 0 deletions test/providers/nodebb/topicTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,58 @@ describe('providers/nodebb/topic', () => {
return topic.unmute().should.become(topic);
});
});
describe('lock()', () => {
let topic, data;
beforeEach(() => {
topic = new Topic({});
data = utils.mapGet(topic);
});
it('should emit `topics.lock` via websocket', () => {
const id = Math.random();
const cid = Math.random();
data.id = id;
data.categoryId = cid;
return topic.lock().then(() => {
forum._emit.calledWith('topics.lock', {
tids: [id],
cid: cid
}).should.be.true;
});
});
it('should resolve to locked topic', () => {
return topic.lock().should.become(topic);
});
it('should reject if websocket rejects', () => {
forum._emit.rejects('bad');
return topic.lock().should.be.rejected;
});
});
describe('unlock()', () => {
let topic, data;
beforeEach(() => {
topic = new Topic({});
data = utils.mapGet(topic);
});
it('should emit `topics.unlock` via websocket', () => {
const id = Math.random();
const cid = Math.random();
data.id = id;
data.categoryId = cid;
return topic.unlock().then(() => {
forum._emit.calledWith('topics.unlock', {
tids: [id],
cid: cid
}).should.be.true;
});
});
it('should resolve to locked topic', () => {
return topic.unlock().should.become(topic);
});
it('should reject if websocket rejects', () => {
forum._emit.rejects('bad');
return topic.unlock().should.be.rejected;
});
});
describe('static functions', () => {
describe('static getRecentTopics()', () => {
let spy = () => 0;
Expand Down

0 comments on commit 2dcf223

Please sign in to comment.