mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
37 lines
969 B
JavaScript
37 lines
969 B
JavaScript
import {
|
|
generateUser,
|
|
requester,
|
|
resetHabiticaDB,
|
|
} from '../../../../helpers/api-integration/v3';
|
|
|
|
describe('POST /coupons/validate/:code', () => {
|
|
let api = requester();
|
|
|
|
before(async () => {
|
|
await resetHabiticaDB();
|
|
});
|
|
|
|
it('returns an error if code is missing', async () => {
|
|
await expect(api.post('/coupons/validate')).to.eventually.be.rejected.and.eql({
|
|
code: 404,
|
|
error: 'NotFound',
|
|
message: 'Not found.',
|
|
});
|
|
});
|
|
|
|
it('returns true if coupon code is valid', async () => {
|
|
let sudoUser = await generateUser({
|
|
'contributor.sudo': true,
|
|
});
|
|
|
|
let [coupon] = await sudoUser.post('/coupons/generate/wondercon?count=1');
|
|
let res = await api.post(`/coupons/validate/${coupon._id}`);
|
|
expect(res).to.eql({valid: true});
|
|
});
|
|
|
|
it('returns false if coupon code is valid', async () => {
|
|
let res = await api.post('/coupons/validate/notValid');
|
|
expect(res).to.eql({valid: false});
|
|
});
|
|
});
|