mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
fix(export) - Issue 12482 - Fix messages in xml export.
This commit is contained in:
79
test/api/unit/top-level/dataexport.test.js
Normal file
79
test/api/unit/top-level/dataexport.test.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import dataexport from '../../../../website/server/controllers/top-level/dataexport';
|
||||
|
||||
import * as Tasks from '../../../../website/server/models/task';
|
||||
import * as inboxLib from '../../../../website/server/libs/inbox';
|
||||
|
||||
describe('xml export', async () => {
|
||||
let exported;
|
||||
|
||||
const user = {
|
||||
toJSON () {
|
||||
return {
|
||||
newMessages: {
|
||||
'283171a5-422c-4991-bc78-95b1b5b51629': {
|
||||
name: 'The Language Hackers',
|
||||
value: true,
|
||||
},
|
||||
'283171a6-422c-4991-bc78-95b1b5b51629': {
|
||||
name: 'The Bug Hackers',
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
inbox: {},
|
||||
pinnedItems: [],
|
||||
unpinnedItems: [],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const response = {
|
||||
locals: { user },
|
||||
set () {},
|
||||
status: () => ({
|
||||
send: data => {
|
||||
exported = data;
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
const tasks = [{
|
||||
toJSON: () => ({ a: 'b', type: 'c' }),
|
||||
}];
|
||||
const messages = [{ flags: { content: 'message' } }];
|
||||
|
||||
sinon.stub(Tasks.Task, 'find').returns({ exec: async () => tasks });
|
||||
sinon.stub(inboxLib, 'getUserInbox').resolves(messages);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('maps the newMessages field to have id as a value in a list.', async () => {
|
||||
await dataexport.exportUserDataXml.handler({}, response);
|
||||
expect(exported).to.equal(`<user>
|
||||
<newMessages>
|
||||
<id>283171a5-422c-4991-bc78-95b1b5b51629</id>
|
||||
<name>The Language Hackers</name>
|
||||
<value>true</value>
|
||||
</newMessages>
|
||||
<newMessages>
|
||||
<id>283171a6-422c-4991-bc78-95b1b5b51629</id>
|
||||
<name>The Bug Hackers</name>
|
||||
<value>false</value>
|
||||
</newMessages>
|
||||
<inbox>
|
||||
<messages>
|
||||
<flags>content</flags>
|
||||
</messages>
|
||||
</inbox>
|
||||
<tasks>
|
||||
<cs>
|
||||
<a>b</a>
|
||||
<type>c</type>
|
||||
</cs>
|
||||
</tasks>
|
||||
</user>`);
|
||||
});
|
||||
});
|
||||
@@ -112,14 +112,15 @@ async function _getUserDataForExport (user, xmlMode = false) {
|
||||
// object maps cant be parsed
|
||||
userData.inbox.messages = _(userData.inbox.messages)
|
||||
.map(m => {
|
||||
const flags = Object.keys(m.flags);
|
||||
m.flags = flags;
|
||||
m.flags = Object.keys(m.flags);
|
||||
|
||||
return m;
|
||||
})
|
||||
.value();
|
||||
|
||||
// _id gets parsed as an bytearray => which gets casted to a chararray => "weird chars"
|
||||
userData.newMessages = _.map(userData.newMessages, (msg, id) => ({ id, ...msg }));
|
||||
|
||||
// _id gets parsed as a bytearray => which gets cast to a chararray => "weird chars"
|
||||
userData.unpinnedItems = userData.unpinnedItems.map(i => ({
|
||||
path: i.path,
|
||||
type: i.type,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import mongoose from 'mongoose';
|
||||
import { Schema } from 'mongoose';
|
||||
import validator from 'validator';
|
||||
import shared from '../../../common';
|
||||
import { // eslint-disable-line import/no-cycle
|
||||
@@ -10,8 +10,6 @@ import { schema as TagSchema } from '../tag';
|
||||
import { schema as UserNotificationSchema } from '../userNotification';
|
||||
import { schema as WebhookSchema } from '../webhook';
|
||||
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const RESTRICTED_EMAIL_DOMAINS = Object.freeze(['habitica.com', 'habitrpg.com']);
|
||||
|
||||
// User schema definition
|
||||
|
||||
Reference in New Issue
Block a user