Commit ed459753 authored by Nick Thomas's avatar Nick Thomas

Stop using HipChat in the ServicesController spec

parent 099777a3
...@@ -3,9 +3,8 @@ require 'spec_helper' ...@@ -3,9 +3,8 @@ require 'spec_helper'
describe Projects::ServicesController do describe Projects::ServicesController do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:service) { create(:hipchat_service, project: project) } let(:service) { create(:jira_service, project: project) }
let(:hipchat_client) { { '#room' => double(send: true) } } let(:service_params) { { username: 'username', password: 'password', url: 'http://example.com' } }
let(:service_params) { { token: 'hipchat_token_p', room: '#room' } }
before do before do
sign_in(user) sign_in(user)
...@@ -24,13 +23,13 @@ describe Projects::ServicesController do ...@@ -24,13 +23,13 @@ describe Projects::ServicesController do
end end
context 'when validations fail' do context 'when validations fail' do
let(:service_params) { { active: 'true', token: '' } } let(:service_params) { { active: 'true', url: '' } }
it 'returns error messages in JSON response' do it 'returns error messages in JSON response' do
put :test, namespace_id: project.namespace, project_id: project, id: :hipchat, service: service_params put :test, namespace_id: project.namespace, project_id: project, id: service.to_param, service: service_params
expect(json_response['message']).to eq "Validations failed." expect(json_response['message']).to eq "Validations failed."
expect(json_response['service_response']).to eq "Token can't be blank" expect(json_response['service_response']).to include "Url can't be blank"
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
end end
...@@ -52,7 +51,8 @@ describe Projects::ServicesController do ...@@ -52,7 +51,8 @@ describe Projects::ServicesController do
end end
it 'returns success' do it 'returns success' do
expect(HipChat::Client).to receive(:new).with('hipchat_token_p', anything).and_return(hipchat_client) stub_request(:get, 'http://example.com/rest/api/2/serverInfo')
.to_return(status: 200, body: '{}')
put :test, namespace_id: project.namespace, project_id: project, id: service.to_param, service: service_params put :test, namespace_id: project.namespace, project_id: project, id: service.to_param, service: service_params
...@@ -61,7 +61,8 @@ describe Projects::ServicesController do ...@@ -61,7 +61,8 @@ describe Projects::ServicesController do
end end
it 'returns success' do it 'returns success' do
expect(HipChat::Client).to receive(:new).with('hipchat_token_p', anything).and_return(hipchat_client) stub_request(:get, 'http://example.com/rest/api/2/serverInfo')
.to_return(status: 200, body: '{}')
put :test, namespace_id: project.namespace, project_id: project, id: service.to_param, service: service_params put :test, namespace_id: project.namespace, project_id: project, id: service.to_param, service: service_params
...@@ -76,12 +77,16 @@ describe Projects::ServicesController do ...@@ -76,12 +77,16 @@ describe Projects::ServicesController do
it 'persist the object' do it 'persist the object' do
do_put do_put
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_empty
expect(BuildkiteService.first).to be_present expect(BuildkiteService.first).to be_present
end end
it 'creates the ServiceHook object' do it 'creates the ServiceHook object' do
do_put do_put
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_empty
expect(BuildkiteService.first.service_hook).to be_present expect(BuildkiteService.first.service_hook).to be_present
end end
...@@ -96,13 +101,18 @@ describe Projects::ServicesController do ...@@ -96,13 +101,18 @@ describe Projects::ServicesController do
context 'failure' do context 'failure' do
it 'returns success status code and the error message' do it 'returns success status code and the error message' do
expect(HipChat::Client).to receive(:new).with('hipchat_token_p', anything).and_raise('Bad test') stub_request(:get, 'http://example.com/rest/api/2/serverInfo')
.to_return(status: 404)
put :test, namespace_id: project.namespace, project_id: project, id: service.to_param, service: service_params put :test, namespace_id: project.namespace, project_id: project, id: service.to_param, service: service_params
expect(response.status).to eq(200) expect(response).to have_gitlab_http_status(200)
expect(JSON.parse(response.body)) expect(json_response).to eq(
.to eq('error' => true, 'message' => 'Test failed.', 'service_response' => 'Bad test', 'test_failed' => true) 'error' => true,
'message' => 'Test failed.',
'service_response' => '',
'test_failed' => true
)
end end
end end
end end
...@@ -114,7 +124,7 @@ describe Projects::ServicesController do ...@@ -114,7 +124,7 @@ describe Projects::ServicesController do
namespace_id: project.namespace, project_id: project, id: service.to_param, service: { active: true } namespace_id: project.namespace, project_id: project, id: service.to_param, service: { active: true }
expect(response).to redirect_to(project_settings_integrations_path(project)) expect(response).to redirect_to(project_settings_integrations_path(project))
expect(flash[:notice]).to eq 'HipChat activated.' expect(flash[:notice]).to eq 'JIRA activated.'
end end
end end
...@@ -123,7 +133,7 @@ describe Projects::ServicesController do ...@@ -123,7 +133,7 @@ describe Projects::ServicesController do
put :update, put :update,
namespace_id: project.namespace, project_id: project, id: service.to_param, service: { active: false } namespace_id: project.namespace, project_id: project, id: service.to_param, service: { active: false }
expect(flash[:notice]).to eq 'HipChat settings saved, but not activated.' expect(flash[:notice]).to eq 'JIRA settings saved, but not activated.'
end end
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