Skip to content

Commit

Permalink
adding api test
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Aug 21, 2024
1 parent 08aea5f commit 1c60fde
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/file_upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./has_import_permission'));
loadTestFile(require.resolve('./index_exists'));
loadTestFile(require.resolve('./preview_index_time_range'));
loadTestFile(require.resolve('./preview_tika_contents'));
});
}
8 changes: 8 additions & 0 deletions x-pack/test/api_integration/apis/file_upload/pdf_base64.ts

Large diffs are not rendered by default.

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);
});
});
};

0 comments on commit 1c60fde

Please sign in to comment.