2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-11-06 00:12:25 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Api::V1::Accounts::NotesController do
|
|
|
|
render_views
|
|
|
|
|
2022-01-28 00:46:42 +01:00
|
|
|
let(:user) { Fabricate(:user) }
|
2021-11-06 00:12:25 +01:00
|
|
|
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
|
|
|
|
|
2023-10-13 14:42:09 +02:00
|
|
|
context 'when account note has reasonable length', :aggregate_failures do
|
2021-11-06 00:12:25 +01:00
|
|
|
let(:comment) { 'foo' }
|
|
|
|
|
|
|
|
it 'updates account note' do
|
|
|
|
subject
|
2023-10-13 14:42:09 +02:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2021-11-06 00:12:25 +01:00
|
|
|
expect(AccountNote.find_by(account_id: user.account.id, target_account_id: account.id).comment).to eq comment
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-13 14:42:09 +02:00
|
|
|
context 'when account note exceeds allowed length', :aggregate_failures do
|
2021-11-06 00:12:25 +01:00
|
|
|
let(:comment) { 'a' * 2_001 }
|
|
|
|
|
|
|
|
it 'does not create account note' do
|
|
|
|
subject
|
2023-10-13 14:42:09 +02:00
|
|
|
|
|
|
|
expect(response).to have_http_status(422)
|
2023-05-23 16:49:11 +02:00
|
|
|
expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id)).to_not exist
|
2021-11-06 00:12:25 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|