diff options
Diffstat (limited to 'spec/lib/gitlab/danger/teammate_spec.rb')
-rw-r--r-- | spec/lib/gitlab/danger/teammate_spec.rb | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/spec/lib/gitlab/danger/teammate_spec.rb b/spec/lib/gitlab/danger/teammate_spec.rb index ca036390bde..bd1c2b10dc8 100644 --- a/spec/lib/gitlab/danger/teammate_spec.rb +++ b/spec/lib/gitlab/danger/teammate_spec.rb @@ -2,11 +2,14 @@ require 'fast_spec_helper' +require 'rspec-parameterized' + require 'gitlab/danger/teammate' describe Gitlab::Danger::Teammate do - subject { described_class.new(options) } - let(:options) { { 'projects' => projects, 'role' => role } } + subject { described_class.new(options.stringify_keys) } + + let(:options) { { username: 'luigi', projects: projects, role: role } } let(:projects) { { project => capabilities } } let(:role) { 'Engineer, Manage' } let(:labels) { [] } @@ -95,4 +98,72 @@ describe Gitlab::Danger::Teammate do expect(subject.maintainer?(project, :frontend, labels)).to be_falsey end end + + describe '#status' do + let(:capabilities) { ['dish washing'] } + + context 'with empty cache' do + context 'for successful request' do + it 'returns the response' do + mock_status = double(does_not: 'matter') + expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json) + .and_return(mock_status) + + expect(subject.status).to be mock_status + end + end + + context 'for failing request' do + it 'returns nil' do + expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json) + .and_raise(Gitlab::Danger::RequestHelper::HTTPError.new) + + expect(subject.status).to be nil + end + end + end + + context 'with filled cache' do + it 'returns the cached response' do + mock_status = double(does_not: 'matter') + expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json) + .and_return(mock_status) + subject.status + + expect(Gitlab::Danger::RequestHelper).not_to receive(:http_get_json) + expect(subject.status).to be mock_status + end + end + end + + describe '#available?' do + using RSpec::Parameterized::TableSyntax + + let(:capabilities) { ['dry head'] } + + where(:status, :result) do + {} | true + { message: 'dear reader' } | true + { message: 'OOO: massage' } | false + { message: 'love it SOOO much' } | false + { emoji: 'red_circle' } | false + end + + with_them do + before do + expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json) + .and_return(status&.stringify_keys) + end + + it { expect(subject.available?).to be result } + end + + it 'returns true if request fails' do + expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json) + .exactly(2).times + .and_raise(Gitlab::Danger::RequestHelper::HTTPError.new) + + expect(subject.available?).to be true + end + end end |