Module: GdsApi::TestHelpers::Rummager

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

Constant Summary collapse

RUMMAGER_ENDPOINT =
Plek.current.find('rummager')

Instance Method Summary collapse

Instance Method Details

#assert_rummager_deleted_content(base_path, **options) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/gds_api/test_helpers/rummager.rb', line 85

def assert_rummager_deleted_content(base_path, **options)
  assert_requested(
    :delete,
    %r{#{RUMMAGER_ENDPOINT}/content.*#{base_path}},
    **options
  )
end

#assert_rummager_deleted_item(id, index: nil, **options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gds_api/test_helpers/rummager.rb', line 66

def assert_rummager_deleted_item(id, index: nil, **options)
  if id =~ %r{^/}
    raise ArgumentError, 'Rummager id must not start with a slash'
  end
  if index
    assert_requested(
      :delete,
      %r{#{RUMMAGER_ENDPOINT}/#{index}/documents/#{id}},
      **options
    )
  else
    assert_requested(
      :delete,
      %r{#{RUMMAGER_ENDPOINT}/documents/#{id}},
      **options
    )
  end
end

#assert_rummager_posted_item(attributes, index: nil, **options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gds_api/test_helpers/rummager.rb', line 26

def assert_rummager_posted_item(attributes, index: nil, **options)
  if index
    url = RUMMAGER_ENDPOINT + "/#{index}/documents"
  else
    url = RUMMAGER_ENDPOINT + "/documents"
  end

  assert_requested(:post, url, **options) do |req|
    data = JSON.parse(req.body)
    attributes.to_a.all? do |key, value|
      data[key.to_s] == value
    end
  end
end

#assert_rummager_search(options) ⇒ Object



49
50
51
# File 'lib/gds_api/test_helpers/rummager.rb', line 49

def assert_rummager_search(options)
  assert_requested :get, "#{RUMMAGER_ENDPOINT}/search.json", **options
end

#rummager_has_no_policies_for_any_typeObject



108
109
110
111
# File 'lib/gds_api/test_helpers/rummager.rb', line 108

def rummager_has_no_policies_for_any_type
  stub_request(:get, %r{/search.json})
    .to_return(body: no_search_results_found)
end

#rummager_has_no_services_and_info_data_for_organisationObject



98
99
100
101
# File 'lib/gds_api/test_helpers/rummager.rb', line 98

def rummager_has_no_services_and_info_data_for_organisation
  stub_request_for(no_search_results_found)
  run_example_query
end

#rummager_has_policies_for_every_type(options = {}) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/gds_api/test_helpers/rummager.rb', line 113

def rummager_has_policies_for_every_type(options = {})
  if options[:count]
    stub_request(:get, %r{/search.json.*count=#{options[:count]}.*})
      .to_return(body: first_n_results(new_policies_results, n: options[:count]))
  else
    stub_request(:get, %r{/search.json})
      .to_return(body: new_policies_results)
  end
end

#rummager_has_services_and_info_data_for_organisationObject



93
94
95
96
# File 'lib/gds_api/test_helpers/rummager.rb', line 93

def rummager_has_services_and_info_data_for_organisation
  stub_request_for(search_results_found)
  run_example_query
end

#rummager_has_specialist_sector_organisations(_sub_sector) ⇒ Object



103
104
105
106
# File 'lib/gds_api/test_helpers/rummager.rb', line 103

def rummager_has_specialist_sector_organisations(_sub_sector)
  stub_request_for(sub_sector_organisations_results)
  run_example_query
end

#stub_any_rummager_delete(index: nil) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/gds_api/test_helpers/rummager.rb', line 53

def stub_any_rummager_delete(index: nil)
  if index
    stub_request(:delete, %r{#{RUMMAGER_ENDPOINT}/#{index}/documents/.*})
  else
    # use rummager's default index
    stub_request(:delete, %r{#{RUMMAGER_ENDPOINT}/documents/.*})
  end
end

#stub_any_rummager_delete_contentObject



62
63
64
# File 'lib/gds_api/test_helpers/rummager.rb', line 62

def stub_any_rummager_delete_content
  stub_request(:delete, %r{#{RUMMAGER_ENDPOINT}/content.*})
end

#stub_any_rummager_post(index: nil) ⇒ Object



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

def stub_any_rummager_post(index: nil)
  if index
    stub_request(:post, %r{#{RUMMAGER_ENDPOINT}/#{index}/documents})
      .to_return(status: [202, "Accepted"])
  else
    stub_request(:post, %r{#{RUMMAGER_ENDPOINT}/documents})
      .to_return(status: [202, "Accepted"])
  end
end

#stub_any_rummager_post_with_queueing_enabledObject



19
20
21
22
23
24
# File 'lib/gds_api/test_helpers/rummager.rb', line 19

def stub_any_rummager_post_with_queueing_enabled
  warn "stub_any_rummager_post_with_queueing_enabled is deprecated: use stub_any_rummager_post instead"

  stub_request(:post, %r{#{RUMMAGER_ENDPOINT}/documents}) \
    .to_return(status: [202, "Accepted"])
end

#stub_any_rummager_searchObject



41
42
43
# File 'lib/gds_api/test_helpers/rummager.rb', line 41

def stub_any_rummager_search
  stub_request(:get, %r{#{RUMMAGER_ENDPOINT}/search.json})
end

#stub_any_rummager_search_to_return_no_resultsObject



45
46
47
# File 'lib/gds_api/test_helpers/rummager.rb', line 45

def stub_any_rummager_search_to_return_no_results
  stub_any_rummager_search.to_return(body: { results: [] }.to_json)
end