about summary refs log tree commit diff
path: root/spec/controllers/api/v1/accounts/notes_controller_spec.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-11-06 00:12:25 +0100
committerGitHub <noreply@github.com>2021-11-06 00:12:25 +0100
commit87085a5152011b2f5595feba2a6c4d56a2b425f0 (patch)
tree2140bc1044a84d308a2f8ae8cf52832ce5a8d6d1 /spec/controllers/api/v1/accounts/notes_controller_spec.rb
parent39cdf61ab7be267a374c472c230b315971ead43c (diff)
Fix AccountNote not having a maximum length (#16942)
Diffstat (limited to 'spec/controllers/api/v1/accounts/notes_controller_spec.rb')
-rw-r--r--spec/controllers/api/v1/accounts/notes_controller_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/controllers/api/v1/accounts/notes_controller_spec.rb b/spec/controllers/api/v1/accounts/notes_controller_spec.rb
new file mode 100644
index 000000000..0a2957fed
--- /dev/null
+++ b/spec/controllers/api/v1/accounts/notes_controller_spec.rb
@@ -0,0 +1,48 @@
+require 'rails_helper'
+
+describe Api::V1::Accounts::NotesController do
+  render_views
+
+  let(:user)    { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
+  let(:token)   { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:accounts') }
+  let(:account) { Fabricate(:account) }
+  let(:comment) { 'foo' }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'POST #create' do
+    subject do
+      post :create, params: { account_id: account.id, comment: comment }
+    end
+
+    context 'when account note has reasonable length' do
+      let(:comment) { 'foo' }
+
+      it 'returns http success' do
+        subject
+        expect(response).to have_http_status(200)
+      end
+
+      it 'updates account note' do
+        subject
+        expect(AccountNote.find_by(account_id: user.account.id, target_account_id: account.id).comment).to eq comment
+      end
+    end
+
+    context 'when account note exceends allowed length' do
+      let(:comment) { 'a' * 2_001 }
+
+      it 'returns 422' do
+        subject
+        expect(response).to have_http_status(422)
+      end
+
+      it 'does not create account note' do
+        subject
+        expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id).exists?).to be_falsey
+      end
+    end
+  end
+end