about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-09 13:58:18 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-09 19:58:18 +0200
commit441d6dc734d2590b14ca010076496e652d6ef676 (patch)
treeb7543a42509b6f0aed0dfd7a0ee5931b9483dfc3 /spec
parentd5cabfe5c65ac29d2f9c151b46c01a9fd885a9e0 (diff)
Spec and refactor for pubsubhubbub/unsubscribe service (#2946)
* Add coverage for pubsub unsubscribe service

* Refactor pubsub unsubscribe service
Diffstat (limited to 'spec')
-rw-r--r--spec/services/pubsubhubbub/unsubscribe_service_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/services/pubsubhubbub/unsubscribe_service_spec.rb b/spec/services/pubsubhubbub/unsubscribe_service_spec.rb
new file mode 100644
index 000000000..59054ed99
--- /dev/null
+++ b/spec/services/pubsubhubbub/unsubscribe_service_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Pubsubhubbub::UnsubscribeService do
+  describe '#call' do
+    subject { described_class.new }
+
+    context 'with a nil account' do
+      it 'returns an invalid topic status' do
+        result = subject.call(nil, 'callback.host')
+
+        expect(result).to eq invalid_topic_status
+      end
+    end
+
+    context 'with a valid account' do
+      let(:account) { Fabricate(:account) }
+
+      it 'returns a valid topic status and does not run confirm when no subscription' do
+        allow(Pubsubhubbub::ConfirmationWorker).to receive(:perform_async).and_return(nil)
+        result = subject.call(account, 'callback.host')
+
+        expect(result).to eq valid_topic_status
+        expect(Pubsubhubbub::ConfirmationWorker).not_to have_received(:perform_async)
+      end
+
+      it 'returns a valid topic status and does run confirm when there is a subscription' do
+        subscription = Fabricate(:subscription, account: account, callback_url: 'callback.host')
+        allow(Pubsubhubbub::ConfirmationWorker).to receive(:perform_async).and_return(nil)
+        result = subject.call(account, 'callback.host')
+
+        expect(result).to eq valid_topic_status
+        expect(Pubsubhubbub::ConfirmationWorker).to have_received(:perform_async).with(subscription.id, 'unsubscribe')
+      end
+    end
+
+    def invalid_topic_status
+      ['Invalid topic URL', 422]
+    end
+
+    def valid_topic_status
+      ['', 202]
+    end
+  end
+end