Skip to content
代码片段 群组 项目
未验证 提交 483d6c59 编辑于 作者: Max Fan's avatar Max Fan 提交者: GitLab
浏览文件

Merge branch 'ia-async-spam-trust-scores' into 'master'

Refactor spam scores to use Abuse::TrustScoreWorker

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/140397



Merged-by: default avatarMax Fan <mfan@gitlab.com>
Approved-by: default avatarHinam Mehra <hmehra@gitlab.com>
Approved-by: default avatarMax Fan <mfan@gitlab.com>
Reviewed-by: default avatarIan Anderson <ianderson@gitlab.com>
Reviewed-by: default avatarMax Fan <mfan@gitlab.com>
Co-authored-by: default avatarimand3r <ianderson@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -70,7 +70,8 @@ def get_spamcheck_verdict
result = spamcheck_client.spam?(spammable: target, user: user, context: context, extra_features: extra_features)
if result.evaluated?
Abuse::TrustScore.create!(user: user, score: result.score, source: :spamcheck)
correlation_id = Labkit::Correlation::CorrelationId.current_id || ''
Abuse::TrustScoreWorker.perform_async(user.id, :spamcheck, result.score, correlation_id)
end
result.verdict
......
......@@ -263,11 +263,10 @@
end
context 'if the endpoint is accessible' do
let(:user_scores) { Abuse::UserTrustScore.new(user) }
before do
allow(service).to receive(:spamcheck_client).and_return(spam_client)
allow(spam_client).to receive(:spam?).and_return(spam_client_result)
allow(Labkit::Correlation::CorrelationId).to receive(:current_id).and_return('cid')
end
context 'if the result is a NOOP verdict' do
......@@ -275,8 +274,8 @@
let(:verdict_value) { ::Spamcheck::SpamVerdict::Verdict::NOOP }
it 'returns the verdict' do
expect(Abuse::TrustScoreWorker).not_to receive(:perform_async)
is_expected.to eq(NOOP)
expect(user_scores.spam_score).to eq(0.0)
end
end
......@@ -286,8 +285,8 @@
context 'the result was evaluated' do
it 'returns the verdict and updates the spam score' do
expect(Abuse::TrustScoreWorker).to receive(:perform_async).once.with(user.id, :spamcheck, instance_of(Float), 'cid')
is_expected.to eq(ALLOW)
expect(user_scores.spam_score).to be_within(0.000001).of(verdict_score)
end
end
......@@ -295,8 +294,8 @@
let(:verdict_evaluated) { false }
it 'returns the verdict and does not update the spam score' do
expect(Abuse::TrustScoreWorker).not_to receive(:perform_async)
expect(subject).to eq(ALLOW)
expect(user_scores.spam_score).to eq(0.0)
end
end
end
......@@ -317,8 +316,8 @@
with_them do
it "returns expected spam constant and updates the spam score" do
expect(Abuse::TrustScoreWorker).to receive(:perform_async).once.with(user.id, :spamcheck, instance_of(Float), 'cid')
is_expected.to eq(expected)
expect(user_scores.spam_score).to be_within(0.000001).of(verdict_score)
end
end
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册