fix(dataexport) - 12482 - Extract xml marshalling into library

- Add integration test on dataexport endpoint
- Add library with unit test for xml marshalling
This commit is contained in:
Bart Enkelaar
2020-09-25 08:55:28 +02:00
parent 8b9c76a2b7
commit 6e91326648
5 changed files with 505 additions and 115 deletions

View File

@@ -0,0 +1,32 @@
import _ from 'lodash';
import * as js2xml from 'js2xmlparser';
export function marshallUserData (userData) {
// object maps can't be marshalled to XML
userData.inbox.messages = _(userData.inbox.messages)
.map(m => {
m.flags = Object.keys(m.flags);
return m;
})
.value();
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,
}));
userData.pinnedItems = userData.pinnedItems.map(i => ({
path: i.path,
type: i.type,
}));
return js2xml.parse('user', userData, {
cdataInvalidChars: true,
declaration: {
include: false,
},
});
}