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.

42 lines
1.2 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::SubscriptionsController, type: :controller do
  3. render_views
  4. let(:account) { Fabricate(:account, username: 'gargron', domain: 'quitter.no', verify_token: '123', remote_url: 'topic_url', secret: 'abc') }
  5. describe 'GET #show' do
  6. before do
  7. get :show, params: { :id => account.id, 'hub.topic' => 'topic_url', 'hub.verify_token' => 123, 'hub.challenge' => '456' }
  8. end
  9. it 'returns http success' do
  10. expect(response).to have_http_status(:success)
  11. end
  12. it 'echoes back the challenge' do
  13. expect(response.body).to match '456'
  14. end
  15. end
  16. describe 'POST #update' do
  17. let(:feed) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
  18. before do
  19. stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
  20. request.env['HTTP_X_HUB_SIGNATURE'] = "sha1=#{OpenSSL::HMAC.hexdigest('sha1', 'abc', feed)}"
  21. request.env['RAW_POST_DATA'] = feed
  22. post :update, params: { id: account.id }
  23. end
  24. it 'returns http created' do
  25. expect(response).to have_http_status(:created)
  26. end
  27. it 'creates statuses for feed' do
  28. expect(account.statuses.count).to_not eq 0
  29. end
  30. end
  31. end