Do a shallow clone copy of the body when the body key is defined (#1584)
This commit is contained in:
committed by
GitHub
parent
185697b6fe
commit
a5a0a1c589
@ -134,3 +134,32 @@ test('Api with body key and keyed body', async t => {
|
||||
|
||||
t.equal(response.result, 'created')
|
||||
})
|
||||
|
||||
test('Using the body key should not mutate the body', async t => {
|
||||
t.plan(2)
|
||||
|
||||
const Connection = connection.buildMockConnection({
|
||||
onRequest (opts) {
|
||||
// @ts-expect-error
|
||||
t.same(JSON.parse(opts.body), { query: { match_all: {} }, sort: 'foo' })
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: { took: 42 }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection
|
||||
})
|
||||
|
||||
const body = { query: { match_all: {} } }
|
||||
await client.search({
|
||||
index: 'test',
|
||||
sort: 'foo',
|
||||
body
|
||||
})
|
||||
|
||||
t.same(body, { query: { match_all: {} } })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user