Module: GdsApi::TestHelpers::Mapit
- Defined in:
- lib/gds_api/test_helpers/mapit.rb
Constant Summary collapse
- MAPIT_ENDPOINT =
Plek.current.find('mapit')
Instance Method Summary collapse
- #mapit_does_not_have_a_bad_postcode(postcode) ⇒ Object
- #mapit_does_not_have_a_postcode(postcode) ⇒ Object
- #mapit_has_a_postcode(postcode, coords) ⇒ Object
- #mapit_has_a_postcode_and_areas(postcode, coords, areas) ⇒ Object
Instance Method Details
#mapit_does_not_have_a_bad_postcode(postcode) ⇒ Object
49 50 51 52 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 49 def mapit_does_not_have_a_bad_postcode(postcode) stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json") .to_return(:body => { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, :status => 400) end |
#mapit_does_not_have_a_postcode(postcode) ⇒ Object
44 45 46 47 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 44 def mapit_does_not_have_a_postcode(postcode) stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json") .to_return(:body => { "code" => 404, "error" => "No Postcode matches the given query." }.to_json, :status => 404) end |
#mapit_has_a_postcode(postcode, coords) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 7 def mapit_has_a_postcode(postcode, coords) response = { "wgs84_lat" => coords.first, "wgs84_lon" => coords.last, "postcode" => postcode } stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json") .to_return(:body => response.to_json, :status => 200) stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(' ').first + ".json") .to_return(:body => response.to_json, :status => 200) end |
#mapit_has_a_postcode_and_areas(postcode, coords, areas) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 20 def mapit_has_a_postcode_and_areas(postcode, coords, areas) response = { "wgs84_lat" => coords.first, "wgs84_lon" => coords.last, "postcode" => postcode } area_response = Hash[areas.map.with_index {|area, i| [i, { 'codes' => { 'ons' => area['ons'], 'gss' => area['gss'] }, 'name' => area['name'], 'type' => area['type'] }] }] stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json") .to_return(:body => response.merge({'areas' => area_response}).to_json, :status => 200) stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(' ').first + ".json") .to_return(:body => response.to_json, :status => 200) end |