-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08aea5f
commit 1c60fde
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
x-pack/test/api_integration/apis/file_upload/preview_tika_contents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; | ||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
import { pdfBase64 } from './pdf_base64'; | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const supertest = getService('supertest'); | ||
|
||
async function runRequest(base64File: string, expectedResponseCode: number = 200) { | ||
const { body } = await supertest | ||
.post(`/internal/file_upload/preview_tika_contents`) | ||
.set('kbn-xsrf', 'kibana') | ||
.set(ELASTIC_HTTP_VERSION_HEADER, '1') | ||
.send({ base64File }) | ||
.expect(expectedResponseCode); | ||
|
||
return body; | ||
} | ||
const expectedResponse = { | ||
date: '2010-12-01T13:33:24Z', | ||
content_type: 'application/pdf', | ||
author: 'John', | ||
format: 'application/pdf; version=1.5', | ||
modified: '2010-12-01T13:33:24Z', | ||
language: 'en', | ||
creator_tool: 'Microsoft® Word 2010', | ||
content: 'This is a test PDF file', | ||
content_length: 28, | ||
}; | ||
|
||
describe('POST /internal/file_upload/preview_tika_content', () => { | ||
it('should return the text content from the file', async () => { | ||
const resp = await runRequest(pdfBase64); | ||
|
||
expect(resp).to.eql(expectedResponse); | ||
}); | ||
|
||
it('should fail to return text when bad data is sent', async () => { | ||
await runRequest('bad data', 500); | ||
}); | ||
}); | ||
}; |