Taskme update
This commit is contained in:
@@ -128,6 +128,26 @@ RSpec.describe Api::BroadcastsController, type: :controller do
|
||||
expect(included.first.dig("id")).to eq broadcast.files.first.id.to_s
|
||||
expect(included.first.dig("type")).to eq 'active_storage_attachment'
|
||||
end
|
||||
|
||||
context "when files param contains a signed_id string" do
|
||||
it "adds that file to the broadcast" do
|
||||
project = create(:project, name: 'first', account_id: current_user.primary_account.id)
|
||||
broadcast = create(:broadcast, :with_stream, skip_create_callback: true, project: project, status: 'created')
|
||||
blob = ActiveStorage::Blob.create_after_upload!(io: StringIO.new("Hello"), filename: "hello.txt", content_type: "text/plain")
|
||||
|
||||
sign_in_to_api(current_user)
|
||||
patch :update, params: { project_id: project, id: broadcast, broadcast: { files: [blob.signed_id] } }
|
||||
|
||||
relationships = JSON.parse(response.body).dig('data', 'relationships')
|
||||
included = JSON.parse(response.body).dig('included')
|
||||
|
||||
expect(relationships.keys).to include('files')
|
||||
expect(included.size).to eq 1
|
||||
expect(included.first.dig("id")).to eq broadcast.files.first.id.to_s
|
||||
expect(included.first.dig("type")).to eq 'active_storage_attachment'
|
||||
expect(included.first.dig("attributes", "filename")).to eq 'hello.txt'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
|
||||
36
spec/controllers/api/direct_uploads_controller_spec.rb
Normal file
36
spec/controllers/api/direct_uploads_controller_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::DirectUploadsController, type: :controller do
|
||||
let(:current_user) { create(:user) }
|
||||
let(:project) { create(:project, account: current_user.primary_account) }
|
||||
|
||||
before do
|
||||
sign_in_to_api(current_user)
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
it 'returns data for a direct upload' do
|
||||
post :create, params: { direct_upload: direct_upload_params }
|
||||
|
||||
expect(response).to be_successful
|
||||
expect(response_body_data_attributes).to include('id', 'key', 'signed_id', 'url', 'headers')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def direct_upload_params
|
||||
file = file_fixture("video_file.mp4")
|
||||
checksum = Digest::MD5.base64digest(StringIO.new(file.read).to_s)
|
||||
|
||||
{ filename: file.basename.to_s, content_type: "video/mp4", byte_size: file.size, checksum: checksum }
|
||||
end
|
||||
|
||||
def response_body_data
|
||||
JSON.parse(response.body).dig('data')
|
||||
end
|
||||
|
||||
def response_body_data_attributes
|
||||
response_body_data.dig('attributes')
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user