about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-21 22:07:18 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-21 22:07:18 +0200
commite46abc71cad590c2113247d41feca80d27a557b0 (patch)
tree7c7947aa82231a1d28fd2240a689ca057550ea1d /spec
parent4bec613897d8835bb78202c7a36691b654f14967 (diff)
Fix notifications in UI, added new API for fetching account relationships
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/accounts_controller_spec.rb42
-rw-r--r--spec/spec_helper.rb2
2 files changed, 43 insertions, 1 deletions
diff --git a/spec/controllers/api/accounts_controller_spec.rb b/spec/controllers/api/accounts_controller_spec.rb
index 91e62837c..7fef8b9fe 100644
--- a/spec/controllers/api/accounts_controller_spec.rb
+++ b/spec/controllers/api/accounts_controller_spec.rb
@@ -71,4 +71,46 @@ RSpec.describe Api::AccountsController, type: :controller do
       expect(user.account.following?(other_account)).to be false
     end
   end
+
+  describe 'GET #relationships' do
+    let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
+    let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
+
+    before do
+      user.account.follow!(simon)
+      lewis.follow!(user.account)
+    end
+
+    context 'provided only one ID' do
+      before do
+        get :relationships, params: { id: simon.id }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'returns JSON with correct data' do
+        json = body_as_json
+
+        expect(json).to be_a Enumerable
+        expect(json.first[:following]).to be true
+        expect(json.first[:followed_by]).to be false
+      end
+    end
+
+    context 'provided multiple IDs' do
+      before do
+        get :relationships, params: { id: [simon.id, lewis.id] }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      xit 'returns JSON with correct data' do
+        # todo
+      end
+    end
+  end
 end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 8d77b39f3..2fdce8755 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -23,5 +23,5 @@ def body_as_json
 end
 
 def json_str_to_hash(str)
-  JSON.parse(str).with_indifferent_access
+  JSON.parse(str, symbolize_names: true)
 end