|
52 | 52 | client.search(headers: param_headers)
|
53 | 53 | end
|
54 | 54 | end
|
| 55 | + |
| 56 | + context 'when accept header is changed' do |
| 57 | + let!(:client) do |
| 58 | + described_class.new( |
| 59 | + host: 'http://localhost:9200', |
| 60 | + transport_options: { headers: instance_headers } |
| 61 | + ).tap do |client| |
| 62 | + client.instance_variable_set('@verified', true) |
| 63 | + end |
| 64 | + end |
| 65 | + let(:instance_headers) do |
| 66 | + { accept: 'application/json' } |
| 67 | + end |
| 68 | + |
| 69 | + it 'performs the request with the header' do |
| 70 | + connection_headers = client.transport.connections.connections.first.connection.headers |
| 71 | + expect(connection_headers['Accept']).to eq 'application/json' |
| 72 | + expect(connection_headers['Content-Type']).to eq 'application/vnd.elasticsearch+json; compatible-with=9' |
| 73 | + |
| 74 | + expect_any_instance_of(Faraday::Connection) |
| 75 | + .to receive(:run_request) |
| 76 | + .with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') } |
| 77 | + client.search |
| 78 | + end |
| 79 | + end |
| 80 | + |
| 81 | + context 'when content-type header is changed' do |
| 82 | + let!(:client) do |
| 83 | + described_class.new( |
| 84 | + host: 'http://localhost:9200', |
| 85 | + transport_options: { headers: instance_headers } |
| 86 | + ).tap do |client| |
| 87 | + client.instance_variable_set('@verified', true) |
| 88 | + end |
| 89 | + end |
| 90 | + let(:instance_headers) do |
| 91 | + { content_type: 'application/json' } |
| 92 | + end |
| 93 | + |
| 94 | + it 'performs the request with the header' do |
| 95 | + connection_headers = client.transport.connections.connections.first.connection.headers |
| 96 | + expect(connection_headers['Accept']).to eq 'application/vnd.elasticsearch+json; compatible-with=9' |
| 97 | + expect(connection_headers['Content-Type']).to eq 'application/json' |
| 98 | + |
| 99 | + expect_any_instance_of(Faraday::Connection) |
| 100 | + .to receive(:run_request) |
| 101 | + .with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') } |
| 102 | + client.search |
| 103 | + end |
| 104 | + end |
| 105 | + |
| 106 | + context 'when no header is set, uses v9 content-type and accept' do |
| 107 | + let!(:client) do |
| 108 | + described_class.new(host: 'http://localhost:9200').tap do |client| |
| 109 | + client.instance_variable_set('@verified', true) |
| 110 | + end |
| 111 | + end |
| 112 | + |
| 113 | + it 'performs the request with the header' do |
| 114 | + expected_headers = client.transport.connections.connections.first.connection.headers |
| 115 | + expect(expected_headers['Accept']).to eq 'application/vnd.elasticsearch+json; compatible-with=9' |
| 116 | + expect(expected_headers['Content-Type']).to eq 'application/vnd.elasticsearch+json; compatible-with=9' |
| 117 | + |
| 118 | + expect_any_instance_of(Faraday::Connection) |
| 119 | + .to receive(:run_request) |
| 120 | + .with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') } |
| 121 | + client.search |
| 122 | + end |
| 123 | + end |
55 | 124 | end
|
0 commit comments