notes_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Accounts Notes API' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:scopes) { 'write:accounts' }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. let(:account) { Fabricate(:account) }
  9. let(:comment) { 'foo' }
  10. describe 'POST /api/v1/accounts/:account_id/note' do
  11. subject do
  12. post "/api/v1/accounts/#{account.id}/note", params: { comment: comment }, headers: headers
  13. end
  14. context 'when account note has reasonable length', :aggregate_failures do
  15. let(:comment) { 'foo' }
  16. it 'updates account note' do
  17. subject
  18. expect(response).to have_http_status(200)
  19. expect(response.content_type)
  20. .to start_with('application/json')
  21. expect(AccountNote.find_by(account_id: user.account.id, target_account_id: account.id).comment).to eq comment
  22. end
  23. end
  24. context 'when account note exceeds allowed length', :aggregate_failures do
  25. let(:comment) { 'a' * 2_001 }
  26. it 'does not create account note' do
  27. subject
  28. expect(response).to have_http_status(422)
  29. expect(response.content_type)
  30. .to start_with('application/json')
  31. expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id)).to_not exist
  32. end
  33. end
  34. end
  35. end