Skip to content

Commit

Permalink
Finished
Browse files Browse the repository at this point in the history
Increasing code coverage

Signed-off-by: Rodrigo Nardi <[email protected]>
  • Loading branch information
RodrigoMNardi committed May 31, 2024
1 parent b4029fc commit 8bc98d8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ SimpleCov.start do
enable_coverage :branch
primary_coverage :branch
add_filter %r{^/spec/}
add_filter 'database_loader.rb'
add_group 'Models', 'lib/models'
add_group 'GitHub Functions', 'lib/github'
add_group 'Bamboo CI Functions', 'lib/bamboo_ci'
add_group 'Helpers', 'lib/helpers'
add_group 'Others', %w[app/ database_loader.rb]
add_group 'Others', %w[app/]

minimum_coverage_by_file line: 90, branch: 90
end
2 changes: 1 addition & 1 deletion lib/github/plan_execution/finished.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def slack_notify_cancelled(job)
def check_stages
github_check = Github::Check.new(@check_suite)
@logger.info ">>> @result: #{@result.inspect}"
return if @result.nil? or @result.empty? or @result['status-code'] == 404
return if @result.nil? or @result.empty? or @result['status-code']&.between?(400, 500)

@result.dig('stages', 'stage').each do |stage|
stage.dig('results', 'result').each do |result|
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/check_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@
create_list(:ci_job, 5, check_suite: check_suite, stage: stage, status: 1)
end
end

trait :with_stages do
after(:create) do |check_suite|
create(:stage, check_suite: check_suite)
end
end
end
end
50 changes: 50 additions & 0 deletions spec/lib/github/plan_execution/finished_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,56 @@
end

describe 'Finishing execution' do
context 'when receives a valid payload - but stages does not have tests' do
let(:check_suite) { create(:check_suite, :with_stages) }
let(:status) { 200 }
let(:body) do
{
'stages' => {
'stage' => [
'results' => {
'result' =>
check_suite.ci_jobs.map { |job| { 'buildResultKey' => job.job_ref, 'state' => 'Successful' } }
}
]
}
}
end
let(:payload) { { 'bamboo_ref' => check_suite.bamboo_ci_ref } }

it 'must returns error' do
expect(pla_exec.finished).to eq([200, 'Finished'])
end
end

context 'when receives a valid payload - but result has error' do
let(:status) { 200 }
let(:body) do
{
'status-code' => 400
}
end
let(:payload) { { 'bamboo_ref' => check_suite.bamboo_ci_ref } }

before do
stub_request(:get, url)
.with(
headers: {
'Accept' => %w[*/* application/json],
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization' => 'Basic dXNlcjpwYXNzd29yZA==',
'Host' => '127.0.0.1',
'User-Agent' => 'Ruby'
}
)
.to_return(status: status, body: body.to_json, headers: {})
end

it 'must returns error' do
expect(pla_exec.finished).to eq([200, 'Finished'])
end
end

context 'when receives a valid payload - Successful' do
let(:status) { 200 }
let(:body) do
Expand Down

0 comments on commit 8bc98d8

Please sign in to comment.