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.

54 lines
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::SalmonController, type: :controller do
  3. render_views
  4. let(:account) { Fabricate(:user, account: Fabricate(:account, username: 'catsrgr8')).account }
  5. before do
  6. stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
  7. stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
  8. stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
  9. stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
  10. end
  11. describe 'POST #update' do
  12. context 'with valid post data' do
  13. before do
  14. request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
  15. post :update, params: { id: account.id }
  16. end
  17. it 'contains XML in the request body' do
  18. expect(request.body.read).to be_a String
  19. end
  20. it 'returns http success' do
  21. expect(response).to have_http_status(:success)
  22. end
  23. it 'creates remote account' do
  24. expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
  25. end
  26. it 'creates status' do
  27. expect(Status.find_by(uri: 'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note')).to_not be_nil
  28. end
  29. it 'creates mention for target account' do
  30. expect(account.mentions.count).to eq 1
  31. end
  32. end
  33. context 'with invalid post data' do
  34. before do
  35. request.env['RAW_POST_DATA'] = ''
  36. post :update, params: { id: account.id }
  37. end
  38. it 'returns http success' do
  39. expect(response).to have_http_status(202)
  40. end
  41. end
  42. end
  43. end