1
0

block_service_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe BlockService do
  4. subject { described_class.new }
  5. let(:sender) { Fabricate(:account, username: 'alice') }
  6. describe 'local' do
  7. let(:bob) { Fabricate(:account, username: 'bob') }
  8. before do
  9. NotificationPermission.create!(account: sender, from_account: bob)
  10. end
  11. it 'creates a blocking relation and removes notification permissions' do
  12. expect { subject.call(sender, bob) }
  13. .to change { sender.blocking?(bob) }.from(false).to(true)
  14. .and change { NotificationPermission.exists?(account: sender, from_account: bob) }.from(true).to(false)
  15. end
  16. end
  17. describe 'remote ActivityPub' do
  18. let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  19. before do
  20. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  21. end
  22. it 'creates a blocking relation and send block activity', :inline_jobs do
  23. subject.call(sender, bob)
  24. expect(sender)
  25. .to be_blocking(bob)
  26. expect(a_request(:post, 'http://example.com/inbox'))
  27. .to have_been_made.once
  28. end
  29. end
  30. end