Files
habitica/test/api/v3/integration/coupons/POST-coupons_validate_code.test.js
Matteo Pagliazzi 85fb5f33aa fix test lint
2019-10-08 20:45:38 +02:00

37 lines
983 B
JavaScript

import {
generateUser,
requester,
resetHabiticaDB,
} from '../../../../helpers/api-integration/v3';
describe('POST /coupons/validate/:code', () => {
const 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 () => {
const sudoUser = await generateUser({
'contributor.sudo': true,
});
const [coupon] = await sudoUser.post('/coupons/generate/wondercon?count=1');
const res = await api.post(`/coupons/validate/${coupon._id}`);
expect(res).to.eql({ valid: true });
});
it('returns false if coupon code is valid', async () => {
const res = await api.post('/coupons/validate/notValid');
expect(res).to.eql({ valid: false });
});
});