Unknown parameters handling (#761)
This commit is contained in:
committed by
GitHub
parent
7acd2e3b07
commit
23cfe11e44
@ -221,3 +221,31 @@ test('Basic (options and promises)', t => {
|
||||
.catch(t.fail)
|
||||
})
|
||||
})
|
||||
|
||||
test('Pass unknown parameters as query parameters (and get a warning)', t => {
|
||||
t.plan(4)
|
||||
|
||||
function handler (req, res) {
|
||||
t.strictEqual(req.url, '/test/doc/_search?q=foo%3Abar&winter=is%20coming')
|
||||
res.setHeader('Content-Type', 'application/json;utf=8')
|
||||
res.end(JSON.stringify({ hello: 'world' }))
|
||||
}
|
||||
|
||||
buildServer(handler, ({ port }, server) => {
|
||||
const client = new Client({
|
||||
node: `http://localhost:${port}`
|
||||
})
|
||||
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
q: 'foo:bar',
|
||||
winter: 'is coming'
|
||||
}, (err, { body, warnings }) => {
|
||||
t.error(err)
|
||||
t.deepEqual(body, { hello: 'world' })
|
||||
t.deepEqual(warnings, ['Client - Unknown parameter: "winter", sending it as query parameter'])
|
||||
server.stop()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -1535,6 +1535,45 @@ test('Warning header', t => {
|
||||
})
|
||||
})
|
||||
|
||||
t.test('Multiple warnings and external warning', t => {
|
||||
t.plan(5)
|
||||
|
||||
const warn1 = '112 - "cache down" "Wed, 21 Oct 2015 07:28:00 GMT"'
|
||||
const warn2 = '199 agent "Error message" "2015-01-01"'
|
||||
function handler (req, res) {
|
||||
res.setHeader('Content-Type', 'application/json;utf=8')
|
||||
res.setHeader('Warning', warn1 + ',' + warn2)
|
||||
res.end(JSON.stringify({ hello: 'world' }))
|
||||
}
|
||||
|
||||
buildServer(handler, ({ port }, server) => {
|
||||
const pool = new ConnectionPool({ Connection })
|
||||
pool.addConnection(`http://localhost:${port}`)
|
||||
|
||||
const transport = new Transport({
|
||||
emit: () => {},
|
||||
connectionPool: pool,
|
||||
serializer: new Serializer(),
|
||||
maxRetries: 3,
|
||||
requestTimeout: 30000,
|
||||
sniffInterval: false,
|
||||
sniffOnStart: false
|
||||
})
|
||||
|
||||
transport.request({
|
||||
method: 'GET',
|
||||
path: '/hello'
|
||||
}, {
|
||||
warnings: ['winter is coming']
|
||||
}, (err, { warnings }) => {
|
||||
t.error(err)
|
||||
t.deepEqual(warnings, ['winter is coming', warn1, warn2])
|
||||
warnings.forEach(w => t.type(w, 'string'))
|
||||
server.stop()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user