feat: API to download breached conversations (#9150)

* feat: add download conversations endpoint

* feat: template for conversation list download

* feat: setup download API and tests

* chore: revert formatting change

* feat: rename download method

* feat: rename template

* feat: include sla_policy table in download query

* refactor: add nil safety to assignee

* chore: Update en.yml

* fix: remove applied_sla relation
This commit is contained in:
Shivam Mishra
2024-03-26 09:22:49 +05:30
committed by GitHub
parent 9917cb4273
commit d1dd319091
5 changed files with 81 additions and 1 deletions

View File

@@ -104,6 +104,36 @@ RSpec.describe 'Applied SLAs API', type: :request do
end
end
describe 'GET /api/v1/accounts/{account.id}/applied_slas/download' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
get "/api/v1/accounts/#{account.id}/applied_slas/download"
expect(response).to have_http_status(:unauthorized)
end
end
context 'when it is an authenticated user' do
it 'returns a CSV file with breached conversations' do
create(:applied_sla, sla_policy: sla_policy1, conversation: conversation1, sla_status: 'missed')
create(:applied_sla, sla_policy: sla_policy1, conversation: conversation2, sla_status: 'missed')
conversation1.update(status: 'open')
conversation2.update(status: 'resolved')
get "/api/v1/accounts/#{account.id}/applied_slas/download",
headers: administrator.create_new_auth_token
expect(response).to have_http_status(:success)
expect(response.headers['Content-Type']).to eq('text/csv')
expect(response.headers['Content-Disposition']).to include('attachment; filename=breached_conversation.csv')
csv_data = CSV.parse(response.body)
csv_data.reject! { |row| row.all?(&:nil?) }
expect(csv_data.size).to eq(2)
expect(csv_data[1][0].to_i).to eq(conversation1.display_id)
end
end
end
describe 'GET /api/v1/accounts/{account.id}/applied_slas' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do