builds_email_service_spec.rb 1.37 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

describe BuildsEmailService do
  let(:build) { create(:ci_build) }
  let(:data) { Gitlab::BuildDataBuilder.build(build) }
  let(:service) { BuildsEmailService.new }

  describe :execute do
9
    it 'sends email' do
10 11 12 13 14 15
      service.recipients = 'test@gitlab.com'
      data[:build_status] = 'failed'
      expect(BuildEmailWorker).to receive(:perform_async)
      service.execute(data)
    end

16 17 18 19 20 21 22 23
    it 'does not send email with succeeded build and notify_only_broken_builds on' do
      expect(service).to receive(:notify_only_broken_builds).and_return(true)
      data[:build_status] = 'success'
      expect(BuildEmailWorker).not_to receive(:perform_async)
      service.execute(data)
    end

    it 'does not send email with failed build and build_allow_failure is true' do
24 25 26 27 28
      data[:build_status] = 'failed'
      data[:build_allow_failure] = true
      expect(BuildEmailWorker).not_to receive(:perform_async)
      service.execute(data)
    end
29 30 31 32 33 34 35 36 37 38 39 40 41

    it 'does not send email with unknown build status' do
      data[:build_status] = 'foo'
      expect(BuildEmailWorker).not_to receive(:perform_async)
      service.execute(data)
    end

    it 'does not send email when recipients list is empty' do
      service.recipients = ' ,, '
      data[:build_status] = 'failed'
      expect(BuildEmailWorker).not_to receive(:perform_async)
      service.execute(data)
    end
42 43
  end
end