Add new tests
This commit is contained in:
parent
55c61d2e41
commit
1ac0639677
|
@ -11,6 +11,9 @@ describe Projects::MattermostsController do
|
|||
|
||||
describe 'GET #new' do
|
||||
before do
|
||||
allow_any_instance_of(MattermostSlashCommandsService).
|
||||
to receive(:list_teams).and_return([])
|
||||
|
||||
get(:new,
|
||||
namespace_id: project.namespace.to_param,
|
||||
project_id: project.to_param)
|
||||
|
@ -33,7 +36,9 @@ describe Projects::MattermostsController do
|
|||
|
||||
context 'no request can be made to mattermost' do
|
||||
it 'shows the error' do
|
||||
expect(controller).to set_flash[:alert].to /\AFailed to open TCP connection to/
|
||||
allow_any_instance_of(MattermostSlashCommandsService).to receive(:configure).and_return([false, "error message"])
|
||||
|
||||
expect(subject).to redirect_to(new_namespace_project_mattermost_url(project.namespace, project))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mattermost::Client do
|
||||
let(:user) { build(:user) }
|
||||
|
||||
subject { described_class.new(user) }
|
||||
|
||||
context 'JSON parse error' do
|
||||
before do
|
||||
Struct.new("Request", :body, :success?)
|
||||
end
|
||||
|
||||
it 'yields an error on malformed JSON' do
|
||||
bad_json = Struct::Request.new("I'm not json", true)
|
||||
expect { subject.send(:json_response, bad_json) }.to raise_error(Mattermost::ClientError)
|
||||
end
|
||||
|
||||
it 'shows a client error if the request was unsuccessful' do
|
||||
bad_request = Struct::Request.new("true", false)
|
||||
|
||||
expect { subject.send(:json_response, bad_request) }.to raise_error(Mattermost::ClientError)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -95,5 +95,29 @@ describe Mattermost::Session, type: :request do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with lease' do
|
||||
before do
|
||||
allow(subject).to receive(:lease_try_obtain).and_return('aldkfjsldfk')
|
||||
end
|
||||
|
||||
it 'tries to obtain a lease' do
|
||||
expect(subject).to receive(:lease_try_obtain)
|
||||
expect(Gitlab::ExclusiveLease).to receive(:cancel)
|
||||
|
||||
# Cannot setup a session, but we should still cancel the lease
|
||||
expect { subject.with_session }.to raise_error(Mattermost::NoSessionError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'without lease' do
|
||||
before do
|
||||
allow(subject).to receive(:lease_try_obtain).and_return(nil)
|
||||
end
|
||||
|
||||
it 'returns a NoSessionError error' do
|
||||
expect { subject.with_session }.to raise_error(Mattermost::NoSessionError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue