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.

59 lines
1.9 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::PushController, type: :controller do
  3. describe 'POST #update' do
  4. context 'with hub.mode=subscribe' do
  5. it 'creates a subscription' do
  6. service = double(call: ['', 202])
  7. allow(Pubsubhubbub::SubscribeService).to receive(:new).and_return(service)
  8. account = Fabricate(:account)
  9. account_topic_url = "https://#{Rails.configuration.x.local_domain}/users/#{account.username}.atom"
  10. post :update, params: {
  11. 'hub.mode' => 'subscribe',
  12. 'hub.topic' => account_topic_url,
  13. 'hub.callback' => 'https://callback.host/api',
  14. 'hub.lease_seconds' => '3600',
  15. 'hub.secret' => 'as1234df',
  16. }
  17. expect(service).to have_received(:call).with(
  18. account,
  19. 'https://callback.host/api',
  20. 'as1234df',
  21. '3600',
  22. nil
  23. )
  24. expect(response).to have_http_status(202)
  25. end
  26. end
  27. context 'with hub.mode=unsubscribe' do
  28. it 'unsubscribes the account' do
  29. service = double(call: ['', 202])
  30. allow(Pubsubhubbub::UnsubscribeService).to receive(:new).and_return(service)
  31. account = Fabricate(:account)
  32. account_topic_url = "https://#{Rails.configuration.x.local_domain}/users/#{account.username}.atom"
  33. post :update, params: {
  34. 'hub.mode' => 'unsubscribe',
  35. 'hub.topic' => account_topic_url,
  36. 'hub.callback' => 'https://callback.host/api',
  37. }
  38. expect(service).to have_received(:call).with(
  39. account,
  40. 'https://callback.host/api',
  41. )
  42. expect(response).to have_http_status(202)
  43. end
  44. end
  45. context 'with unknown mode' do
  46. it 'returns an unknown mode error' do
  47. post :update, params: { 'hub.mode' => 'fake' }
  48. expect(response).to have_http_status(422)
  49. expect(response.body).to match(/Unknown mode/)
  50. end
  51. end
  52. end
  53. end