about summary refs log tree commit diff
path: root/spec/controllers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-03-20 13:03:06 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-03-20 13:03:06 +0100
commitb640f35621b419ae9b9e621e00a8a055068ce2f4 (patch)
tree430d9b5a442a427d07135b96ac0f71fd24d4aa99 /spec/controllers
parente14b76c7cb07c3ebc01a17991df9fe5b69d1b5bc (diff)
Writing out more tests, fixed some bugs
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/api/accounts_controller_spec.rb56
-rw-r--r--spec/controllers/api/follows_controller_spec.rb43
-rw-r--r--spec/controllers/api/salmon_controller_spec.rb30
-rw-r--r--spec/controllers/api/statuses_controller_spec.rb14
-rw-r--r--spec/controllers/api/subscriptions_controller_spec.rb33
5 files changed, 165 insertions, 11 deletions
diff --git a/spec/controllers/api/accounts_controller_spec.rb b/spec/controllers/api/accounts_controller_spec.rb
index 915a40a8a..7bcb1a788 100644
--- a/spec/controllers/api/accounts_controller_spec.rb
+++ b/spec/controllers/api/accounts_controller_spec.rb
@@ -1,27 +1,71 @@
 require 'rails_helper'
 
 RSpec.describe Api::AccountsController, type: :controller do
+  let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
+  let(:token) { double acceptable?: true, resource_owner_id: user.id }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
   describe 'GET #show' do
-    it 'returns http success'
+    it 'returns http success' do
+      get :show, id: user.account.id
+      expect(response).to have_http_status(:success)
+    end
   end
 
   describe 'GET #statuses' do
-    it 'returns http success'
+    it 'returns http success' do
+      get :statuses, id: user.account.id
+      expect(response).to have_http_status(:success)
+    end
   end
 
   describe 'GET #followers' do
-    it 'returns http success'
+    it 'returns http success' do
+      get :followers, id: user.account.id
+      expect(response).to have_http_status(:success)
+    end
   end
 
   describe 'GET #following' do
-    it 'returns http success'
+    it 'returns http success' do
+      get :following, id: user.account.id
+      expect(response).to have_http_status(:success)
+    end
   end
 
   describe 'POST #follow' do
-    it 'returns http success'
+    let(:other_account) { Fabricate(:account, username: 'bob') }
+
+    before do
+      post :follow, id: other_account.id
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'creates a following relation between user and target user' do
+      expect(user.account.following?(other_account)).to be true
+    end
   end
 
   describe 'POST #unfollow' do
-    it 'returns http success'
+    let(:other_account) { Fabricate(:account, username: 'bob') }
+
+    before do
+      user.account.follow!(other_account)
+      post :unfollow, id: other_account.id
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'removes the following relation between user and target user' do
+      expect(user.account.following?(other_account)).to be false
+    end
   end
 end
diff --git a/spec/controllers/api/follows_controller_spec.rb b/spec/controllers/api/follows_controller_spec.rb
index 75f470181..e9bb1bfa5 100644
--- a/spec/controllers/api/follows_controller_spec.rb
+++ b/spec/controllers/api/follows_controller_spec.rb
@@ -1,7 +1,48 @@
 require 'rails_helper'
 
 RSpec.describe Api::FollowsController, type: :controller do
+  let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
+  let(:token) { double acceptable?: true, resource_owner_id: user.id }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
   describe 'POST #create' do
