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
- #stub_mapit_does_not_have_a_bad_postcode(postcode) ⇒ Object (also: #mapit_does_not_have_a_bad_postcode)
- #stub_mapit_does_not_have_a_postcode(postcode) ⇒ Object (also: #mapit_does_not_have_a_postcode)
- #stub_mapit_does_not_have_area_for_code(code_type, code) ⇒ Object (also: #mapit_does_not_have_area_for_code)
- #stub_mapit_does_not_have_areas(area_type) ⇒ Object (also: #mapit_does_not_have_areas)
- #stub_mapit_has_a_postcode(postcode, coords) ⇒ Object (also: #mapit_has_a_postcode)
- #stub_mapit_has_a_postcode_and_areas(postcode, coords, areas) ⇒ Object (also: #mapit_has_a_postcode_and_areas)
- #stub_mapit_has_area_for_code(code_type, code, area) ⇒ Object (also: #mapit_has_area_for_code)
- #stub_mapit_has_areas(area_type, areas) ⇒ Object (also: #mapit_has_areas)
Instance Method Details
#stub_mapit_does_not_have_a_bad_postcode(postcode) ⇒ Object Also known as: mapit_does_not_have_a_bad_postcode
50 51 52 53 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 50 def stub_mapit_does_not_have_a_bad_postcode(postcode) stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(' ', '+') + ".json") .to_return(body: { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, status: 400) end |
#stub_mapit_does_not_have_a_postcode(postcode) ⇒ Object Also known as: mapit_does_not_have_a_postcode
45 46 47 48 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 45 def stub_mapit_does_not_have_a_postcode(postcode) stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(' ', '+') + ".json") .to_return(body: { "code" => 404, "error" => "No Postcode matches the given query." }.to_json, status: 404) end |
#stub_mapit_does_not_have_area_for_code(code_type, code) ⇒ Object Also known as: mapit_does_not_have_area_for_code
70 71 72 73 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 70 def stub_mapit_does_not_have_area_for_code(code_type, code) stub_request(:get, "#{MAPIT_ENDPOINT}/code/#{code_type}/#{code}.json") .to_return(body: { "code" => 404, "error" => "No areas were found that matched code #{code_type} = #{code}." }.to_json, status: 404) end |
#stub_mapit_does_not_have_areas(area_type) ⇒ Object Also known as: mapit_does_not_have_areas
60 61 62 63 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 60 def stub_mapit_does_not_have_areas(area_type) stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json") .to_return(body: [].to_json, status: 200) end |
#stub_mapit_has_a_postcode(postcode, coords) ⇒ Object Also known as: mapit_has_a_postcode
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 6 def stub_mapit_has_a_postcode(postcode, coords) response = { "wgs84_lat" => coords.first, "wgs84_lon" => coords.last, "postcode" => postcode } stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(' ', '+') + ".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 |
#stub_mapit_has_a_postcode_and_areas(postcode, coords, areas) ⇒ Object Also known as: mapit_has_a_postcode_and_areas
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 19 def stub_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'], 'govuk_slug' => area['govuk_slug'] }, 'name' => area['name'], 'type' => area['type'], 'country_name' => area['country_name'] }] }] stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(' ', '+') + ".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 |
#stub_mapit_has_area_for_code(code_type, code, area) ⇒ Object Also known as: mapit_has_area_for_code
65 66 67 68 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 65 def stub_mapit_has_area_for_code(code_type, code, area) stub_request(:get, "#{MAPIT_ENDPOINT}/code/#{code_type}/#{code}.json") .to_return(body: area.to_json, status: 200) end |
#stub_mapit_has_areas(area_type, areas) ⇒ Object Also known as: mapit_has_areas
55 56 57 58 |
# File 'lib/gds_api/test_helpers/mapit.rb', line 55 def stub_mapit_has_areas(area_type, areas) stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json") .to_return(body: areas.to_json, status: 200) end |