diff options
Diffstat (limited to 'spec/workers/abuse/trust_score_worker_spec.rb')
-rw-r--r-- | spec/workers/abuse/trust_score_worker_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/workers/abuse/trust_score_worker_spec.rb b/spec/workers/abuse/trust_score_worker_spec.rb new file mode 100644 index 00000000000..adc582ada94 --- /dev/null +++ b/spec/workers/abuse/trust_score_worker_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Abuse::TrustScoreWorker, :clean_gitlab_redis_shared_state, feature_category: :instance_resiliency do + let(:worker) { described_class.new } + let_it_be(:user) { create(:user) } + + subject(:perform) { worker.perform(user.id, :telesign, 0.85, 'foo') } + + it_behaves_like 'an idempotent worker' do + let(:job_args) { [user.id, :telesign, 0.5] } + end + + context "when the user does not exist" do + let(:log_payload) { { 'message' => 'User not found.', 'user_id' => user.id } } + + before do + allow(User).to receive(:find_by_id).with(user.id).and_return(nil) + end + + it 'logs an error' do + expect(Sidekiq.logger).to receive(:info).with(hash_including(log_payload)) + + expect { perform }.not_to raise_exception + end + + it 'does not attempt to create the trust score' do + expect(Abuse::TrustScore).not_to receive(:create!) + + perform + end + end + + context "when the user exists" do + it 'creates an abuse trust score with the correct data' do + expect { perform }.to change { Abuse::TrustScore.count }.from(0).to(1) + expect(Abuse::TrustScore.last.attributes).to include({ + user_id: user.id, + source: "telesign", + score: 0.85, + correlation_id_value: 'foo' + }.stringify_keys) + end + end +end |