Do a shallow clone copy of the body when the body key is defined (#1584)

This commit is contained in:
Tomas Della Vedova
2021-10-25 16:56:33 +02:00
committed by GitHub
parent 185697b6fe
commit a5a0a1c589
42 changed files with 139 additions and 110 deletions

View File

@ -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: {} } })
})