-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfile_reader_100.test.js
More file actions
52 lines (44 loc) · 1.39 KB
/
file_reader_100.test.js
File metadata and controls
52 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const retry = require('async-retry');
const transformer = require('../dist/node-es-transformer.cjs');
const deleteIndex = require('./utils/delete_index');
const { elasticsearchUrl, getElasticsearchClient } = require('./utils/elasticsearch');
const client = getElasticsearchClient();
const indexName = 'file_reader_100';
describe('indexes an ndjson file with 100 docs', () => {
afterAll(async () => {
await deleteIndex(client, indexName)();
await client.close();
});
it('should index the ndjson file and find its docs', done => {
(async () => {
const { events } = await transformer({
fileName: './data/sample_data_100.ndjson',
targetIndexName: indexName,
mappings: {
properties: {
the_index: {
type: 'integer',
},
code: {
type: 'integer',
},
url: {
type: 'keyword',
},
},
},
verbose: false,
});
events.on('finish', async () => {
await client.indices.refresh({ index: indexName });
await retry(async () => {
const res = await fetch(`${elasticsearchUrl}/${indexName}/_search?q=the_index:99`);
expect(res.status).toBe(200);
const body = await res.json();
expect(body?.hits?.total?.value).toBe(1);
});
done();
});
})();
});
});