Updated test
This commit is contained in:
@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user