Skip to content

Commit 6a5cf11

Browse files
committed
[Client] Updates elasticsearch tests for APIs with required body
1 parent abd73e7 commit 6a5cf11

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

elasticsearch/spec/unit/elasticsearch_product_validation_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
describe 'Elasticsearch: Validation' do
2222
let(:host) { 'http://localhost:9200' }
2323
let(:count_request_stub) do
24-
stub_request(:get, "#{host}/_count")
25-
.to_return(status: status, body: nil, headers: headers)
24+
stub_request(:post, "#{host}/_count")
25+
.to_return(status: status, body: '', headers: headers)
2626
end
2727
let(:status) { 200 }
28-
let(:body) { nil }
28+
let(:body) { '' }
2929
let(:headers) { {} }
3030
let(:client) { Elasticsearch::Client.new }
3131

@@ -39,7 +39,7 @@
3939
expect(client.instance_variable_get('@verified')).to be false
4040
count_request_stub
4141
expect do
42-
client.count
42+
client.count(body: '')
4343
end.to raise_error Elastic::Transport::Transport::Errors::Unauthorized
4444
expect(client.instance_variable_get('@verified')).to be true
4545

@@ -61,7 +61,7 @@
6161
expect(client.instance_variable_get('@verified')).to be false
6262
count_request_stub
6363
expect do
64-
client.count
64+
client.count(body: '')
6565
end.to raise_error Elastic::Transport::Transport::Errors::Forbidden
6666
expect(client.instance_variable_get('@verified')).to be true
6767

@@ -83,7 +83,7 @@
8383
expect(client.instance_variable_get('@verified')).to be false
8484
count_request_stub
8585
expect do
86-
client.count
86+
client.count(body: '')
8787
end.to raise_error Elastic::Transport::Transport::Errors::RequestEntityTooLarge
8888
expect(client.instance_variable_get('@verified')).to be true
8989

@@ -107,7 +107,7 @@
107107
expect(client.instance_variable_get('@verified')).to be false
108108
count_request_stub
109109
expect do
110-
client.count
110+
client.count(body: '')
111111
end.to raise_error Elastic::Transport::Transport::Errors::ServiceUnavailable
112112
expect(client.instance_variable_get('@verified')).to be false
113113

@@ -131,7 +131,7 @@
131131
it 'Makes requests and passes validation' do
132132
expect(client.instance_variable_get('@verified')).to be false
133133
count_request_stub
134-
client.count
134+
client.count(body: '')
135135
expect(client.instance_variable_get('@verified')).to be true
136136
end
137137
end

elasticsearch/spec/unit/headers_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
it 'performs the request with the header' do
2626
allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
27-
expect { client.search(headers: headers) }.not_to raise_error
27+
expect { client.search(headers: headers, body: '') }.not_to raise_error
2828
expect(client).to have_received(:perform_request)
29-
.with('GET', '_search', {}, nil, headers, { endpoint: 'search' })
29+
.with('POST', '_search', {}, '', headers, { endpoint: 'search' })
3030
end
3131
end
3232

@@ -47,9 +47,9 @@
4747

4848
expect_any_instance_of(Faraday::Connection)
4949
.to receive(:run_request)
50-
.with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') }
50+
.with(:post, 'http://localhost:9200/_search', '', expected_headers) { OpenStruct.new(body: '') }
5151

52-
client.search(headers: param_headers)
52+
client.search(headers: param_headers, body: '')
5353
end
5454
end
5555

@@ -73,8 +73,8 @@
7373

7474
expect_any_instance_of(Faraday::Connection)
7575
.to receive(:run_request)
76-
.with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') }
77-
client.search
76+
.with(:post, 'http://localhost:9200/_search', '', connection_headers) { OpenStruct.new(body: '') }
77+
client.search(body: '')
7878
end
7979
end
8080

@@ -98,8 +98,8 @@
9898

9999
expect_any_instance_of(Faraday::Connection)
100100
.to receive(:run_request)
101-
.with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') }
102-
client.search
101+
.with(:post, 'http://localhost:9200/_search', '', connection_headers) { OpenStruct.new(body: '') }
102+
client.search(body: '')
103103
end
104104
end
105105

@@ -117,8 +117,8 @@
117117

118118
expect_any_instance_of(Faraday::Connection)
119119
.to receive(:run_request)
120-
.with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') }
121-
client.search
120+
.with(:post, 'http://localhost:9200/_search', '', expected_headers) { OpenStruct.new(body: '') }
121+
client.search(body: '')
122122
end
123123
end
124124
end

elasticsearch/spec/unit/opaque_id_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828
context 'when x-opaque-id is set' do
2929
it 'uses x-opaque-id on a request' do
30-
client.search(opaque_id: '12345')
30+
client.search(opaque_id: '12345', body: '')
3131
expect(transport).to have_received(:perform_request)
32-
.with('GET', '_search', {}, nil, { 'X-Opaque-Id' => '12345' }, {:endpoint=>"search"})
32+
.with('POST', '_search', {}, '', { 'X-Opaque-Id' => '12345' }, {:endpoint=>"search"})
3333
end
3434
end
3535

@@ -40,9 +40,9 @@
4040
end
4141

4242
it 'uses x-opaque-id on a request' do
43-
expect { client.search(opaque_id: '12345') }.not_to raise_error
43+
expect { client.search(opaque_id: '12345', body: '') }.not_to raise_error
4444
expect(transport).to have_received(:perform_request)
45-
.with('GET', '_search', {}, nil, { 'X-Opaque-Id' => 'elastic_cloud12345' }, {:endpoint=>"search"})
45+
.with('POST', '_search', {}, '', { 'X-Opaque-Id' => 'elastic_cloud12345' }, {:endpoint=>"search"})
4646
end
4747
end
4848
end

0 commit comments

Comments
 (0)