Updated test

This commit is contained in:
delvedor
2019-02-19 09:34:14 +01:00
parent 665ea3999d
commit a8f861c4d4
2 changed files with 44 additions and 1 deletions

View File

@ -6,9 +6,12 @@ import {
EventMeta,
SniffMeta,
ResurrectMeta,
events
events,
ClientExtendsCallbackOptions
} from '../../index'
import { TransportRequestParams, TransportRequestOptions } from '../../lib/Transport'
const client = new Client({ node: 'http://localhost:9200' })
client.on(events.REQUEST, (err: Error | null, meta: EventMeta) => {})
@ -65,3 +68,21 @@ client.index({
})
.then((result: ApiResponse) => {})
.catch((err: Error) => {})
// extend client
client.extend('namespace.method', (options: ClientExtendsCallbackOptions) => {
return function (params: any) {
const requestParams: TransportRequestParams = {
method: 'GET',
path: '/',
querystring: {}
}
const requestOptions: TransportRequestOptions = {
ignore: [404],
maxRetries: 5
}
return options.makeRequest(requestParams, requestOptions)
}
})

View File

@ -429,6 +429,28 @@ test('Extend client APIs', t => {
}
})
t.test('Can override an existing method with { force: true }', t => {
t.plan(1)
const client = new Client({ node: 'http://localhost:9200' })
try {
client.extend('index', { force: true }, () => t.pass('Called'))
} catch (err) {
t.fail('Should not throw')
}
})
t.test('Can override an existing namespace and method with { force: true }', t => {
t.plan(1)
const client = new Client({ node: 'http://localhost:9200' })
try {
client.extend('indices.delete', { force: true }, () => t.pass('Called'))
} catch (err) {
t.fail('Should not throw')
}
})
t.test('Should call the transport.request method', t => {
t.plan(2)