about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-08 18:44:30 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-09 00:44:30 +0200
commit04166c4a35c97f5540252617c7858bf20d315a7e (patch)
tree92fd0b6340ea5ca99d4812d3d92fa81b588ea8a7 /spec
parentfed585e3f42578f133da66497c1720f9d47833d1 (diff)
Specs for API push controller, with refactor (#2926)
* Coverage for api push controller

* Refactor the api/push controller
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/push_controller_spec.rb49
1 files changed, 47 insertions, 2 deletions
diff --git a/spec/controllers/api/push_controller_spec.rb b/spec/controllers/api/push_controller_spec.rb
index e699006f7..18bfa70e5 100644
--- a/spec/controllers/api/push_controller_spec.rb
+++ b/spec/controllers/api/push_controller_spec.rb
@@ -3,11 +3,56 @@ require 'rails_helper'
 RSpec.describe Api::PushController, type: :controller do
   describe 'POST #update' do
     context 'with hub.mode=subscribe' do
-      pending
+      it 'creates a subscription' do
+        service = double(call: ['', 202])
+        allow(Pubsubhubbub::SubscribeService).to receive(:new).and_return(service)
+        account = Fabricate(:account)
+        account_topic_url = "https://#{Rails.configuration.x.local_domain}/users/#{account.username}.atom"
+        post :update, params: {
+          'hub.mode' => 'subscribe',
+          'hub.topic' => account_topic_url,
+          'hub.callback' => 'https://callback.host/api',
+          'hub.lease_seconds' => '3600',
+          'hub.secret' => 'as1234df',
+        }
+
+        expect(service).to have_received(:call).with(
+          account,
+          'https://callback.host/api',
+          'as1234df',
+          '3600',
+        )
+        expect(response).to have_http_status(:success)
+      end
     end
 
     context 'with hub.mode=unsubscribe' do
-      pending
+      it 'unsubscribes the account' do
+        service = double(call: ['', 202])
+        allow(Pubsubhubbub::UnsubscribeService).to receive(:new).and_return(service)
+        account = Fabricate(:account)
+        account_topic_url = "https://#{Rails.configuration.x.local_domain}/users/#{account.username}.atom"
+        post :update, params: {
+          'hub.mode' => 'unsubscribe',
+          'hub.topic' => account_topic_url,
+          'hub.callback' => 'https://callback.host/api',
+        }
+
+        expect(service).to have_received(:call).with(
+          account,
+          'https://callback.host/api',
+        )
+        expect(response).to have_http_status(:success)
+      end
+    end
+
+    context 'with unknown mode' do
+      it 'returns an unknown mode error' do
+        post :update, params: { 'hub.mode' => 'fake' }
+
+        expect(response).to have_http_status(422)
+        expect(response.body).to match(/Unknown mode/)
+      end
     end
   end
 end