error_tracking_shared_context.rb 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# frozen_string_literal: true

shared_context 'sentry error tracking context feature' do
  include ReactiveCachingHelpers

  let_it_be(:project) { create(:project) }
  let_it_be(:project_error_tracking_settings) { create(:project_error_tracking_setting, project: project) }
  let_it_be(:issue_response_body) { fixture_file('sentry/issue_sample_response.json') }
  let_it_be(:issue_response) { JSON.parse(issue_response_body) }
  let_it_be(:event_response_body) { fixture_file('sentry/issue_latest_event_sample_response.json') }
  let_it_be(:event_response) { JSON.parse(event_response_body) }
  let(:sentry_api_urls) { Sentry::ApiUrls.new(project_error_tracking_settings.api_url) }
  let(:issue_id) { issue_response['id'] }
14 15 16
  let(:issue_seen) { 1.year.ago.utc }
  let(:formatted_issue_seen) { issue_seen.strftime("%Y-%m-%d %I:%M:%S%p %Z") }
  let(:date_received) { 1.month.ago.utc }
17 18 19 20

  before do
    request_headers = { 'Authorization' => 'Bearer access_token_123', 'Content-Type' => 'application/json' }
    response_headers = { 'Content-Type' => 'application/json' }
21 22 23 24 25

    issue_response['firstSeen'] = issue_seen.iso8601(6)
    issue_response['lastSeen'] = issue_seen.iso8601(6)
    event_response['dateReceived'] = date_received.iso8601(6)

26 27 28
    issue_url = sentry_api_urls.issue_url(issue_id).to_s
    stub_request(:get, issue_url)
      .with(headers: request_headers)
29
      .to_return(status: 200, body: issue_response.to_json, headers: response_headers)
30 31 32
    event_url = sentry_api_urls.issue_latest_event_url(issue_id).to_s
    stub_request(:get, event_url)
      .with(headers: request_headers)
33
      .to_return(status: 200, body: event_response.to_json, headers: response_headers)
34 35
  end
end