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.

40 lines
1.2 KiB

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