|
312 | 312 | expect(ci_job.reload.stage).not_to be_nil
|
313 | 313 | end
|
314 | 314 | end
|
| 315 | + |
| 316 | + context 'when the current stage is cancelled' do |
| 317 | + let(:stage) { create(:stage, :cancelled, check_suite: check_suite) } |
| 318 | + let(:ci_job) { create(:ci_job, stage: stage, check_suite: check_suite) } |
| 319 | + |
| 320 | + before do |
| 321 | + ci_job |
| 322 | + end |
| 323 | + |
| 324 | + it 'does not update the stage' do |
| 325 | + expect { summary.build_summary }.not_to(change { stage.reload.status }) |
| 326 | + end |
| 327 | + end |
| 328 | + |
| 329 | + context 'when stage does not exists' do |
| 330 | + let(:ci_job) { create(:ci_job, stage: nil, check_suite: check_suite) } |
| 331 | + let(:stage_configuration) { create(:stage_configuration, bamboo_stage_name: 'D', position: 1) } |
| 332 | + |
| 333 | + let(:current_stage) do |
| 334 | + create(:stage, name: 'B', check_suite: check_suite, configuration: create(:stage_configuration, position: 1)) |
| 335 | + end |
| 336 | + |
| 337 | + let(:job_info) do |
| 338 | + [ |
| 339 | + { |
| 340 | + name: ci_job.name, |
| 341 | + stage: 'D' |
| 342 | + } |
| 343 | + ] |
| 344 | + end |
| 345 | + |
| 346 | + before do |
| 347 | + allow(BambooCi::RunningPlan).to receive(:fetch).and_return(job_info) |
| 348 | + ci_job |
| 349 | + stage_configuration |
| 350 | + end |
| 351 | + |
| 352 | + it 'must create a new stage' do |
| 353 | + summary.build_summary |
| 354 | + expect(Stage.all.pluck(:name)).to include('D') |
| 355 | + end |
| 356 | + end |
| 357 | + |
| 358 | + context 'when the current stage is not mandatory and fails' do |
| 359 | + let(:stage1) { create(:stage, :build, check_suite: check_suite) } |
| 360 | + let(:stage2) { create(:stage, check_suite: check_suite) } |
| 361 | + let(:ci_job) { create(:ci_job, :failure, stage: stage1, check_suite: check_suite) } |
| 362 | + let(:ci_job2) { create(:ci_job, stage: stage2, check_suite: check_suite) } |
| 363 | + |
| 364 | + before do |
| 365 | + stage1.configuration.update(mandatory: false, position: 1) |
| 366 | + stage2.configuration.update(position: 2) |
| 367 | + |
| 368 | + ci_job |
| 369 | + ci_job2 |
| 370 | + summary.build_summary |
| 371 | + end |
| 372 | + |
| 373 | + it 'does not cancel the next stage' do |
| 374 | + expect(stage1.reload.status).to eq('failure') |
| 375 | + expect(stage2.reload.status).to eq('queued') |
| 376 | + end |
| 377 | + end |
| 378 | + |
| 379 | + context 'when the current stage is mandatory and succeeds' do |
| 380 | + let(:stage1) { create(:stage, :build, check_suite: check_suite) } |
| 381 | + let(:stage2) { create(:stage, check_suite: check_suite) } |
| 382 | + let(:ci_job) { create(:ci_job, :success, stage: stage1, check_suite: check_suite) } |
| 383 | + let(:ci_job2) { create(:ci_job, stage: stage2, check_suite: check_suite) } |
| 384 | + |
| 385 | + before do |
| 386 | + stage1.configuration.update(mandatory: true, position: 1) |
| 387 | + stage2.configuration.update(position: 2) |
| 388 | + |
| 389 | + ci_job |
| 390 | + ci_job2 |
| 391 | + summary.build_summary |
| 392 | + end |
| 393 | + |
| 394 | + it 'marks the next stage as in_progress' do |
| 395 | + expect(stage1.reload.status).to eq('success') |
| 396 | + expect(stage2.reload.status).to eq('in_progress') |
| 397 | + end |
| 398 | + end |
| 399 | + |
| 400 | + context 'when has a checkout message' do |
| 401 | + let(:stage) { create(:stage, :build, check_suite: check_suite) } |
| 402 | + let(:ci_job) do |
| 403 | + create(:ci_job, :success, stage: stage, check_suite: check_suite, name: 'Sourcecode', summary: 'HI') |
| 404 | + end |
| 405 | + let(:message) do |
| 406 | + "Sourcecode -> https://ci1.netdef.org/browse/#{ci_job.job_ref}\n```\nHI\n```" |
| 407 | + end |
| 408 | + |
| 409 | + it 'must update stage' do |
| 410 | + expect(summary.send(:generate_message, 'source', ci_job)).to include(message) |
| 411 | + end |
| 412 | + end |
| 413 | + |
| 414 | + context 'when has not a checkout message' do |
| 415 | + let(:stage) { create(:stage, :build, check_suite: check_suite) } |
| 416 | + let(:ci_job) do |
| 417 | + create(:ci_job, :success, stage: stage, check_suite: check_suite, name: 'Sourcecode') |
| 418 | + end |
| 419 | + let(:message) do |
| 420 | + "Sourcecode -> https://ci1.netdef.org/browse/#{ci_job.job_ref}\n```\nHI\n```" |
| 421 | + end |
| 422 | + |
| 423 | + it 'must update stage' do |
| 424 | + expect(summary.send(:generate_message, 'source', ci_job)).not_to include(message) |
| 425 | + end |
| 426 | + end |
315 | 427 | end
|
0 commit comments