about summary refs log tree commit diff
path: root/spec/controllers/api/v1/accounts
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2023-04-14 19:22:47 -0500
committerStarfall <us@starfall.systems>2023-04-14 19:22:47 -0500
commit4fe1689de43f4404eb9530fcfbcbfb26d6c1c13a (patch)
tree6811b845bb7f4966b10dcefa3dea404246f161c7 /spec/controllers/api/v1/accounts
parent65c1e53a32cabcdbb7bca57002bb0f6acdebe07e (diff)
parentbed63f6dae0879ac840066b031229e0d139089cd (diff)
Merge remote-tracking branch 'glitch/main' HEAD main
Diffstat (limited to 'spec/controllers/api/v1/accounts')
-rw-r--r--spec/controllers/api/v1/accounts/credentials_controller_spec.rb21
-rw-r--r--spec/controllers/api/v1/accounts/familiar_followers_controller_spec.rb23
-rw-r--r--spec/controllers/api/v1/accounts/featured_tags_controller_spec.rb23
-rw-r--r--spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/accounts/identity_proofs_controller_spec.rb23
-rw-r--r--spec/controllers/api/v1/accounts/lists_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/accounts/lookup_controller_spec.rb23
-rw-r--r--spec/controllers/api/v1/accounts/notes_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/accounts/relationships_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/accounts/search_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/accounts/statuses_controller_spec.rb30
12 files changed, 141 insertions, 14 deletions
diff --git a/spec/controllers/api/v1/accounts/credentials_controller_spec.rb b/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
index aae35ce38..a677aaad0 100644
--- a/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 describe Api::V1::Accounts::CredentialsController do
@@ -35,7 +37,7 @@ describe Api::V1::Accounts::CredentialsController do
             source: {
               privacy: 'unlisted',
               sensitive: true,
-            }
+            },
           }
         end
 
@@ -44,6 +46,7 @@ describe Api::V1::Accounts::CredentialsController do
         end
 
         it 'updates account info' do
+          user.reload
           user.account.reload
 
           expect(user.account.display_name).to eq("Alice Isn't Dead")
@@ -51,7 +54,7 @@ describe Api::V1::Accounts::CredentialsController do
           expect(user.account.avatar).to exist
           expect(user.account.header).to exist
           expect(user.setting_default_privacy).to eq('unlisted')
-          expect(user.setting_default_sensitive).to eq(true)
+          expect(user.setting_default_sensitive).to be(true)
         end
 
         it 'queues up an account update distribution' do
@@ -70,17 +73,17 @@ describe Api::V1::Accounts::CredentialsController do
         it 'returns http success' do
           expect(response).to have_http_status(200)
         end
-     end
+      end
 
-      describe 'with invalid data' do
+      describe 'with a too long profile bio' do
         before do
           note = 'This is too long. '
-          note = note + 'a' * (Account::MAX_NOTE_LENGTH - note.length + 1)
+          note += 'a' * (Account::MAX_NOTE_LENGTH - note.length + 1)
           patch :update, params: { note: note }
         end
 
         it 'returns http unprocessable entity' do
-          expect(response).to have_http_status(:unprocessable_entity)
+          expect(response).to have_http_status(422)
         end
       end
     end
@@ -88,20 +91,20 @@ describe Api::V1::Accounts::CredentialsController do
 
   context 'without an oauth token' do
     before do
-      allow(controller).to receive(:doorkeeper_token) { nil }
+      allow(controller).to receive(:doorkeeper_token).and_return(nil)
     end
 
     describe 'GET #show' do
       it 'returns http unauthorized' do
         get :show
-        expect(response).to have_http_status(:unauthorized)
+        expect(response).to have_http_status(401)
       end
     end
 
     describe 'PATCH #update' do
       it 'returns http unauthorized' do
         patch :update, params: { note: 'Foo' }
-        expect(response).to have_http_status(:unauthorized)
+        expect(response).to have_http_status(401)
       end
     end
   end
