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) ⇒ Object



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

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

#assert_rummager_deleted_item(id) ⇒ Object

Deprecated.

Rummager.delete_docment is deprecated, so is this stub! Use ‘assert_rummager_deleted_content`



39
40
41
42
43
44
45
46
# File 'lib/gds_api/test_helpers/rummager.rb', line 39

def assert_rummager_deleted_item(id)
  warn "assert_rummager_deleted_item stub is deprecated, instead use: assert_rummager_deleted_content"

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

#assert_rummager_posted_item(attributes) ⇒ Object



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

def assert_rummager_posted_item(attributes)
  url = RUMMAGER_ENDPOINT + "/documents"
  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

#rummager_has_no_policies_for_any_typeObject



67
68
69
70
# File 'lib/gds_api/test_helpers/rummager.rb', line 67

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

#rummager_has_no_services_and_info_data_for_organisationObject



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

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



72
73
74
75
76
77
78
79
80
# File 'lib/gds_api/test_helpers/rummager.rb', line 72

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

#rummager_has_services_and_info_data_for_organisationObject



52
53
54
55
# File 'lib/gds_api/test_helpers/rummager.rb', line 52

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



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

def rummager_has_specialist_sector_organisations(sub_sector)
  stub_request_for(sub_sector_organisations_results)
  run_example_query
end

#stub_any_rummager_deleteObject

Deprecated.

Rummager.delete_docment is deprecated, so is this stub! Use ‘stub_any_rummager_delete_content`



29
30
31
32
# File 'lib/gds_api/test_helpers/rummager.rb', line 29

def stub_any_rummager_delete
  warn "stub_any_rummager_delete is deprecated, instead use: stub_any_rummager_delete_content"
  stub_request(:delete, %r{#{RUMMAGER_ENDPOINT}/documents/.*})
end

#stub_any_rummager_delete_contentObject



34
35
36
# File 'lib/gds_api/test_helpers/rummager.rb', line 34

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

#stub_any_rummager_postObject



9
10
11
# File 'lib/gds_api/test_helpers/rummager.rb', line 9

def stub_any_rummager_post
  stub_request(:post, %r{#{RUMMAGER_ENDPOINT}/documents})
end

#stub_any_rummager_post_with_queueing_enabledObject



13
14
15
16
# File 'lib/gds_api/test_helpers/rummager.rb', line 13

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