diff options
Diffstat (limited to 'spec/support/helpers')
-rw-r--r-- | spec/support/helpers/features/notes_helpers.rb | 8 | ||||
-rw-r--r-- | spec/support/helpers/graphql_helpers.rb | 8 | ||||
-rw-r--r-- | spec/support/helpers/prometheus_helpers.rb | 8 | ||||
-rw-r--r-- | spec/support/helpers/stub_requests.rb | 13 |
4 files changed, 35 insertions, 2 deletions
diff --git a/spec/support/helpers/features/notes_helpers.rb b/spec/support/helpers/features/notes_helpers.rb index a2d8d71b541..8c27f81930d 100644 --- a/spec/support/helpers/features/notes_helpers.rb +++ b/spec/support/helpers/features/notes_helpers.rb @@ -23,6 +23,14 @@ module Spec end end + def edit_note(note_text_to_edit, new_note_text) + page.within('#notes-list li.note', text: note_text_to_edit) do + find('.js-note-edit').click + fill_in('note[note]', with: new_note_text) + find('.js-comment-button').click + end + end + def preview_note(text) page.within('.js-main-target-form') do filled_text = fill_in('note[note]', with: text) diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index ae1b859ae3f..d86371d70b9 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -3,6 +3,8 @@ module GraphqlHelpers MutationDefinition = Struct.new(:query, :variables) + NoData = Class.new(StandardError) + # makes an underscored string look like a fieldname # "merge_request" => "mergeRequest" def self.fieldnamerize(underscored_field_name) @@ -158,8 +160,9 @@ module GraphqlHelpers post_graphql(mutation.query, current_user: current_user, variables: mutation.variables) end + # Raises an error if no data is found def graphql_data - json_response['data'] + json_response['data'] || (raise NoData, graphql_errors) end def graphql_errors @@ -173,8 +176,9 @@ module GraphqlHelpers end end + # Raises an error if no response is found def graphql_mutation_response(mutation_name) - graphql_data[GraphqlHelpers.fieldnamerize(mutation_name)] + graphql_data.fetch(GraphqlHelpers.fieldnamerize(mutation_name)) end def nested_fields?(field) diff --git a/spec/support/helpers/prometheus_helpers.rb b/spec/support/helpers/prometheus_helpers.rb index 4d39d9df494..7c03746a395 100644 --- a/spec/support/helpers/prometheus_helpers.rb +++ b/spec/support/helpers/prometheus_helpers.rb @@ -76,6 +76,14 @@ module PrometheusHelpers WebMock.stub_request(:any, /prometheus.example.com/) end + def stub_any_prometheus_request_with_response(status: 200, headers: {}, body: nil) + stub_any_prometheus_request.to_return({ + status: status, + headers: { 'Content-Type' => 'application/json' }.merge(headers), + body: body || prometheus_values_body.to_json + }) + end + def stub_all_prometheus_requests(environment_slug, body: nil, status: 200) stub_prometheus_request( prometheus_query_with_time_url(prometheus_memory_query(environment_slug), Time.now.utc), diff --git a/spec/support/helpers/stub_requests.rb b/spec/support/helpers/stub_requests.rb index 6eb8007ed26..473f07dd413 100644 --- a/spec/support/helpers/stub_requests.rb +++ b/spec/support/helpers/stub_requests.rb @@ -28,6 +28,19 @@ module StubRequests .and_return([addr]) end + def stub_all_dns(url, ip_address:) + url = URI(url) + port = 80 # arbitarily chosen, does not matter as we are not going to connect + socket = Socket.sockaddr_in(port, ip_address) + addr = Addrinfo.new(socket) + + # See Gitlab::UrlBlocker + allow(Addrinfo).to receive(:getaddrinfo).and_call_original + allow(Addrinfo).to receive(:getaddrinfo) + .with(url.hostname, anything, nil, :STREAM) + .and_return([addr]) + end + def stubbed_hostname(url, hostname: IP_ADDRESS_STUB) url = parse_url(url) url.hostname = hostname |