diff --git a/spec/controllers/api/v1/accounts/familiar_followers_controller_spec.rb b/spec/controllers/api/v1/accounts/familiar_followers_controller_spec.rb
new file mode 100644
index 000000000..bb075261f
--- /dev/null
+++ b/spec/controllers/api/v1/accounts/familiar_followers_controller_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Api::V1::Accounts::FamiliarFollowersController do
+  render_views
+
+  let(:user)    { Fabricate(:user) }
+  let(:token)   { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:follows') }
+  let(:account) { Fabricate(:account) }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'GET #index' do
+    it 'returns http success' do
+      get :index, params: { account_id: account.id, limit: 2 }
+
+      expect(response).to have_http_status(200)
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/accounts/featured_tags_controller_spec.rb b/spec/controllers/api/v1/accounts/featured_tags_controller_spec.rb
new file mode 100644
index 000000000..53ac1e2a7
--- /dev/null
+++ b/spec/controllers/api/v1/accounts/featured_tags_controller_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Api::V1::Accounts::FeaturedTagsController do
+  render_views
+
+  let(:user)    { Fabricate(:user) }
+  let(:token)   { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts') }
+  let(:account) { Fabricate(:account) }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'GET #index' do
+    it 'returns http success' do
+      get :index, params: { account_id: account.id, limit: 2 }
+
+      expect(response).to have_http_status(200)
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb b/spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb
index 1e6e1d8e0..53298a2e4 100644
--- a/spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 describe Api::V1::Accounts::FollowerAccountsController do
diff --git a/spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb b/spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb
index cc962c6ee..7390b25b5 100644
--- a/spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 describe Api::V1::Accounts::FollowingAccountsController do
diff --git a/spec/controllers/api/v1/accounts/identity_proofs_controller_spec.rb b/spec/controllers/api/v1/accounts/identity_proofs_controller_spec.rb
new file mode 100644
index 000000000..6351de761
--- /dev/null
+++ b/spec/controllers/api/v1/accounts/identity_proofs_controller_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Api::V1::Accounts::IdentityProofsController do
+  render_views
+
+  let(:user)    { Fabricate(:user) }
+  let(:token)   { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts') }
+  let(:account) { Fabricate(:account) }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'GET #index' do
+    it 'returns http success' do
+      get :index, params: { account_id: account.id, limit: 2 }
+
+      expect(response).to have_http_status(200)
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/accounts/lists_controller_spec.rb b/spec/controllers/api/v1/accounts/lists_controller_spec.rb
index d71485633..418839cfa 100644
--- a/spec/controllers/api/v1/accounts/lists_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/lists_controller_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 describe Api::V1::Accounts::ListsController do
diff --git a/spec/controllers/api/v1/accounts/lookup_controller_spec.rb b/spec/controllers/api/v1/accounts/lookup_controller_spec.rb
new file mode 100644
index 000000000..37407766f
--- /dev/null
+++ b/spec/controllers/api/v1/accounts/lookup_controller_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Api::V1::Accounts::LookupController do
+  render_views
+
+  let(:user)    { Fabricate(:user) }
+  let(:token)   { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts') }
+  let(:account) { Fabricate(:account) }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'GET #show' do
+    it 'returns http success' do
+      get :show, params: { account_id: account.id, acct: account.acct }
+
+      expect(response).to have_http_status(200)
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/accounts/notes_controller_spec.rb b/spec/controllers/api/v1/accounts/notes_controller_spec.rb
index 42c2d8a86..fd4d34f69 100644
--- a/spec/controllers/api/v1/accounts/notes_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/notes_controller_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 describe Api::V1::Accounts::NotesController do
diff --git a/spec/controllers/api/v1/accounts/relationships_controller_spec.rb b/spec/controllers/api/v1/accounts/relationships_controller_spec.rb
index 69ad0d061..da8d7fe3f 100644
--- a/spec/controllers/api/v1/accounts/relationships_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/relationships_controller_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 describe Api::V1::Accounts::RelationshipsController do
diff --git a/spec/controllers/api/v1/accounts/search_controller_spec.rb b/spec/controllers/api/v1/accounts/search_controller_spec.rb
index 5b23bff68..d2b675a3c 100644
--- a/spec/controllers/api/v1/accounts/search_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/search_controller_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 RSpec.describe Api::V1::Accounts::SearchController, type: :controller do
diff --git a/spec/controllers/api/v1/accounts/statuses_controller_spec.rb b/spec/controllers/api/v1/accounts/statuses_controller_spec.rb
index b962b3398..e57c37179 100644
--- a/spec/controllers/api/v1/accounts/statuses_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/statuses_controller_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 describe Api::V1::Accounts::StatusesController do
@@ -16,6 +18,11 @@ describe Api::V1::Accounts::StatusesController do
       get :index, params: { account_id: user.account.id, limit: 1 }
 
       expect(response).to have_http_status(200)
+    end
+
+    it 'returns expected headers' do
+      get :index, params: { account_id: user.account.id, limit: 1 }
+
       expect(response.headers['Link'].links.size).to eq(2)
     end
 
@@ -28,15 +35,25 @@ describe Api::V1::Accounts::StatusesController do
     end
 
     context 'with exclude replies' do
+      let!(:older_statuses) { user.account.statuses.destroy_all }
+      let!(:status) { Fabricate(:status, account: user.account) }
+      let!(:status_self_reply) { Fabricate(:status, account: user.account, thread: status) }
+
       before do
-        Fabricate(:status, account: user.account, thread: Fabricate(:status))
+        Fabricate(:status, account: user.account, thread: Fabricate(:status)) # Reply to another user
+        get :index, params: { account_id: user.account.id, exclude_replies: true }
       end
 
       it 'returns http success' do
-        get :index, params: { account_id: user.account.id, exclude_replies: true }
-
         expect(response).to have_http_status(200)
       end
+
+      it 'returns posts along with self replies' do
+        json = body_as_json
+        post_ids = json.map { |item| item[:id].to_i }.sort
+
+        expect(post_ids).to eq [status.id, status_self_reply.id]
+      end
     end
 
     context 'with only own pinned' do
@@ -55,8 +72,11 @@ describe Api::V1::Accounts::StatusesController do
       let(:account)        { Fabricate(:account, username: 'bob', domain: 'example.com') }
       let(:status)         { Fabricate(:status, account: account) }
       let(:private_status) { Fabricate(:status, account: account, visibility: :private) }
-      let!(:pin)           { Fabricate(:status_pin, account: account, status: status) }
-      let!(:private_pin)   { Fabricate(:status_pin, account: account, status: private_status) }
+
+      before do
+        Fabricate(:status_pin, account: account, status: status)
+        Fabricate(:status_pin, account: account, status: private_status)
+      end
 
       it 'returns http success' do
         get :index, params: { account_id: account.id, pinned: true }