Skip to content

Commit

Permalink
Misc coverage improvements re: sidekiq/inline (#28651)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Jan 9, 2024
1 parent 68f06f1 commit 5dc6347
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
82 changes: 82 additions & 0 deletions spec/models/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,88 @@
end
end

describe 'Setting account from activity_type' do
context 'when activity_type is a Status' do
it 'sets the notification from_account correctly' do
status = Fabricate(:status)

notification = Fabricate.build(:notification, activity_type: 'Status', activity: status)

expect(notification.from_account).to eq(status.account)
end
end

context 'when activity_type is a Follow' do
it 'sets the notification from_account correctly' do
follow = Fabricate(:follow)

notification = Fabricate.build(:notification, activity_type: 'Follow', activity: follow)

expect(notification.from_account).to eq(follow.account)
end
end

context 'when activity_type is a Favourite' do
it 'sets the notification from_account correctly' do
favourite = Fabricate(:favourite)

notification = Fabricate.build(:notification, activity_type: 'Favourite', activity: favourite)

expect(notification.from_account).to eq(favourite.account)
end
end

context 'when activity_type is a FollowRequest' do
it 'sets the notification from_account correctly' do
follow_request = Fabricate(:follow_request)

notification = Fabricate.build(:notification, activity_type: 'FollowRequest', activity: follow_request)

expect(notification.from_account).to eq(follow_request.account)
end
end

context 'when activity_type is a Poll' do
it 'sets the notification from_account correctly' do
poll = Fabricate(:poll)

notification = Fabricate.build(:notification, activity_type: 'Poll', activity: poll)

expect(notification.from_account).to eq(poll.account)
end
end

context 'when activity_type is a Report' do
it 'sets the notification from_account correctly' do
report = Fabricate(:report)

notification = Fabricate.build(:notification, activity_type: 'Report', activity: report)

expect(notification.from_account).to eq(report.account)
end
end

context 'when activity_type is a Mention' do
it 'sets the notification from_account correctly' do
mention = Fabricate(:mention)

notification = Fabricate.build(:notification, activity_type: 'Mention', activity: mention)

expect(notification.from_account).to eq(mention.status.account)
end
end

context 'when activity_type is an Account' do
it 'sets the notification from_account correctly' do
account = Fabricate(:account)

notification = Fabricate.build(:notification, activity_type: 'Account', account: account)

expect(notification.account).to eq(account)
end
end
end

describe '.preload_cache_collection_target_statuses' do
subject do
described_class.preload_cache_collection_target_statuses(notifications) do |target_statuses|
Expand Down
3 changes: 3 additions & 0 deletions spec/services/fan_out_on_write_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
ProcessMentionsService.new.call(status)
ProcessHashtagsService.new.call(status)

Fabricate(:media_attachment, status: status, account: alice)

allow(redis).to receive(:publish)

subject.call(status)
Expand Down Expand Up @@ -49,6 +51,7 @@ def home_feed_of(account)
it 'is broadcast to the public stream' do
expect(redis).to have_received(:publish).with('timeline:public', anything)
expect(redis).to have_received(:publish).with('timeline:public:local', anything)
expect(redis).to have_received(:publish).with('timeline:public:media', anything)
end
end

Expand Down
11 changes: 10 additions & 1 deletion spec/services/remove_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
end

context 'when removed status is not a reblog' do
let!(:status) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct} ThisIsASecret") }
let!(:media_attachment) { Fabricate(:media_attachment, account: alice) }
let!(:status) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct} ThisIsASecret", media_ids: [media_attachment.id]) }

before do
FavouriteService.new.call(jeff, status)
Expand All @@ -37,6 +38,14 @@
expect(HomeFeed.new(jeff).get(10).pluck(:id)).to_not include(status.id)
end

it 'publishes to public media timeline' do
allow(redis).to receive(:publish).with(any_args)

subject.call(status)

expect(redis).to have_received(:publish).with('timeline:public:media', Oj.dump(event: :delete, payload: status.id.to_s))
end

it 'sends Delete activity to followers' do
subject.call(status)
expect(a_request(:post, hank.inbox_url).with(
Expand Down

0 comments on commit 5dc6347

Please sign in to comment.