notes_controller_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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' do
  17. let(:comment) { 'foo' }
  18. it 'returns http success' do
  19. subject
  20. expect(response).to have_http_status(200)
  21. end
  22. it 'updates account note' do
  23. subject
  24. expect(AccountNote.find_by(account_id: user.account.id, target_account_id: account.id).comment).to eq comment
  25. end
  26. end
  27. context 'when account note exceeds allowed length' do
  28. let(:comment) { 'a' * 2_001 }
  29. it 'returns 422' do
  30. subject
  31. expect(response).to have_http_status(422)
  32. end
  33. it 'does not create account note' do
  34. subject
  35. expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id)).to_not exist
  36. end
  37. end
  38. end
  39. end