Module: GdsApi::TestHelpers::LocalLinksManager
- Defined in:
- lib/gds_api/test_helpers/local_links_manager.rb
Constant Summary collapse
- LOCAL_LINKS_MANAGER_ENDPOINT =
Plek.find("local-links-manager")
Instance Method Summary collapse
- #convert_to_query_string_params(parameters) ⇒ Object
- #stub_local_links_manager_does_not_have_a_custodian_code(local_custodian_code) ⇒ Object
- #stub_local_links_manager_does_not_have_an_authority(authority_slug) ⇒ Object
- #stub_local_links_manager_has_a_district_and_county_local_authority(district_slug, county_slug, district_snac: "00AG", county_snac: "00LC", district_gss: "EE06000063", county_gss: "EE06000064", local_custodian_code: nil) ⇒ Object
- #stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England", status: "ok", snac: "00AG", gss: "EE06000063", local_custodian_code: nil, title: nil) ⇒ Object
- #stub_local_links_manager_has_a_local_authority(authority_slug, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) ⇒ Object
- #stub_local_links_manager_has_a_local_authority_without_homepage(authority_slug, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) ⇒ Object
- #stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) ⇒ Object
- #stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) ⇒ Object
- #stub_local_links_manager_request_with_invalid_parameters(**parameters) ⇒ Object
- #stub_local_links_manager_request_with_missing_parameters(**parameters) ⇒ Object
- #stub_local_links_manager_request_without_local_authority_slug ⇒ Object
- #stub_local_links_manager_request_without_local_custodian_code ⇒ Object
Instance Method Details
#convert_to_query_string_params(parameters) ⇒ Object
99 100 101 102 103 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 99 def convert_to_query_string_params(parameters) # convert nil to an empty string, otherwise query param is not expressed correctly parameters.each_key { |key| parameters[key] = "" if parameters[key].nil? } parameters end |
#stub_local_links_manager_does_not_have_a_custodian_code(local_custodian_code) ⇒ Object
184 185 186 187 188 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 184 def stub_local_links_manager_does_not_have_a_custodian_code(local_custodian_code) stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { local_custodian_code: }) .to_return(body: {}.to_json, status: 404) end |
#stub_local_links_manager_does_not_have_an_authority(authority_slug) ⇒ Object
178 179 180 181 182 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 178 def () stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { authority_slug: }) .to_return(body: {}.to_json, status: 404) end |
#stub_local_links_manager_has_a_district_and_county_local_authority(district_slug, county_slug, district_snac: "00AG", county_snac: "00LC", district_gss: "EE06000063", county_gss: "EE06000064", local_custodian_code: nil) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 131 def (district_slug, county_slug, district_snac: "00AG", county_snac: "00LC", district_gss: "EE06000063", county_gss: "EE06000064", local_custodian_code: nil) response = { "local_authorities" => [ { "name" => district_slug.capitalize, "homepage_url" => "http://#{district_slug}.example.com", "country_name" => "England", "tier" => "district", "slug" => district_slug, "gss" => district_gss, }, { "name" => county_slug.capitalize, "homepage_url" => "http://#{county_slug}.example.com", "country_name" => "England", "tier" => "county", "slug" => county_slug, "gss" => county_gss, }, ], } response["local_authorities"][0]["snac"] = district_snac if district_snac response["local_authorities"][1]["snac"] = county_snac if county_snac stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { authority_slug: district_slug }) .to_return(body: response.to_json, status: 200) unless local_custodian_code.nil? stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { local_custodian_code: }) .to_return(body: response.to_json, status: 200) end end |
#stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England", status: "ok", snac: "00AG", gss: "EE06000063", local_custodian_code: nil, title: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 8 def stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England", status: "ok", snac: "00AG", gss: "EE06000063", local_custodian_code: nil, title: nil) response = { "local_authority" => { "name" => .capitalize, "gss" => gss, "tier" => "unitary", "homepage_url" => "http://#{}.example.com", "country_name" => country_name, "slug" => , }, "local_interaction" => { "lgsl_code" => lgsl, "lgil_code" => lgil, "url" => url, "status" => status, "title" => title, }, } response["local_authority"]["snac"] = snac if snac stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link") .with(query: { authority_slug:, lgsl:, lgil: }) .to_return(body: response.to_json, status: 200) unless local_custodian_code.nil? stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link") .with(query: { local_custodian_code:, lgsl:, lgil: }) .to_return(body: response.to_json, status: 200) end end |
#stub_local_links_manager_has_a_local_authority(authority_slug, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 105 def (, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) response = { "local_authorities" => [ { "name" => .capitalize, "homepage_url" => "http://#{}.example.com", "country_name" => country_name, "tier" => "unitary", "slug" => , "gss" => gss, }, ], } response["local_authorities"][0]["snac"] = snac if snac stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { authority_slug: }) .to_return(body: response.to_json, status: 200) unless local_custodian_code.nil? stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { local_custodian_code: }) .to_return(body: response.to_json, status: 200) end end |
#stub_local_links_manager_has_a_local_authority_without_homepage(authority_slug, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 190 def (, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) response = { "local_authorities" => [ { "name" => .capitalize, "homepage_url" => "", "country_name" => country_name, "tier" => "unitary", "slug" => , "gss" => gss, }, ], } response["local_authorities"][0]["snac"] = snac if snac stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { authority_slug: }) .to_return(body: response.to_json, status: 200) unless local_custodian_code.nil? stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { local_custodian_code: }) .to_return(body: response.to_json, status: 200) end end |
#stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 39 def stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) response = { "local_authority" => { "name" => .capitalize, "gss" => gss, "tier" => "unitary", "homepage_url" => "http://#{}.example.com", "country_name" => country_name, "slug" => , }, } response["local_authority"]["snac"] = snac if snac stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link") .with(query: { authority_slug:, lgsl:, lgil: }) .to_return(body: response.to_json, status: 200) unless local_custodian_code.nil? stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link") .with(query: { local_custodian_code:, lgsl:, lgil: }) .to_return(body: response.to_json, status: 200) end end |
#stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 63 def stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England", snac: "00AG", gss: "EE06000063", local_custodian_code: nil) response = { "local_authority" => { "name" => .capitalize, "gss" => gss, "tier" => "unitary", "homepage_url" => nil, "country_name" => country_name, "slug" => , }, } response["local_authority"]["snac"] = snac if snac stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link") .with(query: { authority_slug:, lgsl:, lgil: }) .to_return(body: response.to_json, status: 200) unless local_custodian_code.nil? stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link") .with(query: { local_custodian_code:, lgsl:, lgil: }) .to_return(body: response.to_json, status: 200) end end |
#stub_local_links_manager_request_with_invalid_parameters(**parameters) ⇒ Object
93 94 95 96 97 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 93 def stub_local_links_manager_request_with_invalid_parameters(**parameters) stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link") .with(query: convert_to_query_string_params(parameters)) .to_return(body: {}.to_json, status: 404) end |
#stub_local_links_manager_request_with_missing_parameters(**parameters) ⇒ Object
87 88 89 90 91 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 87 def stub_local_links_manager_request_with_missing_parameters(**parameters) stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link") .with(query: convert_to_query_string_params(parameters)) .to_return(body: {}.to_json, status: 400) end |
#stub_local_links_manager_request_without_local_authority_slug ⇒ Object
166 167 168 169 170 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 166 def stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { authority_slug: "" }) .to_return(body: {}.to_json, status: 400) end |
#stub_local_links_manager_request_without_local_custodian_code ⇒ Object
172 173 174 175 176 |
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 172 def stub_local_links_manager_request_without_local_custodian_code stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority") .with(query: { local_custodian_code: "" }) .to_return(body: {}.to_json, status: 400) end |