]> cat aescling's git repositories - mastodon.git/commitdiff
Add tests for BootstrapTimelineService (#16476)
authorClaire <claire.github-309c@sitedethib.com>
Wed, 7 Jul 2021 19:12:43 +0000 (21:12 +0200)
committerGitHub <noreply@github.com>
Wed, 7 Jul 2021 19:12:43 +0000 (21:12 +0200)
spec/services/bootstrap_timeline_service_spec.rb

index 880ca4f0dbda93f2e4c1f69b846958434994e0b8..16f3e9962e4db09478d401cc7645c7874053d946 100644 (file)
@@ -1,4 +1,37 @@
 require 'rails_helper'
 
 RSpec.describe BootstrapTimelineService, type: :service do
+  subject { BootstrapTimelineService.new }
+
+  context 'when the new user has registered from an invite' do
+    let(:service)    { double }
+    let(:autofollow) { false }
+    let(:inviter)    { Fabricate(:user, confirmed_at: 2.days.ago) }
+    let(:invite)     { Fabricate(:invite, user: inviter, max_uses: nil, expires_at: 1.hour.from_now, autofollow: autofollow) }
+    let(:new_user)   { Fabricate(:user, invite_code: invite.code) }
+
+    before do
+      allow(FollowService).to receive(:new).and_return(service)
+      allow(service).to receive(:call)
+    end
+
+    context 'when the invite has auto-follow enabled' do
+      let(:autofollow) { true }
+
+      it 'calls FollowService to follow the inviter' do
+        subject.call(new_user.account)
+        expect(service).to have_received(:call).with(new_user.account, inviter.account)
+      end
+    end
+
+    context 'when the invite does not have auto-follow enable' do
+      let(:autofollow) { false }
+
+      it 'calls FollowService to follow the inviter' do
+        subject.call(new_user.account)
+        expect(service).to_not have_received(:call)
+      end
+    end
+
+  end
 end