diff --git a/plugins/summoner.js b/plugins/summoner.js index fd903792..37e1f040 100644 --- a/plugins/summoner.js +++ b/plugins/summoner.js @@ -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) => { diff --git a/test/plugins/summonerTest.js b/test/plugins/summonerTest.js index 3a3220cc..55ce6e6e 100644 --- a/test/plugins/summonerTest.js +++ b/test/plugins/summonerTest.js @@ -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');