Skip to content

Commit 31a3f2d

Browse files
authored
Merge pull request #24 from sonnenkern/develop
Develop
2 parents 688fb25 + 109f73a commit 31a3f2d

6 files changed

+25
-13
lines changed

lib/QuipProcessor.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,18 @@ class QuipProcessor {
261261
threadId: quipThread.thread.id,
262262
blobId: file.hash
263263
};
264-
265-
if(Mime.getType(file.name).startsWith('image/')) {
264+
const mimeType = Mime.getType(file.name);
265+
if(mimeType && mimeType.startsWith('image/')) {
266266
//image
267267
const imageHtml = `<br/><img class='message--image' src='RELATIVE_PATH'></img><br/>`;
268268
text += await this._processFile(imageHtml, fileMatch, path, this.options.embeddedImages);
269269
} else {
270270
//file
271-
const fileHtml = `<br/><a href="RELATIVE_PATH">${file.name}</a><br/>`;
271+
let fileName = file.name;
272+
if(!fileName) {
273+
fileName = file.hash;
274+
}
275+
const fileHtml = `<br/><a href="RELATIVE_PATH">${fileName}</a><br/>`;
272276
text += await this._processFile(fileHtml, fileMatch, path);
273277
}
274278

lib/__tests__/QuipProcessor.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,10 @@ describe('methods tests', () => {
903903

904904
quipProcessor._processFile = jest.fn();
905905
quipProcessor._processFile.mockImplementation((html, fileMatch) => {
906-
if(fileMatch.blobId === '1c2EXOl1sx04g5_hPNmt1A') {
907-
return Promise.resolve(html + 'PROCESSED-FILE');
908-
}
909-
if(fileMatch.blobId === 'sVhMwHaxsgiwmfMi4au1Zg') {
906+
if(['1c2EXOl1sx04g5_hPNmt1A',
907+
'sVhMwHaxsgiwmfMi4au1Zg',
908+
'1c2EXOl1sx04g5_hPNmt1A222',
909+
'sVhMwHaxsgiwmfMi4au1Zg111'].includes(fileMatch.blobId)) {
910910
return Promise.resolve(html + 'PROCESSED-FILE');
911911
}
912912
if(fileMatch.blobId === 'Ak5BJnkWubPxpIm4dtlWmg') {

lib/__tests__/QuipService.test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,25 @@ response200Blob.blob = jest.fn(() => blob);
3131

3232
const quipService = new QuipService('###TOKEN###', 'http://quip.com');
3333

34+
beforeEach(() => {
35+
quipService.stats.query_count = 0;
36+
quipService.querries503 = new Map();
37+
});
38+
3439
test('constructor tests', async () => {
3540
expect(quipService.accessToken).toBe('###TOKEN###');
3641
expect(quipService.apiURL).toBe('http://quip.com');
3742
expect(quipService.logger).toBeInstanceOf(LoggerAdapter);
3843
});
3944

4045
test('_apiCall response with 503 code', async () => {
41-
quipService.stats.query_count = 0;
4246
fetch.mockReturnValue(Promise.resolve(response200)).mockReturnValueOnce(Promise.resolve(response503));
4347
const res = await quipService._apiCall('/someURL');
4448
expect(res.data).toBe(123456);
4549
expect(quipService.stats.query_count).toBe(2);
4650
});
4751

4852
test('_apiCall response with 503 code more than 10 times', async () => {
49-
quipService.stats.query_count = 0;
5053
fetch.mockReturnValue(Promise.resolve(response503));
5154
const res = await quipService._apiCall('/someURL');
5255
expect(res).toBe(undefined);
@@ -69,15 +72,13 @@ test('_apiCall: fetch with exeption', async () => {
6972
});
7073

7174
test('_apiCallBlob response with 503 code', async () => {
72-
quipService.stats.query_count = 0;
7375
fetch.mockReturnValue(Promise.resolve(response200Blob)).mockReturnValueOnce(Promise.resolve(response503));
7476
const res = await quipService._apiCallBlob('/someURL');
7577
expect(res).toBe(blob);
7678
expect(quipService.stats.query_count).toBe(2);
7779
});
7880

7981
test('_apiCallBlob response with 503 code more than 10 times', async () => {
80-
quipService.stats.query_count = 0;
8182
fetch.mockReturnValue(Promise.resolve(response503));
8283
const res = await quipService._apiCallBlob('/someURL');
8384
expect(res).toBe(undefined);

lib/__tests__/__snapshots__/QuipProcessor.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ exports[`methods tests _getThreadMessagesHtml thread with messages 1`] = `
66
<div class=\\"message\\"><span class=\\"message--user\\">Heller Stern, 8 May 2020, 09:19<br/></span>Message with thread link <a href=\\"RELATIVE_PATH\\">Document-1</a>PROCESSED-THREAD</div>
77
<div class=\\"message\\"><span class=\\"message--user\\">Heller Stern, 8 May 2020, 09:20<br/></span>Message with person-link <span class=\\"message--user\\">@Alex</span></div>
88
<div class=\\"message\\"><span class=\\"message--user\\">Heller Stern, 8 May 2020, 09:20<br/></span><br/><img class='message--image' src='RELATIVE_PATH'></img><br/>PROCESSED-IMAGE<br/></div>
9-
<div class=\\"message\\"><span class=\\"message--user\\">Heller Stern, 25 May 2020, 20:21<br/></span>444444<br/><a href=\\"RELATIVE_PATH\\">document1.html</a><br/>PROCESSED-FILE<br/><br/><a href=\\"RELATIVE_PATH\\">document1.pdf</a><br/>PROCESSED-FILE<br/></div></div>"
9+
<div class=\\"message\\"><span class=\\"message--user\\">Heller Stern, 25 May 2020, 20:21<br/></span>444444<br/><a href=\\"RELATIVE_PATH\\">document1.html</a><br/>PROCESSED-FILE<br/><br/><a href=\\"RELATIVE_PATH\\">document1.pdf</a><br/>PROCESSED-FILE<br/><br/><a href=\\"RELATIVE_PATH\\">document_unknown_type</a><br/>PROCESSED-FILE<br/><br/><a href=\\"RELATIVE_PATH\\">sVhMwHaxsgiwmfMi4au1Zg111</a><br/>PROCESSED-FILE<br/></div></div>"
1010
`;

lib/__tests__/messages.json

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
{
4949
"name": "document1.pdf",
5050
"hash": "sVhMwHaxsgiwmfMi4au1Zg"
51+
},
52+
{
53+
"name": "document_unknown_type",
54+
"hash": "1c2EXOl1sx04g5_hPNmt1A222"
55+
},
56+
{
57+
"hash": "sVhMwHaxsgiwmfMi4au1Zg111"
5158
}
5259
],
5360
"author_name": "Heller Stern"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quip-export",
3-
"version": "2.2.2",
3+
"version": "2.2.3",
44
"description": "Export all folders and documents from Quip",
55
"main": "index.js",
66
"jest": {

0 commit comments

Comments
 (0)