diff --git a/lib/QuipProcessor.js b/lib/QuipProcessor.js index dd5283e..1277cff 100644 --- a/lib/QuipProcessor.js +++ b/lib/QuipProcessor.js @@ -261,14 +261,18 @@ class QuipProcessor { threadId: quipThread.thread.id, blobId: file.hash }; - - if(Mime.getType(file.name).startsWith('image/')) { + const mimeType = Mime.getType(file.name); + if(mimeType && mimeType.startsWith('image/')) { //image const imageHtml = `

`; text += await this._processFile(imageHtml, fileMatch, path, this.options.embeddedImages); } else { //file - const fileHtml = `
${file.name}
`; + let fileName = file.name; + if(!fileName) { + fileName = file.hash; + } + const fileHtml = `
${fileName}
`; text += await this._processFile(fileHtml, fileMatch, path); } diff --git a/lib/__tests__/QuipProcessor.test.js b/lib/__tests__/QuipProcessor.test.js index 7f874e4..034917a 100644 --- a/lib/__tests__/QuipProcessor.test.js +++ b/lib/__tests__/QuipProcessor.test.js @@ -903,10 +903,10 @@ describe('methods tests', () => { quipProcessor._processFile = jest.fn(); quipProcessor._processFile.mockImplementation((html, fileMatch) => { - if(fileMatch.blobId === '1c2EXOl1sx04g5_hPNmt1A') { - return Promise.resolve(html + 'PROCESSED-FILE'); - } - if(fileMatch.blobId === 'sVhMwHaxsgiwmfMi4au1Zg') { + if(['1c2EXOl1sx04g5_hPNmt1A', + 'sVhMwHaxsgiwmfMi4au1Zg', + '1c2EXOl1sx04g5_hPNmt1A222', + 'sVhMwHaxsgiwmfMi4au1Zg111'].includes(fileMatch.blobId)) { return Promise.resolve(html + 'PROCESSED-FILE'); } if(fileMatch.blobId === 'Ak5BJnkWubPxpIm4dtlWmg') { diff --git a/lib/__tests__/QuipService.test.js b/lib/__tests__/QuipService.test.js index 1169c72..617ddcd 100644 --- a/lib/__tests__/QuipService.test.js +++ b/lib/__tests__/QuipService.test.js @@ -31,6 +31,11 @@ response200Blob.blob = jest.fn(() => blob); const quipService = new QuipService('###TOKEN###', 'http://quip.com'); +beforeEach(() => { + quipService.stats.query_count = 0; + quipService.querries503 = new Map(); +}); + test('constructor tests', async () => { expect(quipService.accessToken).toBe('###TOKEN###'); expect(quipService.apiURL).toBe('http://quip.com'); @@ -38,7 +43,6 @@ test('constructor tests', async () => { }); test('_apiCall response with 503 code', async () => { - quipService.stats.query_count = 0; fetch.mockReturnValue(Promise.resolve(response200)).mockReturnValueOnce(Promise.resolve(response503)); const res = await quipService._apiCall('/someURL'); expect(res.data).toBe(123456); @@ -46,7 +50,6 @@ test('_apiCall response with 503 code', async () => { }); test('_apiCall response with 503 code more than 10 times', async () => { - quipService.stats.query_count = 0; fetch.mockReturnValue(Promise.resolve(response503)); const res = await quipService._apiCall('/someURL'); expect(res).toBe(undefined); @@ -69,7 +72,6 @@ test('_apiCall: fetch with exeption', async () => { }); test('_apiCallBlob response with 503 code', async () => { - quipService.stats.query_count = 0; fetch.mockReturnValue(Promise.resolve(response200Blob)).mockReturnValueOnce(Promise.resolve(response503)); const res = await quipService._apiCallBlob('/someURL'); expect(res).toBe(blob); @@ -77,7 +79,6 @@ test('_apiCallBlob response with 503 code', async () => { }); test('_apiCallBlob response with 503 code more than 10 times', async () => { - quipService.stats.query_count = 0; fetch.mockReturnValue(Promise.resolve(response503)); const res = await quipService._apiCallBlob('/someURL'); expect(res).toBe(undefined); diff --git a/lib/__tests__/__snapshots__/QuipProcessor.test.js.snap b/lib/__tests__/__snapshots__/QuipProcessor.test.js.snap index 3b0bc2b..4c48f20 100644 --- a/lib/__tests__/__snapshots__/QuipProcessor.test.js.snap +++ b/lib/__tests__/__snapshots__/QuipProcessor.test.js.snap @@ -6,5 +6,5 @@ exports[`methods tests _getThreadMessagesHtml thread with messages 1`] = `
Heller Stern, 8 May 2020, 09:19
Message with thread link Document-1PROCESSED-THREAD
Heller Stern, 8 May 2020, 09:20
Message with person-link @Alex
Heller Stern, 8 May 2020, 09:20


PROCESSED-IMAGE
-
Heller Stern, 25 May 2020, 20:21
444444
document1.html
PROCESSED-FILE

document1.pdf
PROCESSED-FILE
" +
Heller Stern, 25 May 2020, 20:21
444444
document1.html
PROCESSED-FILE

document1.pdf
PROCESSED-FILE

document_unknown_type
PROCESSED-FILE

sVhMwHaxsgiwmfMi4au1Zg111
PROCESSED-FILE
" `; diff --git a/lib/__tests__/messages.json b/lib/__tests__/messages.json index e9f77bd..fcb4f87 100644 --- a/lib/__tests__/messages.json +++ b/lib/__tests__/messages.json @@ -48,6 +48,13 @@ { "name": "document1.pdf", "hash": "sVhMwHaxsgiwmfMi4au1Zg" + }, + { + "name": "document_unknown_type", + "hash": "1c2EXOl1sx04g5_hPNmt1A222" + }, + { + "hash": "sVhMwHaxsgiwmfMi4au1Zg111" } ], "author_name": "Heller Stern" diff --git a/package.json b/package.json index 0e9a89a..24d7941 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "quip-export", - "version": "2.2.2", + "version": "2.2.3", "description": "Export all folders and documents from Quip", "main": "index.js", "jest": {