Skip to content

Commit 9350a18

Browse files
davimacedoRafael Santos
authored andcommitted
Endpoints for importing and exporting data
1 parent aa071e0 commit 9350a18

File tree

12 files changed

+1052
-8
lines changed

12 files changed

+1052
-8
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
],
1919
"license": "BSD-3-Clause",
2020
"dependencies": {
21+
"adm-zip": "0.4.7",
22+
"archiver": "^1.2.0",
2123
"bcryptjs": "2.3.0",
2224
"body-parser": "1.15.2",
2325
"commander": "2.9.0",
@@ -38,12 +40,14 @@
3840
"redis": "2.6.3",
3941
"request": "2.79.0",
4042
"semver": "5.2.0",
43+
"tmp": "0.0.31",
4144
"tv4": "1.2.7",
4245
"winston": "2.3.0",
4346
"winston-daily-rotate-file": "1.4.0",
4447
"ws": "1.1.1"
4548
},
4649
"devDependencies": {
50+
"adm-zip": "^0.4.7",
4751
"babel-cli": "6.18.0",
4852
"babel-core": "6.18.2",
4953
"babel-eslint": "^7.1.1",

spec/ExportRouter.spec.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
const Parse = require("parse/node");
2+
const request = require('request');
3+
const AdmZip = require('adm-zip');
4+
5+
describe('Export router', () => {
6+
7+
const headers = {
8+
'Content-Type': 'application/json',
9+
'X-Parse-Application-Id': 'test',
10+
'X-Parse-Master-Key': 'test'
11+
};
12+
13+
const createRecords = (itemCount) => {
14+
const ExportTest = Parse.Object.extend("ExportTest");
15+
16+
const items = new Array(itemCount).fill().map((item, index) => {
17+
18+
const exportTest = new ExportTest();
19+
20+
exportTest.set('field1', `value1-${index}`);
21+
exportTest.set('field2', `value2-${index}`);
22+
23+
return exportTest;
24+
});
25+
26+
27+
return Parse.Object.saveAll(items);
28+
};
29+
30+
it_exclude_dbs(['postgres'])('should create export progress', (done) => {
31+
32+
reconfigureServer({
33+
emailAdapter : {
34+
sendMail : () => {
35+
done();
36+
}
37+
}
38+
})
39+
.then(() => {
40+
return createRecords(3000);
41+
})
42+
.then(() => {
43+
request.put(
44+
{
45+
headers: headers,
46+
url: 'http://localhost:8378/1/export_data',
47+
body: JSON.stringify({
48+
name: 'ExportTest',
49+
feedbackEmail: '[email protected]'
50+
})
51+
},
52+
() => {
53+
54+
request.get(
55+
{
56+
headers: headers,
57+
url: 'http://localhost:8378/1/export_progress'
58+
},
59+
(err, response, body) => {
60+
61+
const progress = JSON.parse(body);
62+
63+
expect(progress instanceof Array).toBe(true);
64+
expect(progress.length).toBe(1);
65+
66+
if (progress.length) {
67+
expect(progress[0].id).toBe('ExportTest');
68+
}
69+
70+
});
71+
}
72+
);
73+
}
74+
);
75+
});
76+
77+
it_exclude_dbs(['postgres'])('send success export mail', (done) => {
78+
79+
let results = [];
80+
81+
const emailAdapter = {
82+
sendMail: ({ link, to, subject}) => {
83+
84+
expect(to).toEqual('[email protected]');
85+
expect(subject).toEqual('Export completed');
86+
87+
request.get({ url: link, encoding: null }, function(err, res, zipFile) {
88+
89+
if(err) throw err;
90+
91+
const zip = new AdmZip(zipFile);
92+
const zipEntries = zip.getEntries();
93+
94+
expect(zipEntries.length).toEqual(1);
95+
96+
const entry = zipEntries.pop();
97+
const text = entry.getData().toString('utf8');
98+
const resultsToCompare = JSON.parse(text);
99+
100+
expect(results.length).toEqual(resultsToCompare.length);
101+
102+
done();
103+
});
104+
}
105+
}
106+
reconfigureServer({
107+
emailAdapter: emailAdapter
108+
})
109+
.then(() => {
110+
return createRecords(2176);
111+
})
112+
.then(() => {
113+
request.get(
114+
{
115+
headers: headers,
116+
url: 'http://localhost:8378/1/classes/ExportTest',
117+
},
118+
(err, response, body) => {
119+
results = JSON.parse(body);
120+
121+
request.put(
122+
{
123+
headers: headers,
124+
url: 'http://localhost:8378/1/export_data',
125+
body: JSON.stringify({
126+
name: 'ExportTest',
127+
feedbackEmail: '[email protected]'
128+
})
129+
},
130+
(err, response, body) => {
131+
expect(err).toBe(null);
132+
expect(body).toEqual('"We are exporting your data. You will be notified by e-mail once it is completed."');
133+
}
134+
);
135+
}
136+
);
137+
});
138+
});
139+
});

0 commit comments

Comments
 (0)