-    it 'returns http success'
+    before do
+      stub_request(:get,  "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
+      stub_request(:get,  "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
+      stub_request(:get,  "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
+      stub_request(:get,  "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
+      stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {})
+      stub_request(:post, "https://quitter.no/main/salmon/user/7477").to_return(:status => 200, :body => "", :headers => {})
+      stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {})
+
+      post :create, uri: 'gargron@quitter.no'
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'creates account for remote user' do
+      expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
+    end
+
+    it 'creates a follow relation between user and remote user' do
+      expect(user.account.following?(Account.find_by(username: 'gargron', domain: 'quitter.no'))).to be true
+    end
+
+    it 'sends a salmon slap to the remote user' do
+      expect(a_request(:post, "https://quitter.no/main/salmon/user/7477")).to have_been_made
+    end
+
+    it 'notifies own hub' do
+      expect(a_request(:post, "https://pubsubhubbub.superfeedr.com/")).to have_been_made
+    end
+
+    it 'subscribes to remote hub' do
+      expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made
+    end
   end
 end
diff --git a/spec/controllers/api/salmon_controller_spec.rb b/spec/controllers/api/salmon_controller_spec.rb
index e81ad12ad..d5be69c01 100644
--- a/spec/controllers/api/salmon_controller_spec.rb
+++ b/spec/controllers/api/salmon_controller_spec.rb
@@ -1,7 +1,35 @@
 require 'rails_helper'
 
 RSpec.describe Api::SalmonController, type: :controller do
+  let(:account) { Fabricate(:account, username: 'catsrgr8', user: Fabricate(:user)) }
+
+  before do
+    stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
+    stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
+    stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
+    stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
+  end
+
   describe 'POST #update' do
-    pending
+    before do
+      request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
+      post :update, id: account.id
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'creates remote account' do
+      expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
+    end
+
+    it 'creates status' do
+      expect(Status.find_by(uri: 'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note')).to_not be_nil
+    end
+
+    it 'creates mention for target account' do
+      expect(account.mentions.count).to eq 1
+    end
   end
 end
diff --git a/spec/controllers/api/statuses_controller_spec.rb b/spec/controllers/api/statuses_controller_spec.rb
index bd136a559..75a8b999a 100644
--- a/spec/controllers/api/statuses_controller_spec.rb
+++ b/spec/controllers/api/statuses_controller_spec.rb
@@ -1,8 +1,20 @@
 require 'rails_helper'
 
 RSpec.describe Api::StatusesController, type: :controller do
+  let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
+  let(:token) { double acceptable?: true, resource_owner_id: user.id }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
   describe 'GET #show' do
-    it 'returns http success'
+    let(:status) { Fabricate(:status, account: user.account) }
+
+    it 'returns http success' do
+      get :show, id: status.id
+      expect(response).to have_http_status(:success)
+    end
   end
 
   describe 'GET #home' do
diff --git a/spec/controllers/api/subscriptions_controller_spec.rb b/spec/controllers/api/subscriptions_controller_spec.rb
index 16995c687..e2f2ddd7e 100644
--- a/spec/controllers/api/subscriptions_controller_spec.rb
+++ b/spec/controllers/api/subscriptions_controller_spec.rb
@@ -1,11 +1,40 @@
 require 'rails_helper'
 
 RSpec.describe Api::SubscriptionsController, type: :controller do
+  let(:account) { Fabricate(:account, username: 'gargron', domain: 'quitter.no', verify_token: '123', remote_url: 'topic_url', secret: 'abc') }
+
   describe 'GET #show' do
-    pending
+    before do
+      get :show, id: account.id, 'hub.topic': 'topic_url', 'hub.verify_token': 123, 'hub.challenge': '456'
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'echoes back the challenge' do
+      expect(response.body).to match '456'
+    end
   end
 
   describe 'POST #update' do
-    pending
+    let(:feed) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
+
+    before do
+      stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
+
+      request.env['HTTP_X_HUB_SIGNATURE'] = "sha1=#{OpenSSL::HMAC.hexdigest('sha1', 'abc', feed)}"
+      request.env['RAW_POST_DATA'] = feed
+
+      post :update, id: account.id
+    end
+
+    it 'returns http created' do
+      expect(response).to have_http_status(:created)
+    end
+
+    it 'creates statuses for feed' do
+      expect(account.statuses.count).to_not eq 0
+    end
   end
 end