闭社主体 forked from https://github.com/tootsuite/mastodon
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.

52 lines
1.8 KiB

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