Skip to content

Commit 8f85295

Browse files
committed
Always send match strategy explicitly in US Street API requests
Previously match=strict was suppressed as a "server default" and never sent. Now all match values (strict, enhanced, invalid) are always sent explicitly. Added tests for batch defaults, batch custom parameters, and GET/POST parity.
1 parent 46342ab commit 8f85295

3 files changed

Lines changed: 81 additions & 3 deletions

File tree

lib/smartystreets_ruby_sdk/us_street/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def remap_keys(obj)
5656
converted_lookup['candidates'] = 5
5757
end
5858

59-
converted_lookup['match'] = match_strategy if match_strategy != MatchType::STRICT
59+
converted_lookup['match'] = match_strategy
6060

6161
converted_lookup['input_id'] = lookup.input_id
6262
converted_lookup['street'] = lookup.street

test/mocks/fake_serializer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class FakeSerializer
2+
attr_reader :input
3+
24
def initialize(output)
35
@output = output
46
@input = nil

test/smartystreets_ruby_sdk/us_street/test_street_client.rb

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def test_explicit_match_strict
273273

274274
client.send_lookup(lookup)
275275

276-
assert_nil(sender.request.parameters['match'])
276+
assert_equal(SmartyStreets::USStreet::MatchType::STRICT, sender.request.parameters['match'])
277277
assert_nil(sender.request.parameters['candidates'])
278278
end
279279

@@ -288,7 +288,7 @@ def test_explicit_match_strict_with_candidates
288288

289289
client.send_lookup(lookup)
290290

291-
assert_nil(sender.request.parameters['match'])
291+
assert_equal(SmartyStreets::USStreet::MatchType::STRICT, sender.request.parameters['match'])
292292
assert_equal(3, sender.request.parameters['candidates'])
293293
end
294294

@@ -318,4 +318,80 @@ def test_match_invalid_sends_match_parameter
318318

319319
assert_equal(SmartyStreets::USStreet::MatchType::INVALID, sender.request.parameters['match'])
320320
end
321+
322+
def test_batch_includes_default_match_and_candidates
323+
sender = RequestCapturingSender.new
324+
serializer = FakeSerializer.new('[]')
325+
client = Client.new(sender, serializer)
326+
batch = Batch.new
327+
batch.add(Lookup.new('123 Main St'))
328+
batch.add(Lookup.new('456 Elm St'))
329+
330+
client.send_batch(batch)
331+
332+
serializer.input.each do |converted|
333+
assert_equal(SmartyStreets::USStreet::MatchType::ENHANCED, converted['match'])
334+
assert_equal(5, converted['candidates'])
335+
end
336+
end
337+
338+
def test_batch_custom_parameters_are_top_level_keys
339+
sender = RequestCapturingSender.new
340+
serializer = FakeSerializer.new('[]')
341+
client = Client.new(sender, serializer)
342+
lookup = Lookup.new('123 Main St')
343+
lookup.add_custom_parameter('my_param', 'my_value')
344+
batch = Batch.new
345+
batch.add(lookup)
346+
batch.add(Lookup.new('456 Elm St'))
347+
348+
client.send_batch(batch)
349+
350+
assert_equal('my_value', serializer.input[0]['my_param'])
351+
end
352+
353+
def test_single_and_batch_produce_same_keys_and_values
354+
lookup = Lookup.new
355+
lookup.input_id = 'test-id'
356+
lookup.street = '123 Main St'
357+
lookup.street2 = 'Apt 1'
358+
lookup.secondary = 'Suite B'
359+
lookup.city = 'Denver'
360+
lookup.state = 'CO'
361+
lookup.zipcode = '80014'
362+
lookup.lastline = 'Denver CO 80014'
363+
lookup.addressee = 'John Doe'
364+
lookup.urbanization = 'urb'
365+
lookup.match = SmartyStreets::USStreet::MatchType::ENHANCED
366+
lookup.candidates = 3
367+
lookup.format = SmartyStreets::USStreet::OutputFormat::PROJECT_USA
368+
lookup.county_source = SmartyStreets::USStreet::CountySource::GEOGRAPHIC
369+
lookup.add_custom_parameter('x-custom', 'abc')
370+
371+
# Single lookup path (GET — populates request.parameters)
372+
single_sender = RequestCapturingSender.new
373+
single_serializer = FakeSerializer.new({})
374+
single_client = Client.new(single_sender, single_serializer)
375+
single_client.send_lookup(lookup)
376+
single_params = single_sender.request.parameters
377+
378+
# Batch lookup path (POST — populates serializer.input)
379+
batch_sender = RequestCapturingSender.new
380+
batch_serializer = FakeSerializer.new('[]')
381+
batch_client = Client.new(batch_sender, batch_serializer)
382+
batch = Batch.new
383+
# Reset result from prior send
384+
lookup.result = []
385+
batch.add(lookup)
386+
batch.add(Lookup.new('filler'))
387+
batch_client.send_batch(batch)
388+
batch_params = batch_serializer.input[0]
389+
390+
assert_equal(single_params.keys.sort, batch_params.keys.sort,
391+
'Single and batch paths should produce the same keys')
392+
single_params.each do |key, value|
393+
assert_equal(value, batch_params[key],
394+
"Mismatch for key '#{key}': single=#{value.inspect}, batch=#{batch_params[key].inspect}")
395+
end
396+
end
321397
end

0 commit comments

Comments
 (0)