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
+44
View File
@@ -0,0 +1,44 @@
import * as xmlMarshaller from '../../../../website/server/libs/xmlMarshaller';
describe('xml marshaller marshalls user data', () => {
const minimumUser = {
pinnedItems: [],
unpinnedItems: [],
inbox: {},
};
function userDataWith (fields) {
return { ...minimumUser, ...fields };
}
it('maps the newMessages field to have id as a value in a list.', () => {
const userData = userDataWith({
newMessages: {
'283171a5-422c-4991-bc78-95b1b5b51629': {
name: 'The Language Hackers',
value: true,
},
'283171a6-422c-4991-bc78-95b1b5b51629': {
name: 'The Bug Hackers',
value: false,
},
},
});
const xml = xmlMarshaller.marshallUserData(userData);
expect(xml).to.equal(`<user>
<inbox/>
<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>
</user>`);
});
});
@@ -1,79 +0,0 @@
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>`);
});
});