1# frozen_string_literal: true
2
3require "test_helper"
4require "local_calling_guide_repo"
5
6class LocalCallingGuideRepoTest < Minitest::Test
7 def test_find_returns_lat_lon
8 body = Nokogiri::XML::Builder.new { |xml|
9 xml.root {
10 xml.prefixdata {
11 xml.npa "917"
12 xml.nxx "727"
13 xml.x "0"
14 xml.rc "NEW YORK"
15 xml.region "NY"
16 xml.send(:"rc-lat", "40.739362")
17 xml.send(:"rc-lon", "-73.991043")
18 }
19 xml.prefixdata {
20 xml.npa "917"
21 xml.nxx "727"
22 xml.x "1"
23 xml.rc "NEW YORK"
24 xml.region "NY"
25 xml.send(:"rc-lat", "40.739362")
26 xml.send(:"rc-lon", "-73.991043")
27 }
28 }
29 }.to_xml
30
31 stub_request(
32 :get,
33 "https://localcallingguide.com/xmlprefix.php?npa=917&nxx=727"
34 ).to_return(status: 200, body: body)
35
36 result = LocalCallingGuideRepo.new.find("917", "727").sync
37 assert_equal 40.739362, result[:lat]
38 assert_equal(-73.991043, result[:lon])
39 end
40 em :test_find_returns_lat_lon
41
42 def test_find_raises_on_missing_data
43 body = Nokogiri::XML::Builder.new { |xml|
44 xml.root
45 }.to_xml
46
47 stub_request(
48 :get,
49 "https://localcallingguide.com/xmlprefix.php?npa=000&nxx=000"
50 ).to_return(status: 200, body: body)
51
52 assert_raises(RuntimeError) do
53 LocalCallingGuideRepo.new.find("000", "000").sync
54 end
55 end
56 em :test_find_raises_on_missing_data
57end