mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
fix test lint
This commit is contained in:
@@ -7,15 +7,15 @@ describe('GET /hall/heroes', () => {
|
||||
it('returns all heroes sorted by -contributor.level and with correct fields', async () => {
|
||||
await resetHabiticaDB();
|
||||
|
||||
let nonHero = await generateUser();
|
||||
let hero1 = await generateUser({
|
||||
contributor: {level: 1},
|
||||
const nonHero = await generateUser();
|
||||
const hero1 = await generateUser({
|
||||
contributor: { level: 1 },
|
||||
});
|
||||
let hero2 = await generateUser({
|
||||
contributor: {level: 3},
|
||||
const hero2 = await generateUser({
|
||||
contributor: { level: 3 },
|
||||
});
|
||||
|
||||
let heroes = await nonHero.get('/hall/heroes');
|
||||
const heroes = await nonHero.get('/hall/heroes');
|
||||
expect(heroes.length).to.equal(2);
|
||||
expect(heroes[0]._id).to.equal(hero2._id);
|
||||
expect(heroes[1]._id).to.equal(hero1._id);
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
|
||||
describe('GET /heroes/:heroId', () => {
|
||||
let user;
|
||||
|
||||
before(async () => {
|
||||
user = await generateUser({
|
||||
contributor: {admin: true},
|
||||
contributor: { admin: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('requires the caller to be an admin', async () => {
|
||||
let nonAdmin = await generateUser();
|
||||
const nonAdmin = await generateUser();
|
||||
|
||||
await expect(nonAdmin.get(`/hall/heroes/${user._id}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
@@ -27,24 +27,24 @@ describe('GET /heroes/:heroId', () => {
|
||||
await expect(user.get('/hall/heroes/invalidUUID')).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userWithIDNotFound', {userId: 'invalidUUID'}),
|
||||
message: t('userWithIDNotFound', { userId: 'invalidUUID' }),
|
||||
});
|
||||
});
|
||||
|
||||
it('handles non-existing heroes', async () => {
|
||||
let dummyId = generateUUID();
|
||||
const dummyId = generateUUID();
|
||||
await expect(user.get(`/hall/heroes/${dummyId}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userWithIDNotFound', {userId: dummyId}),
|
||||
message: t('userWithIDNotFound', { userId: dummyId }),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns only necessary hero data given user id', async () => {
|
||||
let hero = await generateUser({
|
||||
contributor: {tier: 23},
|
||||
const hero = await generateUser({
|
||||
contributor: { tier: 23 },
|
||||
});
|
||||
let heroRes = await user.get(`/hall/heroes/${hero._id}`);
|
||||
const heroRes = await user.get(`/hall/heroes/${hero._id}`);
|
||||
|
||||
expect(heroRes).to.have.all.keys([ // works as: object has all and only these keys
|
||||
'_id', 'id', 'balance', 'profile', 'purchased',
|
||||
@@ -55,10 +55,10 @@ describe('GET /heroes/:heroId', () => {
|
||||
});
|
||||
|
||||
it('returns only necessary hero data given username', async () => {
|
||||
let hero = await generateUser({
|
||||
contributor: {tier: 23},
|
||||
const hero = await generateUser({
|
||||
contributor: { tier: 23 },
|
||||
});
|
||||
let heroRes = await user.get(`/hall/heroes/${hero.auth.local.username}`);
|
||||
const heroRes = await user.get(`/hall/heroes/${hero.auth.local.username}`);
|
||||
|
||||
expect(heroRes).to.have.all.keys([ // works as: object has all and only these keys
|
||||
'_id', 'id', 'balance', 'profile', 'purchased',
|
||||
@@ -70,7 +70,7 @@ describe('GET /heroes/:heroId', () => {
|
||||
|
||||
it('returns correct hero using search with difference case', async () => {
|
||||
await generateUser({}, { username: 'TestUpperCaseName123' });
|
||||
let heroRes = await user.get('/hall/heroes/TestuPPerCasEName123');
|
||||
const heroRes = await user.get('/hall/heroes/TestuPPerCasEName123');
|
||||
expect(heroRes.auth.local.username).to.equal('TestUpperCaseName123');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { times } from 'lodash';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
resetHabiticaDB,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { times } from 'lodash';
|
||||
|
||||
describe('GET /hall/patrons', () => {
|
||||
let user;
|
||||
@@ -22,14 +22,14 @@ describe('GET /hall/patrons', () => {
|
||||
});
|
||||
|
||||
it('returns all patrons sorted by -backer.tier and with correct fields', async () => {
|
||||
let patron1 = await generateUser({
|
||||
backer: {tier: 1},
|
||||
const patron1 = await generateUser({
|
||||
backer: { tier: 1 },
|
||||
});
|
||||
let patron2 = await generateUser({
|
||||
backer: {tier: 3},
|
||||
const patron2 = await generateUser({
|
||||
backer: { tier: 3 },
|
||||
});
|
||||
|
||||
let patrons = await user.get('/hall/patrons');
|
||||
const patrons = await user.get('/hall/patrons');
|
||||
expect(patrons.length).to.equal(2);
|
||||
expect(patrons[0]._id).to.equal(patron2._id);
|
||||
expect(patrons[1]._id).to.equal(patron1._id);
|
||||
@@ -45,14 +45,12 @@ describe('GET /hall/patrons', () => {
|
||||
});
|
||||
|
||||
it('returns only first 50 patrons per request, more if req.query.page is passed', async () => {
|
||||
await Promise.all(times(53, n => {
|
||||
return generateUser({backer: {tier: n}});
|
||||
}));
|
||||
await Promise.all(times(53, n => generateUser({ backer: { tier: n } })));
|
||||
|
||||
let patrons = await user.get('/hall/patrons');
|
||||
const patrons = await user.get('/hall/patrons');
|
||||
expect(patrons.length).to.equal(50);
|
||||
|
||||
let morePatrons = await user.get('/hall/patrons?page=1');
|
||||
const morePatrons = await user.get('/hall/patrons?page=1');
|
||||
expect(morePatrons.length).to.equal(2);
|
||||
expect(morePatrons[0].backer.tier).to.equal(2);
|
||||
expect(morePatrons[1].backer.tier).to.equal(1);
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
|
||||
describe('PUT /heroes/:heroId', () => {
|
||||
let user;
|
||||
|
||||
before(async () => {
|
||||
user = await generateUser({
|
||||
contributor: {admin: true},
|
||||
contributor: { admin: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('requires the caller to be an admin', async () => {
|
||||
let nonAdmin = await generateUser();
|
||||
const nonAdmin = await generateUser();
|
||||
|
||||
await expect(nonAdmin.put(`/hall/heroes/${user._id}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
@@ -32,22 +32,22 @@ describe('PUT /heroes/:heroId', () => {
|
||||
});
|
||||
|
||||
it('handles non-existing heroes', async () => {
|
||||
let dummyId = generateUUID();
|
||||
const dummyId = generateUUID();
|
||||
await expect(user.put(`/hall/heroes/${dummyId}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userWithIDNotFound', {userId: dummyId}),
|
||||
message: t('userWithIDNotFound', { userId: dummyId }),
|
||||
});
|
||||
});
|
||||
|
||||
it('change contributor level, balance, ads', async () => {
|
||||
let hero = await generateUser();
|
||||
let prevBlockState = hero.auth.blocked;
|
||||
let prevSleepState = hero.preferences.sleep;
|
||||
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
const hero = await generateUser();
|
||||
const prevBlockState = hero.auth.blocked;
|
||||
const prevSleepState = hero.preferences.sleep;
|
||||
const heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
balance: 3,
|
||||
contributor: {level: 1},
|
||||
purchased: {ads: true},
|
||||
contributor: { level: 1 },
|
||||
purchased: { ads: true },
|
||||
});
|
||||
|
||||
// test response
|
||||
@@ -74,10 +74,10 @@ describe('PUT /heroes/:heroId', () => {
|
||||
});
|
||||
|
||||
it('block a user', async () => {
|
||||
let hero = await generateUser();
|
||||
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
auth: {blocked: true},
|
||||
preferences: {sleep: true},
|
||||
const hero = await generateUser();
|
||||
const heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
auth: { blocked: true },
|
||||
preferences: { sleep: true },
|
||||
});
|
||||
|
||||
// test response values
|
||||
@@ -89,10 +89,10 @@ describe('PUT /heroes/:heroId', () => {
|
||||
});
|
||||
|
||||
it('unblock a user', async () => {
|
||||
let hero = await generateUser();
|
||||
let prevSleepState = hero.preferences.sleep;
|
||||
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
auth: {blocked: false},
|
||||
const hero = await generateUser();
|
||||
const prevSleepState = hero.preferences.sleep;
|
||||
const heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
auth: { blocked: false },
|
||||
});
|
||||
|
||||
// test response values
|
||||
@@ -104,29 +104,29 @@ describe('PUT /heroes/:heroId', () => {
|
||||
});
|
||||
|
||||
it('updates chatRevoked flag', async () => {
|
||||
let hero = await generateUser();
|
||||
const hero = await generateUser();
|
||||
await user.put(`/hall/heroes/${hero._id}`, {
|
||||
flags: {chatRevoked: true},
|
||||
flags: { chatRevoked: true },
|
||||
});
|
||||
await hero.sync();
|
||||
expect(hero.flags.chatRevoked).to.eql(true);
|
||||
});
|
||||
|
||||
it('updates chatShadowMuted flag', async () => {
|
||||
let hero = await generateUser();
|
||||
const hero = await generateUser();
|
||||
await user.put(`/hall/heroes/${hero._id}`, {
|
||||
flags: {chatShadowMuted: true},
|
||||
flags: { chatShadowMuted: true },
|
||||
});
|
||||
await hero.sync();
|
||||
expect(hero.flags.chatShadowMuted).to.eql(true);
|
||||
});
|
||||
|
||||
it('updates contributor level', async () => {
|
||||
let hero = await generateUser({
|
||||
contributor: {level: 5},
|
||||
const hero = await generateUser({
|
||||
contributor: { level: 5 },
|
||||
});
|
||||
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
contributor: {level: 6},
|
||||
const heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
contributor: { level: 6 },
|
||||
});
|
||||
|
||||
// test response
|
||||
@@ -149,11 +149,11 @@ describe('PUT /heroes/:heroId', () => {
|
||||
});
|
||||
|
||||
it('updates contributor data', async () => {
|
||||
let hero = await generateUser({
|
||||
contributor: {level: 5},
|
||||
const hero = await generateUser({
|
||||
contributor: { level: 5 },
|
||||
});
|
||||
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
contributor: {text: 'Astronaut'},
|
||||
const heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
contributor: { text: 'Astronaut' },
|
||||
});
|
||||
|
||||
// test response
|
||||
@@ -174,8 +174,8 @@ describe('PUT /heroes/:heroId', () => {
|
||||
});
|
||||
|
||||
it('updates items', async () => {
|
||||
let hero = await generateUser();
|
||||
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
const hero = await generateUser();
|
||||
const heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||
itemPath: 'items.special.snowball',
|
||||
itemVal: 5,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user