Module: GdsApi::TestHelpers::SupportApi

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

Constant Summary collapse

SUPPORT_API_ENDPOINT =
Plek.current.find('support-api')

Instance Method Summary collapse

Instance Method Details

#stub_any_support_api_callObject


141
142
143
# File 'lib/gds_api/test_helpers/support_api.rb', line 141

def stub_any_support_api_call
  stub_request(:any, %r{\A#{SUPPORT_API_ENDPOINT}})
end

#stub_support_api_anonymous_feedback(params, response_body = {}) ⇒ Object


69
70
71
72
73
# File 'lib/gds_api/test_helpers/support_api.rb', line 69

def stub_support_api_anonymous_feedback(params, response_body = {})
  stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback").
    with(query: params).
    to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_anonymous_feedback_doc_type_summary(document_type, ordering = nil, response_body = nil) ⇒ Object


124
125
126
127
128
129
# File 'lib/gds_api/test_helpers/support_api.rb', line 124

def stub_support_api_anonymous_feedback_doc_type_summary(document_type, ordering = nil, response_body = nil)
  uri = "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/document-types/#{document_type}"
  uri << "?ordering=#{ordering}" if ordering
  stub_http_request(:get, uri).
      to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_anonymous_feedback_organisation_summary(slug, ordering = nil, response_body = {}) ⇒ Object


75
76
77
78
79
80
# File 'lib/gds_api/test_helpers/support_api.rb', line 75

def stub_support_api_anonymous_feedback_organisation_summary(slug, ordering = nil, response_body = {})
  uri = "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/organisations/#{slug}"
  uri << "?ordering=#{ordering}" if ordering
  stub_http_request(:get, uri).
    to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_create_page_improvement(params) ⇒ Object


39
40
41
42
43
# File 'lib/gds_api/test_helpers/support_api.rb', line 39

def stub_support_api_create_page_improvement(params)
  post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/page-improvements")
  post_stub.with(body: params)
  post_stub.to_return(status: 201)
end

#stub_support_api_document_type_list(response_body = nil) ⇒ Object


117
118
119
120
121
122
# File 'lib/gds_api/test_helpers/support_api.rb', line 117

def stub_support_api_document_type_list(response_body = nil)
  response_body ||= %w(case_study detailed_guide smart_answer)

  stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/document-types").
      to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_feedback_export_request(id, response_body = nil) ⇒ Object


131
132
133
134
135
136
137
138
139
# File 'lib/gds_api/test_helpers/support_api.rb', line 131

def stub_support_api_feedback_export_request(id, response_body = nil)
  response_body ||= {
    filename: "feedex_0000-00-00_2015-01-01.csv",
    ready: true
  }

  stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/export-requests/#{id}").
    to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_feedback_export_request_creation(request_details = nil) ⇒ Object


27
28
29
30
31
# File 'lib/gds_api/test_helpers/support_api.rb', line 27

def stub_support_api_feedback_export_request_creation(request_details = nil)
  post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/export-requests")
  post_stub.with(body: { export_request: request_details }) unless request_details.nil?
  post_stub.to_return(status: 202)
end

#stub_support_api_global_export_request_creation(request_details = nil) ⇒ Object


33
34
35
36
37
# File 'lib/gds_api/test_helpers/support_api.rb', line 33

def stub_support_api_global_export_request_creation(request_details = nil)
  post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/global-export-requests")
  post_stub.with(body: { global_export_request: request_details }) unless request_details.nil?
  post_stub.to_return(status: 202)
end

#stub_support_api_long_form_anonymous_contact_creation(request_details = nil) ⇒ Object


21
22
23
24
25
# File 'lib/gds_api/test_helpers/support_api.rb', line 21

def stub_support_api_long_form_anonymous_contact_creation(request_details = nil)
  post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/long-form-contacts")
  post_stub.with(body: { long_form_contact: request_details }) unless request_details.nil?
  post_stub.to_return(status: 202)
end

#stub_support_api_mark_reviewed_for_spam(request_details = nil, response_body = {}) ⇒ Object


59
60
61
62
63
# File 'lib/gds_api/test_helpers/support_api.rb', line 59

def stub_support_api_mark_reviewed_for_spam(request_details = nil, response_body = {})
  post_stub = stub_http_request(:put, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/problem-reports/mark-reviewed-for-spam")
  post_stub.with(body: { reviewed_problem_report_ids: request_details }) unless request_details.nil?
  post_stub.to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_organisation(slug = "cabinet-office", response_body = nil) ⇒ Object


104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/gds_api/test_helpers/support_api.rb', line 104

def stub_support_api_organisation(slug = "cabinet-office", response_body = nil)
  response_body ||= {
    slug: slug,
    web_url: "https://www.gov.uk/government/organisations/#{slug}",
    title: "Cabinet Office",
    acronym: "CO",
    govuk_status: "live"
  }

  stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/organisations/#{slug}").
    to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_organisations_list(response_body = nil) ⇒ Object


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/gds_api/test_helpers/support_api.rb', line 82

def stub_support_api_organisations_list(response_body = nil)
  response_body ||= [
    {
      slug: "cabinet-office",
      web_url: "https://www.gov.uk/government/organisations/cabinet-office",
      title: "Cabinet Office",
      acronym: "CO",
      govuk_status: "live"
    },
    {
      slug: "gds",
      web_url: "https://www.gov.uk/government/organisations/gds",
      title: "Government Digital Service",
      acronym: "GDS",
      govuk_status: "live"
    }
  ]

  stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/organisations").
    to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_problem_report_creation(request_details = nil) ⇒ Object


9
10
11
12
13
# File 'lib/gds_api/test_helpers/support_api.rb', line 9

def stub_support_api_problem_report_creation(request_details = nil)
  post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/problem-reports")
  post_stub.with(body: { problem_report: request_details }) unless request_details.nil?
  post_stub.to_return(status: 202)
end

#stub_support_api_problem_report_daily_totals_for(date, expected_results = nil) ⇒ Object


45
46
47
48
49
50
51
# File 'lib/gds_api/test_helpers/support_api.rb', line 45

def stub_support_api_problem_report_daily_totals_for(date, expected_results = nil)
  date_string = date.strftime("%Y-%m-%d")
  get_stub = stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/problem-reports/#{date_string}/totals")
  response = { status: 200 }
  response[:body] = expected_results if expected_results
  get_stub.to_return(response)
end

#stub_support_api_problem_reports(params, response_body = {}) ⇒ Object


53
54
55
56
57
# File 'lib/gds_api/test_helpers/support_api.rb', line 53

def stub_support_api_problem_reports(params, response_body = {})
  stub_http_request(:get, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/problem-reports").
    with(query: params).
    to_return(status: 200, body: response_body.to_json)
end

#stub_support_api_service_feedback_creation(feedback_details = nil) ⇒ Object


15
16
17
18
19
# File 'lib/gds_api/test_helpers/support_api.rb', line 15

def stub_support_api_service_feedback_creation(feedback_details = nil)
  post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/anonymous-feedback/service-feedback")
  post_stub.with(body: { service_feedback: feedback_details }) unless feedback_details.nil?
  post_stub.to_return(status: 201)
end

#support_api_isnt_availableObject


65
66
67
# File 'lib/gds_api/test_helpers/support_api.rb', line 65

def support_api_isnt_available
  stub_request(:post, /#{SUPPORT_API_ENDPOINT}\/.*/).to_return(status: 503)
end