2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-15 06:33:48 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe RemoteMirrorNotificationWorker, :mailer do
|
2020-02-25 03:08:49 +00:00
|
|
|
let_it_be(:project) { create(:project, :repository, :remote_mirror) }
|
|
|
|
let_it_be(:mirror) { project.remote_mirrors.first }
|
2019-01-15 06:33:48 +00:00
|
|
|
|
2020-08-26 06:10:34 +00:00
|
|
|
describe '#perform' do
|
2019-01-15 06:33:48 +00:00
|
|
|
it 'calls NotificationService#remote_mirror_update_failed when the mirror exists' do
|
|
|
|
mirror.update_column(:last_error, "There was a problem fetching")
|
|
|
|
|
|
|
|
expect(NotificationService).to receive_message_chain(:new, :remote_mirror_update_failed)
|
|
|
|
|
|
|
|
subject.perform(mirror.id)
|
|
|
|
|
|
|
|
expect(mirror.reload.error_notification_sent?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing when the mirror has no errors' do
|
|
|
|
expect(NotificationService).not_to receive(:new)
|
|
|
|
|
|
|
|
subject.perform(mirror.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing when the mirror does not exist' do
|
|
|
|
expect(NotificationService).not_to receive(:new)
|
|
|
|
|
2020-04-01 15:07:45 +00:00
|
|
|
subject.perform(non_existing_record_id)
|
2019-01-15 06:33:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing when a notification has already been sent' do
|
|
|
|
mirror.update_columns(last_error: "There was a problem fetching",
|
|
|
|
error_notification_sent: true)
|
|
|
|
|
|
|
|
expect(NotificationService).not_to receive(:new)
|
|
|
|
|
|
|
|
subject.perform(mirror.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|