Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,13 @@ def test_object.to_s
send_stream_content(res, "", keep_open: true)
end

with_client(subject.new(server.base_uri) do |c|
client = subject.new(server.base_uri) do |c|
c.query_params do
{"basis" => "p:ABC:123", "filter" => "test"}
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
expect(received_req[:query_string]).to include("basis=p%3AABC%3A123")
expect(received_req[:query_string]).to include("filter=test")
Expand All @@ -1032,12 +1034,14 @@ def test_object.to_s
end

counter = 0
with_client(subject.new(server.base_uri, reconnect_time: reconnect_asap) do |c|
client = subject.new(server.base_uri, reconnect_time: reconnect_asap) do |c|
c.query_params do
counter += 1
{"request_id" => counter.to_s}
end
end) do |client|
end

with_client(client) do |_|
req1 = requests.pop
expect(req1[:query_string]).to eq("request_id=1")

Expand All @@ -1058,11 +1062,13 @@ def test_object.to_s
end

base_uri_with_params = "#{server.base_uri}?static=value"
with_client(subject.new(base_uri_with_params) do |c|
client = subject.new(base_uri_with_params) do |c|
c.query_params do
{"dynamic" => "param"}
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
expect(received_req[:query_string]).to include("static=value")
expect(received_req[:query_string]).to include("dynamic=param")
Expand All @@ -1080,11 +1086,13 @@ def test_object.to_s
end

base_uri_with_params = "#{server.base_uri}?key=original"
with_client(subject.new(base_uri_with_params) do |c|
client = subject.new(base_uri_with_params) do |c|
c.query_params do
{"key" => "overridden"}
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
# Dynamic params should override static ones
expect(received_req[:query_string]).to eq("key=overridden")
Expand Down Expand Up @@ -1135,11 +1143,13 @@ def test_object.to_s
end

base_uri_with_params = "#{server.base_uri}?existing=param"
with_client(subject.new(base_uri_with_params) do |c|
client = subject.new(base_uri_with_params) do |c|
c.query_params do
{}
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
# Empty hash should preserve existing params (consistent with Python behavior)
expect(received_req[:query_string]).to eq("existing=param")
Expand All @@ -1156,11 +1166,13 @@ def test_object.to_s
send_stream_content(res, "", keep_open: true)
end

with_client(subject.new(server.base_uri) do |c|
client = subject.new(server.base_uri) do |c|
c.query_params do
nil
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
# Should proceed with base URI (no query params)
expect(received_req[:query_string]).to be_nil
Expand All @@ -1178,11 +1190,13 @@ def test_object.to_s
end

base_uri_with_params = "#{server.base_uri}?fallback=value"
with_client(subject.new(base_uri_with_params) do |c|
client = subject.new(base_uri_with_params) do |c|
c.query_params do
raise "Test exception"
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
# Should fall back to base URI params
expect(received_req[:query_string]).to eq("fallback=value")
Expand All @@ -1200,11 +1214,13 @@ def test_object.to_s
end

base_uri_with_params = "#{server.base_uri}?fallback=value"
with_client(subject.new(base_uri_with_params) do |c|
client = subject.new(base_uri_with_params) do |c|
c.query_params do
"not a hash"
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
# Should fall back to base URI params
expect(received_req[:query_string]).to eq("fallback=value")
Expand All @@ -1230,12 +1246,14 @@ def test_object.to_s
end

connection_count = 0
with_client(subject.new(server.base_uri, reconnect_time: reconnect_asap) do |c|
client = subject.new(server.base_uri, reconnect_time: reconnect_asap) do |c|
c.query_params do
connection_count += 1
{"connection" => connection_count.to_s}
end
end) do |client|
end

with_client(client) do |_|
req1 = requests.pop
expect(req1[:query_string]).to eq("connection=1")

Expand All @@ -1258,11 +1276,13 @@ def test_object.to_s
send_stream_content(res, "", keep_open: true)
end

with_client(subject.new(server.base_uri) do |c|
client = subject.new(server.base_uri) do |c|
c.query_params do
{"basis" => "p:ABC:123", "filter" => "test value with spaces"}
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
expect(received_req[:query_string]).to include("basis=p%3AABC%3A123")
expect(received_req[:query_string]).to include("filter=test+value+with+spaces")
Expand All @@ -1279,15 +1299,17 @@ def test_object.to_s
send_stream_content(res, "", keep_open: true)
end

with_client(subject.new(server.base_uri) do |c|
client = subject.new(server.base_uri) do |c|
c.query_params do
{
"param1" => "value1",
"param2" => "value2",
"param3" => "value3",
}
end
end) do |client|
end

with_client(client) do |_|
received_req = requests.pop
query_string = received_req[:query_string]
expect(query_string).to include("param1=value1")
Expand Down