favourite_service_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe FavouriteService do
  4. subject { described_class.new }
  5. let(:sender) { Fabricate(:account, username: 'alice') }
  6. describe 'local' do
  7. let(:bob) { Fabricate(:account) }
  8. let(:status) { Fabricate(:status, account: bob) }
  9. it 'creates a favourite' do
  10. subject.call(sender, status)
  11. expect(status.favourites.first).to_not be_nil
  12. end
  13. end
  14. describe 'remote ActivityPub' do
  15. let(:bob) { Fabricate(:account, protocol: :activitypub, username: 'bob', domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  16. let(:status) { Fabricate(:status, account: bob) }
  17. before do
  18. stub_request(:post, 'http://example.com/inbox').to_return(status: 200, body: '', headers: {})
  19. end
  20. it 'creates a favourite and sends like activity', :inline_jobs do
  21. subject.call(sender, status)
  22. expect(status.favourites.first)
  23. .to_not be_nil
  24. expect(a_request(:post, 'http://example.com/inbox'))
  25. .to have_been_made.once
  26. end
  27. end
  28. end