feat: common attachment endpoint follow-up changes (#7826)

This commit is contained in:
Shivam Mishra
2023-09-01 15:18:48 +07:00
committed by GitHub
parent 2acf09b3eb
commit 9ebabb9832
14 changed files with 11 additions and 114 deletions

View File

@@ -259,23 +259,5 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
expect(json_response['payload']['id']).to eq(root_article.id)
end
end
describe 'Upload an image' do
let(:article) { create(:article, account_id: account.id, category_id: category.id, portal_id: portal.id, author_id: agent.id) }
it 'update the article with an image' do
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
post "/api/v1/accounts/#{account.id}/portals/#{article.portal.slug}/articles/attach_file",
headers: agent.create_new_auth_token,
params: { background_image: file }
expect(response).to have_http_status(:success)
blob = response.parsed_body
expect(blob['file_url']).to be_present
end
end
end
end

View File

@@ -128,7 +128,7 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
expect(account.automation_rules.count).to eq(0)
post "/api/v1/accounts/#{account.id}/automation_rules/attach_file",
post '/api/v1/upload',
headers: administrator.create_new_auth_token,
params: { attachment: file }
@@ -163,13 +163,13 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
file_1 = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
file_2 = fixture_file_upload(Rails.root.join('spec/assets/sample.png'), 'image/png')
post "/api/v1/accounts/#{account.id}/automation_rules/attach_file",
post '/api/v1/upload',
headers: administrator.create_new_auth_token,
params: { attachment: file_1 }
blob_1 = response.parsed_body
post "/api/v1/accounts/#{account.id}/automation_rules/attach_file",
post '/api/v1/upload',
headers: administrator.create_new_auth_token,
params: { attachment: file_2 }

View File

@@ -129,7 +129,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
it 'Saves file in the macros actions to send an attachments' do
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
post "/api/v1/accounts/#{account.id}/macros/attach_file",
post '/api/v1/upload',
headers: administrator.create_new_auth_token,
params: { attachment: file }

View File

@@ -210,33 +210,4 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
end
end
end
describe 'POST /api/v1/accounts/{account.id}/portals/attach_file' do
it 'update the portal with a logo' do
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
post "/api/v1/accounts/#{account.id}/portals/attach_file",
headers: admin.create_new_auth_token,
params: { logo: file }
expect(response).to have_http_status(:success)
blob = response.parsed_body
expect(blob['blob_key']).to be_present
expect(blob['blob_id']).to be_present
params = { blob_id: blob['blob_id'] }
expect(portal.logo.attachment).not_to be_present
patch "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
headers: admin.create_new_auth_token,
params: params
portal.reload
expect(portal.logo.presence).to be_truthy
expect(portal.logo.attachment).to be_present
end
end
end