Added one more endpoint to attach tempfile and get logo (#6407)

This commit is contained in:
Tejaswini Chile
2023-02-09 14:05:45 +05:30
committed by GitHub
parent 0a7a5abec1
commit c5b245977a
8 changed files with 90 additions and 10 deletions

View File

@@ -86,15 +86,12 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
context 'when it is an authenticated user' do
it 'creates portal' do
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
portal_params = {
portal: {
name: 'test_portal',
slug: 'test_kbase',
custom_domain: 'https://support.chatwoot.dev'
},
logo: file
}
}
post "/api/v1/accounts/#{account.id}/portals",
params: portal_params,
@@ -103,7 +100,6 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response['name']).to eql('test_portal')
expect(json_response['logo']['filename']).to eql('avatar.png')
expect(json_response['custom_domain']).to eql('support.chatwoot.dev')
end
end
@@ -214,4 +210,33 @@ 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 = JSON.parse(response.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