Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc coverage improvements re: sidekiq/inline #28651

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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