feat: add a common upload endpoint (#7806)

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
Shivam Mishra
2023-08-31 10:36:02 +07:00
committed by GitHub
parent 25c3fb3c36
commit deec1d213b
11 changed files with 195 additions and 44 deletions

View File

@@ -0,0 +1,42 @@
require 'rails_helper'
RSpec.describe 'Api::V1::UploadController', type: :request do
describe 'POST /api/v1/upload/' do
let(:account) { create(:account) }
let(:user) { create(:user, account: account) }
it 'uploads the image when authorized' do
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
post '/api/v1/upload/',
headers: user.create_new_auth_token,
params: { attachment: file }
expect(response).to have_http_status(:success)
blob = response.parsed_body
expect(blob['errors']).to be_nil
expect(blob['file_url']).to be_present
expect(blob['blob_key']).to be_present
expect(blob['blob_id']).to be_present
end
it 'does not upload when un-authorized' do
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
post '/api/v1/upload/',
headers: {},
params: { attachment: file }
expect(response).to have_http_status(:unauthorized)
blob = response.parsed_body
expect(blob['errors']).to be_present
expect(blob['file_url']).to be_nil
expect(blob['blob_key']).to be_nil
expect(blob['blob_id']).to be_nil
end
end
end