about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorStanislav Dobrovolschii <uusername@protonmail.ch>2023-03-02 10:05:05 +0100
committerGitHub <noreply@github.com>2023-03-02 10:05:05 +0100
commitd9271126ce9f1d270b7e1af9692b4622d987a1af (patch)
tree2047b7434f68fc6ed261a1ab94d5663c3d4a598a /spec
parentb6602f68eb0dbe07ee2e9b8fb27ee048037c414e (diff)
Add rspecs for FollowRecommendationsScheduler (#23890)
Diffstat (limited to 'spec')
-rw-r--r--spec/fabricators/user_fabricator.rb3
-rw-r--r--spec/workers/scheduler/follow_recommendations_scheduler_spec.rb43
2 files changed, 45 insertions, 1 deletions
diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb
index 967347319..9031d5cd0 100644
--- a/spec/fabricators/user_fabricator.rb
+++ b/spec/fabricators/user_fabricator.rb
@@ -5,5 +5,6 @@ Fabricator(:user) do
   email        { sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } }
   password     '123456789'
   confirmed_at { Time.zone.now }
-  agreement    true
+  current_sign_in_at { Time.zone.now }
+  agreement true
 end
diff --git a/spec/workers/scheduler/follow_recommendations_scheduler_spec.rb b/spec/workers/scheduler/follow_recommendations_scheduler_spec.rb
new file mode 100644
index 000000000..18d5260e4
--- /dev/null
+++ b/spec/workers/scheduler/follow_recommendations_scheduler_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Scheduler::FollowRecommendationsScheduler do
+  let!(:target_accounts) do
+    Fabricate.times(3, :account) do
+      statuses(count: 6)
+    end
+  end
+  let!(:follower_accounts) do
+    Fabricate.times(5, :account) do
+      statuses(count: 6)
+    end
+  end
+
+  describe '#perform' do
+    subject(:scheduled_run) { described_class.new.perform }
+
+    context 'when there are accounts to recommend' do
+      before do
+        # Follow the target accounts by follow accounts to make them recommendable
+        follower_accounts.each do |follower_account|
+          target_accounts.each do |target_account|
+            Fabricate(:follow, account: follower_account, target_account: target_account)
+          end
+        end
+      end
+
+      it 'creates recommendations' do
+        expect { scheduled_run }.to change(FollowRecommendation, :count).from(0).to(target_accounts.size)
+        expect(redis.zrange('follow_recommendations:en', 0, -1)).to match_array(target_accounts.pluck(:id).map(&:to_s))
+      end
+    end
+
+    context 'when there are no accounts to recommend' do
+      it 'does not create follow recommendations' do
+        expect { scheduled_run }.to_not change(FollowRecommendation, :count)
+        expect(redis.zrange('follow_recommendations:en', 0, -1)).to be_empty
+      end
+    end
+  end
+end