2023-02-22 09:55:31 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-11-06 08:12:25 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.describe 'Accounts Notes API' do
|
2023-12-11 16:58:48 +09:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:scopes) { 'write:accounts' }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
2021-11-06 08:12:25 +09:00
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:comment) { 'foo' }
|
|
|
|
|
2023-12-11 16:58:48 +09:00
|
|
|
describe 'POST /api/v1/accounts/:account_id/note' do
|
2021-11-06 08:12:25 +09:00
|
|
|
subject do
|
2023-12-11 16:58:48 +09:00
|
|
|
post "/api/v1/accounts/#{account.id}/note", params: { comment: comment }, headers: headers
|
2021-11-06 08:12:25 +09:00
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
context 'when account note has reasonable length', :aggregate_failures do
|
2021-11-06 08:12:25 +09:00
|
|
|
let(:comment) { 'foo' }
|
|
|
|
|
|
|
|
it 'updates account note' do
|
|
|
|
subject
|
2023-10-13 21:42:09 +09:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2021-11-06 08:12:25 +09:00
|
|
|
expect(AccountNote.find_by(account_id: user.account.id, target_account_id: account.id).comment).to eq comment
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
context 'when account note exceeds allowed length', :aggregate_failures do
|
2021-11-06 08:12:25 +09:00
|
|
|
let(:comment) { 'a' * 2_001 }
|
|
|
|
|
|
|
|
it 'does not create account note' do
|
|
|
|
subject
|
2023-10-13 21:42:09 +09:00
|
|
|
|
|
|
|
expect(response).to have_http_status(422)
|
2023-05-23 23:49:11 +09:00
|
|
|
expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id)).to_not exist
|
2021-11-06 08:12:25 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|