From 923b6c495e73586f25b42a8d46feaff35632c116 Mon Sep 17 00:00:00 2001 From: Alyssa Batula Date: Sun, 11 Sep 2016 00:03:28 -0400 Subject: [PATCH] Collection quest progress reports "found no [item names]" fixes #7816 (#7883) * Updated collection quest tests for no found items. Single-item quests state [user] found no [items]. instead of [user] found nothing. If a quest has two items, the chat message is [user] found no [item1] and no [item2]. * Collection quest messages changed from [user] found nothing to [user] found no [item] * Tests for no collection quest items found changed to [user] found 0 [item1], 0 [item2] * Changed chat messages for no found collection quest items to [user] found 0 [item1], 0 [item2] * Sort items alphabetically in multi-item quests so that it always returns the same string * Formatting updates to conform to test specifications (for collection quest progress reports with no items found * Simplified handling of items not found: any items not found are added to the list of found items with quantity 0 for reporting in the group chat. This also causes all items to appear, in the list, even if only one type is found in a multi-item quest. * Test the group chat message when no items are found in multi-item quests. Test succes no longer depends on the order items are listed. --- test/api/v3/unit/models/group.test.js | 20 +++++++++++++++++++- website/server/models/group.js | 10 +++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/api/v3/unit/models/group.test.js b/test/api/v3/unit/models/group.test.js index ff3785ef5a..577d8108a6 100644 --- a/test/api/v3/unit/models/group.test.js +++ b/test/api/v3/unit/models/group.test.js @@ -350,7 +350,25 @@ describe('Group Model', () => { party = await Group.findOne({_id: party._id}); expect(Group.prototype.sendChat).to.be.calledOnce; - expect(Group.prototype.sendChat).to.be.calledWith('`Participating Member found nothing.`'); + expect(Group.prototype.sendChat).to.be.calledWith('`Participating Member found 0 Bars of Soap.`'); + }); + + it('sends a chat message if no progress is made on quest with multiple items', async () => { + progress.collectedItems = 0; + party.quest.key = 'dilatoryDistress1'; + party.quest.active = false; + + await party.startQuest(questLeader); + await party.save(); + + await Group.processQuestProgress(participatingMember, progress); + + party = await Group.findOne({_id: party._id}); + + expect(Group.prototype.sendChat).to.be.calledOnce; + expect(Group.prototype.sendChat).to.be.calledWithMatch(/`Participating Member found/); + expect(Group.prototype.sendChat).to.be.calledWithMatch(/0 Blue Fins/); + expect(Group.prototype.sendChat).to.be.calledWithMatch(/0 Fire Coral/); }); it('handles collection quests with multiple items', async () => { diff --git a/website/server/models/group.js b/website/server/models/group.js index c9a275679b..501d7d4857 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -607,12 +607,20 @@ schema.methods._processCollectionQuest = async function processCollectionQuest ( group.quest.progress.collect[item]++; }); + // Add 0 for all items not found + let questItems = Object.keys(this.quest.progress.collect); + for (let i = 0; i < questItems.length; i++) { + if (!itemsFound[questItems[i]]) { + itemsFound[questItems[i]] = 0; + } + } + let foundText = _.reduce(itemsFound, (m, v, k) => { m.push(`${v} ${quest.collect[k].text('en')}`); return m; }, []); - foundText = foundText.length > 0 ? foundText.join(', ') : 'nothing'; + foundText = foundText.join(', '); group.sendChat(`\`${user.profile.name} found ${foundText}.\``); group.markModified('quest.progress.collect');