You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

  1. require 'rails_helper'
  2. describe Api::V1::Accounts::NotesController do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:accounts') }
  6. let(:account) { Fabricate(:account) }
  7. let(:comment) { 'foo' }
  8. before do
  9. allow(controller).to receive(:doorkeeper_token) { token }
  10. end
  11. describe 'POST #create' do
  12. subject do
  13. post :create, params: { account_id: account.id, comment: comment }
  14. end
  15. context 'when account note has reasonable length' do
  16. let(:comment) { 'foo' }
  17. it 'returns http success' do
  18. subject
  19. expect(response).to have_http_status(200)
  20. end
  21. it 'updates account note' do
  22. subject
  23. expect(AccountNote.find_by(account_id: user.account.id, target_account_id: account.id).comment).to eq comment
  24. end
  25. end
  26. context 'when account note exceends allowed length' do
  27. let(:comment) { 'a' * 2_001 }
  28. it 'returns 422' do
  29. subject
  30. expect(response).to have_http_status(422)
  31. end
  32. it 'does not create account note' do
  33. subject
  34. expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id).exists?).to be_falsey
  35. end
  36. end
  37. end
  38. end