mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
tests for user data export
This commit is contained in:
@@ -151,7 +151,8 @@
|
||||
"superagent-defaults": "^0.1.13",
|
||||
"uuid": "^2.0.1",
|
||||
"vinyl-source-stream": "^1.0.0",
|
||||
"vinyl-transform": "^1.0.0"
|
||||
"vinyl-transform": "^1.0.0",
|
||||
"xml2js": "^0.4.16"
|
||||
},
|
||||
"apidoc": {
|
||||
"name": "habitica",
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from '../../../../helpers/mongo';
|
||||
import moment from 'moment';
|
||||
|
||||
describe.only('GET /export/history.csv', () => {
|
||||
describe('GET /export/history.csv', () => {
|
||||
it('should return a valid CSV file with tasks history data', async () => {
|
||||
let user = await generateUser();
|
||||
let tasks = await user.post('/tasks/user', [
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
// TODO how to test this route since it uses session authentication?
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../../../helpers/api-v3-integration.helper';
|
||||
|
||||
describe('GET /export/userdata.json', () => {});
|
||||
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'},
|
||||
]);
|
||||
|
||||
let 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']);
|
||||
expect(res.tasks).to.have.all.keys(['dailys', 'habits', 'todos', 'rewards']);
|
||||
expect(res.tasks.habits.length).to.equal(1);
|
||||
expect(res.tasks.habits[0]._id).to.equal(tasks[0]._id);
|
||||
expect(res.tasks.dailys.length).to.equal(1);
|
||||
expect(res.tasks.dailys[0]._id).to.equal(tasks[1]._id);
|
||||
expect(res.tasks.rewards.length).to.equal(1);
|
||||
expect(res.tasks.rewards[0]._id).to.equal(tasks[2]._id);
|
||||
expect(res.tasks.todos.length).to.equal(2);
|
||||
expect(res.tasks.todos[1]._id).to.equal(tasks[3]._id);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,41 @@
|
||||
// TODO how to test this route since it uses session authentication?
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../../../helpers/api-v3-integration.helper';
|
||||
import xml2js from 'xml2js';
|
||||
import Q from 'q';
|
||||
|
||||
describe('GET /export/userdata.xml', () => {});
|
||||
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'},
|
||||
// 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'},
|
||||
|
||||
]);
|
||||
|
||||
let response = await user.get(`/export/userdata.xml`);
|
||||
let {user: res} = await Q.npost(xml2js, 'parseString', [response, {explicitArray: false}]);
|
||||
|
||||
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']);
|
||||
expect(res.tasks).to.have.all.keys(['dailys', 'habits', 'todos', 'rewards']);
|
||||
expect(res.tasks.habits.length).to.equal(2);
|
||||
expect(res.tasks.habits[0]._id).to.equal(tasks[0]._id);
|
||||
expect(res.tasks.dailys.length).to.equal(2);
|
||||
expect(res.tasks.dailys[0]._id).to.equal(tasks[1]._id);
|
||||
expect(res.tasks.rewards.length).to.equal(2);
|
||||
expect(res.tasks.rewards[0]._id).to.equal(tasks[2]._id);
|
||||
expect(res.tasks.todos.length).to.equal(3);
|
||||
expect(res.tasks.todos[1]._id).to.equal(tasks[3]._id);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user