Module: GdsApi::TestHelpers::Imminence

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

Constant Summary collapse

IMMINENCE_API_HOST =

Generally true. If you are initializing the client differently, you could redefine/override the constant or stub directly.

URI.parse(Plek.current.find('imminence')).host

Instance Method Summary collapse

Instance Method Details

#imminence_has_business_support_schemes(facets_hash, schemes) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gds_api/test_helpers/imminence.rb', line 20

def imminence_has_business_support_schemes(facets_hash, schemes)
  results = {
    "_response_info" => {"status" => "ok"},
    "description" => "Business Support Schemes!",
    "total" => schemes.size, "startIndex" => 1, "pageSize" => schemes.size, "currentPage" => 1, "pages" => 1,
    "results" => schemes
  }

  stub_request(:get, "https://#{IMMINENCE_API_HOST}/business_support_schemes.json").
    with(query: facets_hash).
    to_return(status: 200, body: results.to_json, headers: {})
end

#imminence_has_places(latitude, longitude, details) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/gds_api/test_helpers/imminence.rb', line 10

def imminence_has_places(latitude, longitude, details)
  response = JSON.dump(details['details'])

  ["http", "https"].each do |protocol|
    stub_request(:get, "#{protocol}://#{IMMINENCE_API_HOST}/places/#{details['slug']}.json").
    with(:query => {"lat" => latitude, "lng" => longitude, "limit" => "5"}).
    to_return(:status => 200, :body => response, :headers => {})
  end
end

#stub_imminence_default_business_support_schemesObject

Stubs out all bussiness_support_schemes requests to return an ampty set of results. Requests stubbed with the above method will take precedence over this.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gds_api/test_helpers/imminence.rb', line 35

def stub_imminence_default_business_support_schemes
  empty_results = {
    "_response_info" => {"status" => "ok"},
    "description" => "Business Support Schemes!",
    "total" => 0, "startIndex" => 1, "pageSize" => 0, "currentPage" => 1, "pages" => 1,
    "results" => []
  }

  stub_request(:get, %r{\Ahttps://#{IMMINENCE_API_HOST}/business_support_schemes\.json}).
    to_return(:body => empty_results.to_json)
end