You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.8 KiB

  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. it 'sends a block salmon slap' do
  24. expect(a_request(:post, "http://salmon.example.com/").with { |req|
  25. xml = OStatus2::Salmon.new.unpack(req.body)
  26. xml.match(OStatus::TagManager::VERBS[:block])
  27. }).to have_been_made.once
  28. end
  29. end
  30. describe 'remote ActivityPub' do
  31. 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 }
  32. before do
  33. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  34. subject.call(sender, bob)
  35. end
  36. it 'creates a blocking relation' do
  37. expect(sender.blocking?(bob)).to be true
  38. end
  39. it 'sends a block activity' do
  40. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  41. end
  42. end
  43. end