mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
fix test lint
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
|
||||
xdescribe('GET /export/avatar-:memberId.html', () => {
|
||||
let user;
|
||||
@@ -20,16 +20,16 @@ xdescribe('GET /export/avatar-:memberId.html', () => {
|
||||
});
|
||||
|
||||
it('handles non-existing members', async () => {
|
||||
let dummyId = generateUUID();
|
||||
const dummyId = generateUUID();
|
||||
await expect(user.get(`/export/avatar-${dummyId}.html`)).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userWithIDNotFound', {userId: dummyId}),
|
||||
message: t('userWithIDNotFound', { userId: dummyId }),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an html page', async () => {
|
||||
let res = await user.get(`/export/avatar-${user._id}.html`);
|
||||
const res = await user.get(`/export/avatar-${user._id}.html`);
|
||||
expect(res.substring(0, 100).indexOf('<!DOCTYPE html>')).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
import moment from 'moment';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import {
|
||||
updateDocument,
|
||||
} from '../../../../helpers/mongo';
|
||||
import moment from 'moment';
|
||||
|
||||
describe('GET /export/history.csv', () => {
|
||||
// TODO disabled because it randomly causes the build to fail
|
||||
xit('should return a valid CSV file with tasks history data', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
let tasks = await user.post('/tasks/user', [
|
||||
{type: 'daily', text: 'daily 1'},
|
||||
{type: 'habit', text: 'habit 1'},
|
||||
{type: 'habit', text: 'habit 2'},
|
||||
{type: 'todo', text: 'todo 1'},
|
||||
{ type: 'daily', text: 'daily 1' },
|
||||
{ type: 'habit', text: 'habit 1' },
|
||||
{ type: 'habit', text: 'habit 2' },
|
||||
{ type: 'todo', text: 'todo 1' },
|
||||
]);
|
||||
|
||||
// to handle occasional inconsistency in task creation order
|
||||
tasks.sort(function (a, b) {
|
||||
return a.text.localeCompare(b.text);
|
||||
});
|
||||
tasks.sort((a, b) => a.text.localeCompare(b.text));
|
||||
|
||||
// score all the tasks twice
|
||||
await user.post(`/tasks/${tasks[0]._id}/score/up`);
|
||||
@@ -35,16 +33,14 @@ describe('GET /export/history.csv', () => {
|
||||
|
||||
// adding an history entry to daily 1 manually because cron didn't run yet
|
||||
await updateDocument('tasks', tasks[0], {
|
||||
history: [{value: 3.2, date: Number(new Date())}],
|
||||
history: [{ value: 3.2, date: Number(new Date()) }],
|
||||
});
|
||||
|
||||
// get updated tasks
|
||||
tasks = await Promise.all(tasks.map(task => {
|
||||
return user.get(`/tasks/${task._id}`);
|
||||
}));
|
||||
tasks = await Promise.all(tasks.map(task => user.get(`/tasks/${task._id}`)));
|
||||
|
||||
let res = await user.get('/export/history.csv');
|
||||
let splitRes = res.split('\n');
|
||||
const res = await user.get('/export/history.csv');
|
||||
const splitRes = res.split('\n');
|
||||
|
||||
expect(splitRes[0]).to.equal('Task Name,Task ID,Task Type,Date,Value');
|
||||
expect(splitRes[1]).to.equal(`daily 1,${tasks[0]._id},daily,${moment(tasks[0].history[0].date).format('YYYY-MM-DD HH:mm:ss')},${tasks[0].history[0].value}`);
|
||||
|
||||
@@ -6,7 +6,7 @@ describe('GET /export/inbox.html', () => {
|
||||
let user;
|
||||
|
||||
before(async () => {
|
||||
let otherUser = await generateUser({
|
||||
const otherUser = await generateUser({
|
||||
'profile.name': 'Other User',
|
||||
});
|
||||
user = await generateUser({
|
||||
@@ -30,13 +30,13 @@ describe('GET /export/inbox.html', () => {
|
||||
});
|
||||
|
||||
it('returns an html page', async () => {
|
||||
let res = await user.get('/export/inbox.html');
|
||||
const res = await user.get('/export/inbox.html');
|
||||
|
||||
expect(res.substring(0, 100).indexOf('<!DOCTYPE html>')).to.equal(0);
|
||||
});
|
||||
|
||||
it('renders the markdown messages as html', async () => {
|
||||
let res = await user.get('/export/inbox.html');
|
||||
const res = await user.get('/export/inbox.html');
|
||||
|
||||
expect(res).to.include('img class="habitica-emoji"');
|
||||
expect(res).to.include('<h1>Hello!</h1>');
|
||||
@@ -44,11 +44,11 @@ describe('GET /export/inbox.html', () => {
|
||||
});
|
||||
|
||||
it('sorts messages from newest to oldest', async () => {
|
||||
let res = await user.get('/export/inbox.html');
|
||||
const res = await user.get('/export/inbox.html');
|
||||
|
||||
let emojiPosition = res.indexOf('img class="habitica-emoji"');
|
||||
let headingPosition = res.indexOf('<h1>Hello!</h1>');
|
||||
let listPosition = res.indexOf('<li>list 1</li>');
|
||||
const emojiPosition = res.indexOf('img class="habitica-emoji"');
|
||||
const headingPosition = res.indexOf('<h1>Hello!</h1>');
|
||||
const listPosition = res.indexOf('<li>list 1</li>');
|
||||
|
||||
expect(emojiPosition).to.be.greaterThan(headingPosition);
|
||||
expect(headingPosition).to.be.greaterThan(listPosition);
|
||||
|
||||
@@ -4,15 +4,15 @@ import {
|
||||
|
||||
describe('GET /export/userdata.json', () => {
|
||||
it('should return a valid JSON file with user data', async () => {
|
||||
let user = await generateUser();
|
||||
let tasks = await user.post('/tasks/user', [
|
||||
{type: 'habit', text: 'habit 1'},
|
||||
{type: 'daily', text: 'daily 1'},
|
||||
{type: 'reward', text: 'reward 1'},
|
||||
{type: 'todo', text: 'todo 1'},
|
||||
const user = await generateUser();
|
||||
const tasks = await user.post('/tasks/user', [
|
||||
{ type: 'habit', text: 'habit 1' },
|
||||
{ type: 'daily', text: 'daily 1' },
|
||||
{ type: 'reward', text: 'reward 1' },
|
||||
{ type: 'todo', text: 'todo 1' },
|
||||
]);
|
||||
|
||||
let res = await user.get('/export/userdata.json');
|
||||
const res = await user.get('/export/userdata.json');
|
||||
expect(res._id).to.equal(user._id);
|
||||
expect(res).to.contain.all.keys(['tasks', 'flags', 'tasksOrder', 'auth']);
|
||||
expect(res.auth.local).not.to.have.keys(['salt', 'hashed_password']);
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import xml2js from 'xml2js';
|
||||
import util from 'util';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import xml2js from 'xml2js';
|
||||
import util from 'util';
|
||||
|
||||
let parseStringAsync = util.promisify(xml2js.parseString).bind(xml2js);
|
||||
const parseStringAsync = util.promisify(xml2js.parseString).bind(xml2js);
|
||||
|
||||
describe('GET /export/userdata.xml', () => {
|
||||
it('should return a valid XML file with user data', async () => {
|
||||
let user = await generateUser();
|
||||
let tasks = await user.post('/tasks/user', [
|
||||
{type: 'habit', text: 'habit 1'},
|
||||
{type: 'daily', text: 'daily 1'},
|
||||
{type: 'reward', text: 'reward 1'},
|
||||
{type: 'todo', text: 'todo 1'},
|
||||
const user = await generateUser();
|
||||
const tasks = await user.post('/tasks/user', [
|
||||
{ type: 'habit', text: 'habit 1' },
|
||||
{ type: 'daily', text: 'daily 1' },
|
||||
{ type: 'reward', text: 'reward 1' },
|
||||
{ type: 'todo', text: 'todo 1' },
|
||||
// due to how the xml parser works an array is returned only if there's more than one children
|
||||
// so we create two tasks for each type
|
||||
{type: 'habit', text: 'habit 2'},
|
||||
{type: 'daily', text: 'daily 2'},
|
||||
{type: 'reward', text: 'reward 2'},
|
||||
{type: 'todo', text: 'todo 2'},
|
||||
{ type: 'habit', text: 'habit 2' },
|
||||
{ type: 'daily', text: 'daily 2' },
|
||||
{ type: 'reward', text: 'reward 2' },
|
||||
{ type: 'todo', text: 'todo 2' },
|
||||
|
||||
]);
|
||||
|
||||
@@ -27,15 +27,15 @@ describe('GET /export/userdata.xml', () => {
|
||||
await user.get('/user/toggle-pinned-item/marketGear/gear.flat.shield_rogue_5');
|
||||
|
||||
// add a private message
|
||||
let receiver = await generateUser();
|
||||
const receiver = await generateUser();
|
||||
|
||||
user.post('/members/send-private-message', {
|
||||
message: 'Your first message, hi!',
|
||||
toUserId: receiver._id,
|
||||
});
|
||||
|
||||
let response = await user.get('/export/userdata.xml');
|
||||
let {user: res} = await parseStringAsync(response, {explicitArray: false});
|
||||
const response = await user.get('/export/userdata.xml');
|
||||
const { user: res } = await parseStringAsync(response, { explicitArray: false });
|
||||
|
||||
expect(res._id).to.equal(user._id);
|
||||
expect(res).to.contain.all.keys(['tasks', 'flags', 'tasksOrder', 'auth']);
|
||||
@@ -43,19 +43,19 @@ describe('GET /export/userdata.xml', () => {
|
||||
expect(res.tasks).to.have.all.keys(['dailys', 'habits', 'todos', 'rewards']);
|
||||
|
||||
expect(res.tasks.habits.length).to.equal(2);
|
||||
let habitIds = _.map(res.tasks.habits, '_id');
|
||||
const habitIds = _.map(res.tasks.habits, '_id');
|
||||
expect(habitIds).to.have.deep.members([tasks[0]._id, tasks[4]._id]);
|
||||
|
||||
expect(res.tasks.dailys.length).to.equal(2);
|
||||
let dailyIds = _.map(res.tasks.dailys, '_id');
|
||||
const dailyIds = _.map(res.tasks.dailys, '_id');
|
||||
expect(dailyIds).to.have.deep.members([tasks[1]._id, tasks[5]._id]);
|
||||
|
||||
expect(res.tasks.rewards.length).to.equal(2);
|
||||
let rewardIds = _.map(res.tasks.rewards, '_id');
|
||||
const rewardIds = _.map(res.tasks.rewards, '_id');
|
||||
expect(rewardIds).to.have.deep.members([tasks[2]._id, tasks[6]._id]);
|
||||
|
||||
expect(res.tasks.todos.length).to.equal(3);
|
||||
let todoIds = _.map(res.tasks.todos, '_id');
|
||||
const todoIds = _.map(res.tasks.todos, '_id');
|
||||
expect(todoIds).to.deep.include.members([tasks[3]._id, tasks[7]._id]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user