The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

66 lines
2.1 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. post :update, params: { id: account.id }, body: File.read(Rails.root.join('spec', 'fixtures', 'salmon', 'mention.xml'))
  15. end
  16. it 'contains XML in the request body' do
  17. expect(request.body.read).to be_a String
  18. end
  19. it 'returns http success' do
  20. expect(response).to have_http_status(202)
  21. end
  22. it 'creates remote account' do
  23. expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
  24. end
  25. it 'creates status' do
  26. expect(Status.find_by(uri: 'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note')).to_not be_nil
  27. end
  28. it 'creates mention for target account' do
  29. expect(account.mentions.count).to eq 1
  30. end
  31. end
  32. context 'with empty post data' do
  33. before do
  34. post :update, params: { id: account.id }, body: ''
  35. end
  36. it 'returns http client error' do
  37. expect(response).to have_http_status(400)
  38. end
  39. end
  40. context 'with invalid post data' do
  41. before do
  42. service = double(call: false)
  43. allow(VerifySalmonService).to receive(:new).and_return(service)
  44. post :update, params: { id: account.id }, body: File.read(Rails.root.join('spec', 'fixtures', 'salmon', 'mention.xml'))
  45. end
  46. it 'returns http client error' do
  47. expect(response).to have_http_status(401)
  48. end
  49. end
  50. end
  51. end