Skip to content

Commit

Permalink
Merge pull request #406 from RaceProUK/master
Browse files Browse the repository at this point in the history
fix: Summoner - Use `username` if `name` is missing
  • Loading branch information
AccaliaDeElementia authored Feb 28, 2017
2 parents 9bfeb5c + 546bdf3 commit 76b18ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/summoner.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module.exports = function summoner(forum, config) {
debug('summoner received a mention notification!');
return notification.getUser()
.then((user) => {
if (user.username && !user.name) {
user.name = user.username;
}
debug(`summoner responding to summons by ${user.name}`);
const index = Math.floor(Math.random() * messages.length);
const message = messages[index].replace(/%(\w+)%/g, (_, key) => {
Expand Down
18 changes: 18 additions & 0 deletions test/plugins/summonerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ describe('plugins/echo', () => {
forum.Post.reply.should.have.been.calledWith(undefined, undefined, '%keyblade%').once;
});
});
it('should substitute `username` when `name` is missing', () => {
const expected = `a${Math.random()}b`;
user.username = expected;
summoner = testModule(forum, ['%name%']);
return summoner.handler(notification).then(() => {
forum.Post.reply.should.have.been.calledWith(undefined, undefined, expected).once;
});
});
it('should not substitute `username` when `name` is present', () => {
const dummy = `b${Math.random()}a`;
const expected = `a${Math.random()}b`;
user.username = dummy;
user.name = expected;
summoner = testModule(forum, ['%name%']);
return summoner.handler(notification).then(() => {
forum.Post.reply.should.have.been.calledWith(undefined, undefined, expected).once;
});
});
it('choose message randomly', () => {
const sandbox = sinon.sandbox.create();
sandbox.stub(Math, 'random');
Expand Down

0 comments on commit 76b18ae

Please sign in to comment.