favourite_service_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe FavouriteService, type: :service 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. before do
  10. subject.call(sender, status)
  11. end
  12. it 'creates a favourite' do
  13. expect(status.favourites.first).to_not be_nil
  14. end
  15. end
  16. describe 'remote ActivityPub' do
  17. let(:bob) { Fabricate(:account, protocol: :activitypub, username: 'bob', domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  18. let(:status) { Fabricate(:status, account: bob) }
  19. before do
  20. stub_request(:post, 'http://example.com/inbox').to_return(status: 200, body: '', headers: {})
  21. subject.call(sender, status)
  22. end
  23. it 'creates a favourite' do
  24. expect(status.favourites.first).to_not be_nil
  25. end
  26. it 'sends a like activity' do
  27. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  28. end
  29. end
  30. end