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.

45 lines
1.9 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::FollowsController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { double acceptable?: true, resource_owner_id: user.id }
  6. before do
  7. allow(controller).to receive(:doorkeeper_token) { token }
  8. end
  9. describe 'POST #create' do
  10. before do
  11. stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
  12. stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
  13. stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
  14. stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
  15. stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {})
  16. stub_request(:post, "https://quitter.no/main/salmon/user/7477").to_return(:status => 200, :body => "", :headers => {})
  17. post :create, params: { uri: 'gargron@quitter.no' }
  18. end
  19. it 'returns http success' do
  20. expect(response).to have_http_status(:success)
  21. end
  22. it 'creates account for remote user' do
  23. expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
  24. end
  25. it 'creates a follow relation between user and remote user' do
  26. expect(user.account.following?(Account.find_by(username: 'gargron', domain: 'quitter.no'))).to be true
  27. end
  28. it 'sends a salmon slap to the remote user' do
  29. expect(a_request(:post, "https://quitter.no/main/salmon/user/7477")).to have_been_made
  30. end
  31. it 'subscribes to remote hub' do
  32. expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made
  33. end
  34. end
  35. end