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
- #assert_rummager_deleted_content(base_path, **options) ⇒ Object
- #assert_rummager_deleted_item(id, index: nil, **options) ⇒ Object
- #assert_rummager_posted_item(attributes, index: nil, **options) ⇒ Object
- #assert_rummager_search(options) ⇒ Object
- #rummager_has_no_policies_for_any_type ⇒ Object
- #rummager_has_no_services_and_info_data_for_organisation ⇒ Object
- #rummager_has_policies_for_every_type(options = {}) ⇒ Object
- #rummager_has_services_and_info_data_for_organisation ⇒ Object
- #rummager_has_specialist_sector_organisations(_sub_sector) ⇒ Object
- #stub_any_rummager_delete(index: nil) ⇒ Object
- #stub_any_rummager_delete_content ⇒ Object
- #stub_any_rummager_post(index: nil) ⇒ Object
- #stub_any_rummager_post_with_queueing_enabled ⇒ Object
- #stub_any_rummager_search ⇒ Object
- #stub_any_rummager_search_to_return_no_results ⇒ Object
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, **) assert_requested( :delete, %r{#{RUMMAGER_ENDPOINT}/content.*#{base_path}}, ** ) 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, **) 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}}, ** ) else assert_requested( :delete, %r{#{RUMMAGER_ENDPOINT}/documents/#{id}}, ** ) 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, **) if index url = RUMMAGER_ENDPOINT + "/#{index}/documents" else url = RUMMAGER_ENDPOINT + "/documents" end assert_requested(:post, url, **) 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() assert_requested :get, "#{RUMMAGER_ENDPOINT}/search.json", ** end |
#rummager_has_no_policies_for_any_type ⇒ Object
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_organisation ⇒ Object
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( = {}) if [:count] stub_request(:get, %r{/search.json.*count=#{[:count]}.*}) .to_return(body: first_n_results(new_policies_results, n: [:count])) else stub_request(:get, %r{/search.json}) .to_return(body: new_policies_results) end end |
#rummager_has_services_and_info_data_for_organisation ⇒ Object
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_content ⇒ Object
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_enabled ⇒ Object
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_search ⇒ Object
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_results ⇒ Object
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 |