Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import transportPackageJson from '@elastic/transport/package.json'

const kChild = Symbol('elasticsearchjs-child')
const kInitialOptions = Symbol('elasticsearchjs-initial-options')
export const kAcceptedParams = Symbol('elasticsearchjs-accepted-params')

let clientVersion: string = packageJson.version
/* istanbul ignore next */
if (clientVersion.includes('-')) {
Expand Down
96 changes: 96 additions & 0 deletions test/unit/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { test } from 'tap'
import { connection } from '../utils'
import { Client } from '../..'
import { Transport } from '@elastic/transport'
import * as T from '../../lib/api/types'

test('Api with top level body', async t => {
Expand Down Expand Up @@ -167,3 +168,98 @@ test('With generic document and aggregation', async t => {
t.ok(Array.isArray(response.aggregations?.unique.buckets))
})

test('Api request metadata', t => {
t.test('name', async t => {
class TestTransport extends Transport {
// @ts-expect-error
async request(params, options) {
t.equal(params.meta.name, 'synonyms.put_synonym_rule')
return super.request(params, options)
}
}

const Connection = connection.buildMockConnection({
onRequest () {
return {
statusCode: 200,
body: { took: 42 }
}
}
})

const client = new Client({
node: 'http://localhost:9200',
// @ts-expect-error
Transport: TestTransport,
Connection
})
// @ts-expect-error
await client.synonyms.putSynonymRule({ set_id: "foo", rule_id: "bar" })
})

t.test('pathParts', async t => {
class TestTransport extends Transport {
// @ts-expect-error
async request(params, options) {
t.strictSame(params.meta.pathParts, {
set_id: 'foo',
rule_id: 'bar'
})
return super.request(params, options)
}
}

const Connection = connection.buildMockConnection({
onRequest () {
return {
statusCode: 200,
body: { took: 42 }
}
}
})

const client = new Client({
node: 'http://localhost:9200',
// @ts-expect-error
Transport: TestTransport,
Connection
})
// @ts-expect-error
await client.synonyms.putSynonymRule({ set_id: "foo", rule_id: "bar" })
})

t.test('acceptedParams', async t => {
class TestTransport extends Transport {
// @ts-expect-error
async request(params, options) {
t.strictSame(params.meta.acceptedParams, [
'set_id',
'rule_id',
'synonyms',
'refresh',
])
return super.request(params, options)
}
}

const Connection = connection.buildMockConnection({
onRequest () {
return {
statusCode: 200,
body: { took: 42 }
}
}
})

const client = new Client({
node: 'http://localhost:9200',
// @ts-expect-error
Transport: TestTransport,
Connection
})
// @ts-expect-error
await client.synonyms.putSynonymRule({ set_id: "foo", rule_id: "bar" })
})

t.end()
})
Loading