1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20231124

This commit is contained in:
KMY 2023-11-24 09:07:40 +09:00
commit c5e4020922
206 changed files with 1987 additions and 965 deletions

View file

@ -23,7 +23,7 @@ RSpec.describe 'Filters' do
get '/api/v2/filters', headers: headers
end
let!(:filters) { Fabricate.times(3, :custom_filter, account: user.account) }
let!(:filters) { Fabricate.times(2, :custom_filter, account: user.account) }
it_behaves_like 'forbidden for wrong scope', 'write write:filters'
it_behaves_like 'unauthorized for invalid token'

View file

@ -0,0 +1,37 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Instances' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id) }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
describe 'GET /api/v2/instance' do
context 'when logged out' do
it 'returns http success and json' do
get api_v2_instance_path
expect(response)
.to have_http_status(200)
expect(body_as_json)
.to be_present
.and include(title: 'Mastodon')
end
end
context 'when logged in' do
it 'returns http success and json' do
get api_v2_instance_path, headers: headers
expect(response)
.to have_http_status(200)
expect(body_as_json)
.to be_present
.and include(title: 'Mastodon')
end
end
end
end

View file

@ -9,10 +9,82 @@ RSpec.describe 'Media API', :paperclip_processing do
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
describe 'POST /api/v2/media' do
it 'returns http success' do
post '/api/v2/media', headers: headers, params: { file: fixture_file_upload('attachment-jpg.123456_abcd', 'image/jpeg') }
expect(File.exist?(user.account.media_attachments.first.file.path(:small))).to be true
expect(response).to have_http_status(200)
context 'when small media format attachment is processed immediately' do
let(:params) { { file: fixture_file_upload('attachment-jpg.123456_abcd', 'image/jpeg') } }
it 'returns http success' do
post '/api/v2/media', headers: headers, params: params
expect(File.exist?(user.account.media_attachments.first.file.path(:small)))
.to be true
expect(response)
.to have_http_status(200)
expect(body_as_json)
.to be_a(Hash)
end
end
context 'when large format media attachment has not been processed' do
let(:params) { { file: fixture_file_upload('attachment.webm', 'video/webm') } }
it 'returns http accepted' do
post '/api/v2/media', headers: headers, params: params
expect(File.exist?(user.account.media_attachments.first.file.path(:small)))
.to be true
expect(response)
.to have_http_status(202)
expect(body_as_json)
.to be_a(Hash)
end
end
describe 'when paperclip errors occur' do
let(:media_attachments) { double }
let(:params) { { file: fixture_file_upload('attachment.jpg', 'image/jpeg') } }
before do
allow(User).to receive(:find).with(token.resource_owner_id).and_return(user)
allow(user.account).to receive(:media_attachments).and_return(media_attachments)
end
context 'when imagemagick cannot identify the file type' do
before do
allow(media_attachments).to receive(:create!).and_raise(Paperclip::Errors::NotIdentifiedByImageMagickError)
end
it 'returns http unprocessable entity' do
post '/api/v2/media', headers: headers, params: params
expect(response)
.to have_http_status(422)
expect(body_as_json)
.to be_a(Hash)
.and include(error: /File type/)
end
end
context 'when there is a generic error' do
before do
allow(media_attachments).to receive(:create!).and_raise(Paperclip::Error)
end
it 'returns http 500' do
post '/api/v2/media', headers: headers, params: params
expect(response)
.to have_http_status(500)
expect(body_as_json)
.to be_a(Hash)
.and include(error: /processing/)
end
end
end
end
end