Module: GdsApi::TestHelpers::LocalLinksManager

Defined in:
lib/gds_api/test_helpers/local_links_manager.rb

Constant Summary collapse

Plek.current.find("local-links-manager")

Instance Method Summary collapse

Instance Method Details

#convert_to_query_string_params(parameters) ⇒ Object



95
96
97
98
99
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 95

def convert_to_query_string_params(parameters)
  # convert nil to an empty string, otherwise query param is not expressed correctly
  parameters.each { |key, _value| parameters[key] = "" if parameters[key].nil? }
  parameters
end


177
178
179
180
181
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 177

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: local_custodian_code })
    .to_return(body: {}.to_json, status: 404)
end


171
172
173
174
175
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 171

def stub_local_links_manager_does_not_have_an_authority(authority_slug)
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
    .with(query: { authority_slug: authority_slug })
    .to_return(body: {}.to_json, status: 404)
end


126
127
128
129
130
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
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 126

def stub_local_links_manager_has_a_district_and_county_local_authority(district_slug, county_slug, district_snac: "00AG", county_snac: "00LC", 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,
        "snac" => district_snac,
      },
      {
        "name" => county_slug.capitalize,
        "homepage_url" => "http://#{county_slug}.example.com",
        "country_name" => "England",
        "tier" => "county",
        "slug" => county_slug,
        "snac" => 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: local_custodian_code })
      .to_return(body: response.to_json, status: 200)
  end
end


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
# 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", local_custodian_code: nil)
  response = {
    "local_authority" => {
      "name" => authority_slug.capitalize,
      "snac" => snac,
      "tier" => "unitary",
      "homepage_url" => "http://#{authority_slug}.example.com",
      "country_name" => country_name,
      "slug" => authority_slug,
    },
    "local_interaction" => {
      "lgsl_code" => lgsl,
      "lgil_code" => lgil,
      "url" => url,
      "status" => status,
    },
  }

  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
    .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: 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: local_custodian_code, lgsl: lgsl, lgil: lgil })
      .to_return(body: response.to_json, status: 200)
  end
end


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 101

def stub_local_links_manager_has_a_local_authority(authority_slug, country_name: "England", snac: "00AG", local_custodian_code: nil)
  response = {
    "local_authorities" => [
      {
        "name" => authority_slug.capitalize,
        "homepage_url" => "http://#{authority_slug}.example.com",
        "country_name" => country_name,
        "tier" => "unitary",
        "slug" => authority_slug,
        "snac" => snac,
      },
    ],
  }

  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
    .with(query: { authority_slug: 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: local_custodian_code })
      .to_return(body: response.to_json, status: 200)
  end
end


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 183

def stub_local_links_manager_has_a_local_authority_without_homepage(authority_slug, country_name: "England", snac: "00AG", local_custodian_code: nil)
  response = {
    "local_authorities" => [
      {
        "name" => authority_slug.capitalize,
        "homepage_url" => "",
        "country_name" => country_name,
        "tier" => "unitary",
        "slug" => authority_slug,
        "snac" => snac,
      },
    ],
  }

  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
    .with(query: { authority_slug: 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: local_custodian_code })
      .to_return(body: response.to_json, status: 200)
  end
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 37

def stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England", snac: "00AG", local_custodian_code: nil)
  response = {
    "local_authority" => {
      "name" => authority_slug.capitalize,
      "snac" => snac,
      "tier" => "unitary",
      "homepage_url" => "http://#{authority_slug}.example.com",
      "country_name" => country_name,
      "slug" => authority_slug,
    },
  }

  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
    .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: 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: local_custodian_code, lgsl: lgsl, lgil: lgil })
      .to_return(body: response.to_json, status: 200)
  end
end


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 60

def stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England", snac: "00AG", local_custodian_code: nil)
  response = {
    "local_authority" => {
      "name" => authority_slug.capitalize,
      "snac" => snac,
      "tier" => "unitary",
      "homepage_url" => nil,
      "country_name" => country_name,
      "slug" => authority_slug,
    },
  }

  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
    .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: 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: local_custodian_code, lgsl: lgsl, lgil: lgil })
      .to_return(body: response.to_json, status: 200)
  end
end


89
90
91
92
93
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 89

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


83
84
85
86
87
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 83

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


159
160
161
162
163
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 159

def stub_local_links_manager_request_without_local_authority_slug
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
    .with(query: { authority_slug: "" })
    .to_return(body: {}.to_json, status: 400)
end


165
166
167
168
169
# File 'lib/gds_api/test_helpers/local_links_manager.rb', line 165

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