mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
* Updated userItemsNotEnough string * Added a variable to be passed to the deleteSocialAccountText string. This variable name is `magic_word` and is set as DELETE where used * modified incorrectDeletePhrase to use a variable rather than translatable string for the word DELETE. Updated the DELETE-user test and the user api * Changed noSudoAccess from translatable string to static * Changed enterprisePlansEmailSubject from a translatable string to a static string within groupPlans.vue * Fixed test problems with translation fixes * Added no sudo access string to api messages * changed plain string to apiMessage for no sudo access messages
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
import {
|
|
generateUser,
|
|
translate as t,
|
|
resetHabiticaDB,
|
|
} from '../../../../helpers/api-v3-integration.helper';
|
|
import couponCode from 'coupon-code';
|
|
import apiMessages from '../../../../../website/server/libs/apiMessages';
|
|
|
|
describe('POST /coupons/generate/:event', () => {
|
|
let user;
|
|
before(async () => {
|
|
await resetHabiticaDB();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
user = await generateUser({
|
|
'contributor.sudo': true,
|
|
});
|
|
});
|
|
|
|
it('returns an error if user has no sudo permission', async () => {
|
|
await user.update({
|
|
'contributor.sudo': false,
|
|
});
|
|
|
|
await expect(user.post('/coupons/generate/aaa')).to.eventually.be.rejected.and.eql({
|
|
code: 401,
|
|
error: 'NotAuthorized',
|
|
message: apiMessages('noSudoAccess'),
|
|
});
|
|
});
|
|
|
|
it('returns an error if event is invalid', async () => {
|
|
await expect(user.post('/coupons/generate/notValid?count=1')).to.eventually.be.rejected.and.eql({
|
|
code: 400,
|
|
error: 'BadRequest',
|
|
message: 'Coupon validation failed',
|
|
});
|
|
});
|
|
|
|
it('returns an error if count is missing', async () => {
|
|
await expect(user.post('/coupons/generate/notValid')).to.eventually.be.rejected.and.eql({
|
|
code: 400,
|
|
error: 'BadRequest',
|
|
message: t('invalidReqParams'),
|
|
});
|
|
});
|
|
|
|
it('should generate coupons', async () => {
|
|
await user.update({
|
|
'contributor.sudo': true,
|
|
});
|
|
|
|
let coupons = await user.post('/coupons/generate/wondercon?count=2');
|
|
expect(coupons.length).to.equal(2);
|
|
expect(coupons[0].event).to.equal('wondercon');
|
|
expect(couponCode.validate(coupons[1]._id)).to.not.equal(''); // '' means invalid
|
|
});
|
|
});
|