Skip to content

Commit

Permalink
feat(topic): Added lock and unlock
Browse files Browse the repository at this point in the history
These should reject if you're not a moderator
  • Loading branch information
yamikuronue committed Apr 11, 2017
1 parent d0373a9 commit b2bb573
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 b2bb573

Please sign in to comment.