Api quest restrictions - no purchase/start without fulfilling eligibility requirements (#10387)

* removing duplicate translation key

* fixing typos

* extracting quest prerequisite check. adding check for previous quest completion, if required

* fixing (undoing) static change, adding tests

* more typos

* correcting test failures

* honoring quest prerequisites in quest invite API call. updating format of il8n string replacement arg

* no longer using apiError, use translate method instead (msg key was not defined)

* adding @apiError to docblock as requested in issue

* removing checks on quest invite method. small window of opportunity/low risk
This commit is contained in:
Brian Fenton
2018-05-27 09:41:56 -05:00
committed by Matteo Pagliazzi
parent 8fb67e7944
commit ac90a40be5
9 changed files with 64 additions and 11 deletions
@@ -38,4 +38,32 @@ describe('POST /user/buy-quest/:key', () => {
itemText: item.text(),
}));
});
it('returns an error if quest prerequisites are not met', async () => {
let key = 'dilatoryDistress2';
await expect(user.post(`/user/buy-quest/${key}`))
.to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('mustComplete', {quest: 'dilatoryDistress1'}),
});
});
it('allows purchase of a quest if prerequisites are met', async () => {
const prerequisite = 'dilatoryDistress1';
const key = 'dilatoryDistress2';
const item = content.quests[key];
const achievementName = `achievements.quests.${prerequisite}`;
await user.update({[achievementName]: true, 'stats.gp': 9999});
let res = await user.post(`/user/buy-quest/${key}`);
await user.sync();
expect(res.data).to.eql(user.items.quests);
expect(res.message).to.equal(t('messageBought', {
itemText: item.text(),
}));
});
});