habitica-self-host/test/api/v3/integration/coupons/GET-coupons.test.js
Phillip Thelen f8d315ff6e
Upgrade to mongoose 7 (#14971)
* remove some unused dependencies

* update mongoose version

* make common tests pass

* Make unit tests pass

* make api v3 integration tests pass

* fix lint issues

* fix issue with package-lock

* fix(lint): we don't need no .js

* fix(lint): update to latest config-habitrpg

* chore(npm): update package locks

* fix(test): replace deprecated fn

* chore(package): update eslint-habitrpg again

* fix(lint): server linting

* fix(lint): client linting

* fix(client): correct mangled common imports

* chore(npm): update package-locks

* fix(lint): punctuation, module

---------

Co-authored-by: SabreCat <sabrecat@gmail.com>
Co-authored-by: SabreCat <sabe@habitica.com>
2024-01-16 15:18:47 -06:00

39 lines
1.2 KiB
JavaScript

import {
generateUser,
resetHabiticaDB,
} from '../../../../helpers/api-integration/v3';
import apiError from '../../../../../website/server/libs/apiError';
describe('GET /coupons/', () => {
let user;
before(async () => {
await resetHabiticaDB();
});
beforeEach(async () => {
user = await generateUser();
});
it('returns an error if user has no coupons permission', async () => {
await user.get('/user'); // needed so the request after this will authenticate with the correct cookie session
await expect(user.get('/coupons')).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: apiError('noPrivAccess'),
});
});
it('should return the coupons in CSV format ordered by creation date', async () => {
await user.updateOne({
'permissions.coupons': true,
});
const coupons = await user.post('/coupons/generate/wondercon?count=11');
const res = await user.get('/coupons');
const splitRes = res.split('\n');
expect(splitRes.length).to.equal(13);
expect(splitRes[0]).to.equal('code,event,date,user');
expect(splitRes[6].split(',')[1]).to.equal(coupons[5].event);
});
});