logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

salmon_controller_spec.rb (2313B)


  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 empty 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 client error' do
  39. expect(response).to have_http_status(400)
  40. end
  41. end
  42. context 'with invalid post data' do
  43. before do
  44. service = double(call: false)
  45. allow(VerifySalmonService).to receive(:new).and_return(service)
  46. request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
  47. post :update, params: { id: account.id }
  48. end
  49. it 'returns http client error' do
  50. expect(response).to have_http_status(401)
  51. end
  52. end
  53. end
  54. end