闭社主体 forked from https://github.com/tootsuite/mastodon
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.

58 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. )
  23. expect(response).to have_http_status(:success)
  24. end
  25. end
  26. context 'with hub.mode=unsubscribe' do
  27. it 'unsubscribes the account' do
  28. service = double(call: ['', 202])
  29. allow(Pubsubhubbub::UnsubscribeService).to receive(:new).and_return(service)
  30. account = Fabricate(:account)
  31. account_topic_url = "https://#{Rails.configuration.x.local_domain}/users/#{account.username}.atom"
  32. post :update, params: {
  33. 'hub.mode' => 'unsubscribe',
  34. 'hub.topic' => account_topic_url,
  35. 'hub.callback' => 'https://callback.host/api',
  36. }
  37. expect(service).to have_received(:call).with(
  38. account,
  39. 'https://callback.host/api',
  40. )
  41. expect(response).to have_http_status(:success)
  42. end
  43. end
  44. context 'with unknown mode' do
  45. it 'returns an unknown mode error' do
  46. post :update, params: { 'hub.mode' => 'fake' }
  47. expect(response).to have_http_status(422)
  48. expect(response.body).to match(/Unknown mode/)
  49. end
  50. end
  51. end
  52. end