Commit ee49887f authored by Vitali Tatarintev's avatar Vitali Tatarintev

Refactor StackTracesController specs

* Rearrange tests
* Remove duplication by extracting into before block
parent 2a485759
......@@ -12,8 +12,7 @@ describe Projects::ErrorTracking::StackTracesController do
end
describe 'GET #index' do
let_it_be(:issue_id) { 1234 }
let(:issue_id) { 1234 }
let(:issue_stack_trace_service) { spy(:issue_stack_trace_service) }
subject(:get_stack_trace) do
......@@ -24,33 +23,28 @@ describe Projects::ErrorTracking::StackTracesController do
expect(ErrorTracking::IssueLatestEventService)
.to receive(:new).with(project, user, issue_id: issue_id.to_s)
.and_return(issue_stack_trace_service)
expect(issue_stack_trace_service).to receive(:execute).and_return(service_response)
get_stack_trace
end
context 'awaiting data' do
before do
expect(issue_stack_trace_service).to receive(:execute)
.and_return(status: :error, http_status: :no_content)
end
it 'returns no data' do
get_stack_trace
let(:service_response) { { status: :error, http_status: :no_content }}
it 'responds with no data' do
expect(response).to have_gitlab_http_status(:no_content)
end
end
context 'service result is successful' do
before do
expect(issue_stack_trace_service).to receive(:execute)
.and_return(status: :success, latest_event: error_event)
get_stack_trace
end
let(:service_response) { { status: :success, latest_event: error_event } }
let(:error_event) { build(:error_tracking_error_event) }
it 'returns an error' do
it 'responds with success' do
expect(response).to have_gitlab_http_status(:ok)
end
it 'responds with error' do
expect(response).to match_response_schema('error_tracking/issue_stack_trace')
end
......@@ -65,34 +59,26 @@ describe Projects::ErrorTracking::StackTracesController do
let(:error_message) { 'error message' }
context 'without http_status' do
before do
expect(issue_stack_trace_service).to receive(:execute)
.and_return(status: :error, message: error_message)
end
it 'returns 400 with message' do
get_stack_trace
let(:service_response) { { status: :error, message: error_message } }
it 'responds with bad request' do
expect(response).to have_gitlab_http_status(:bad_request)
end
it 'responds with error message' do
expect(json_response['message']).to eq(error_message)
end
end
context 'with explicit http_status' do
let(:http_status) { :no_content }
let(:service_response) { { status: :error, message: error_message, http_status: http_status } }
before do
expect(issue_stack_trace_service).to receive(:execute).and_return(
status: :error,
message: error_message,
http_status: http_status
)
it 'responds with custom http status' do
expect(response).to have_gitlab_http_status(http_status)
end
it 'returns http_status with message' do
get_stack_trace
expect(response).to have_gitlab_http_status(http_status)
it 'responds with error message' do
expect(json_response['message']).to eq(error_message)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment