block_service_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. require 'rails_helper'
  2. RSpec.describe BlockService 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' 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(TagManager::VERBS[:block])
  27. }).to have_been_made.once
  28. end
  29. end
  30. end