Skip to content

Commit

Permalink
Merge pull request #24 from sonnenkern/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sonnenkern authored Jul 11, 2020
2 parents 688fb25 + 109f73a commit 31a3f2d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
10 changes: 7 additions & 3 deletions lib/QuipProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<br/><img class='message--image' src='RELATIVE_PATH'></img><br/>`;
text += await this._processFile(imageHtml, fileMatch, path, this.options.embeddedImages);
} else {
//file
const fileHtml = `<br/><a href="RELATIVE_PATH">${file.name}</a><br/>`;
let fileName = file.name;
if(!fileName) {
fileName = file.hash;
}
const fileHtml = `<br/><a href="RELATIVE_PATH">${fileName}</a><br/>`;
text += await this._processFile(fileHtml, fileMatch, path);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/__tests__/QuipProcessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
9 changes: 5 additions & 4 deletions lib/__tests__/QuipService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,25 @@ 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');
expect(quipService.logger).toBeInstanceOf(LoggerAdapter);
});

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);
expect(quipService.stats.query_count).toBe(2);
});

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);
Expand All @@ -69,15 +72,13 @@ 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);
expect(quipService.stats.query_count).toBe(2);
});

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);
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/__snapshots__/QuipProcessor.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ exports[`methods tests _getThreadMessagesHtml thread with messages 1`] = `
<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>
<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>
<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>
<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>"
<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>"
`;
7 changes: 7 additions & 0 deletions lib/__tests__/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
{
"name": "document1.pdf",
"hash": "sVhMwHaxsgiwmfMi4au1Zg"
},
{
"name": "document_unknown_type",
"hash": "1c2EXOl1sx04g5_hPNmt1A222"
},
{
"hash": "sVhMwHaxsgiwmfMi4au1Zg111"
}
],
"author_name": "Heller Stern"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 31a3f2d

Please sign in to comment.