block_service_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. require 'rails_helper'
  2. RSpec.describe BlockService, type: :service do
  3. let(:sender) { Fabricate(:account, username: 'alice') }
  4. subject { BlockService.new }
  5. describe 'local' do
  6. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  7. before do
  8. subject.call(sender, bob)
  9. end
  10. it 'creates a blocking relation' do
  11. expect(sender.blocking?(bob)).to be true
  12. end
  13. end
  14. describe 'remote OStatus' do
  15. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
  16. before do
  17. stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
  18. subject.call(sender, bob)
  19. end
  20. it 'creates a blocking relation' do
  21. expect(sender.blocking?(bob)).to be true
  22. end
  23. end
  24. describe 'remote ActivityPub' do
  25. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }
  26. before do
  27. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  28. subject.call(sender, bob)
  29. end
  30. it 'creates a blocking relation' do
  31. expect(sender.blocking?(bob)).to be true
  32. end
  33. it 'sends a block activity' do
  34. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  35. end
  36. end
  37. end