notes_controller_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::V1::Accounts::NotesController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:accounts') }
  7. let(:account) { Fabricate(:account) }
  8. let(:comment) { 'foo' }
  9. before do
  10. allow(controller).to receive(:doorkeeper_token) { token }
  11. end
  12. describe 'POST #create' do
  13. subject do
  14. post :create, params: { account_id: account.id, comment: comment }
  15. end
  16. context 'when account note has reasonable length', :aggregate_failures do
  17. let(:comment) { 'foo' }
  18. it 'updates account note' do
  19. subject
  20. expect(response).to have_http_status(200)
  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(AccountNote.where(account_id: user.account.id, target_account_id: account.id)).to_not exist
  30. end
  31. end
  32. end
  33. end