overview_sorting_spec.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'User Overview sorting', authenticated_as: :user, type: :request do
  4. let(:user) { create(:agent) }
  5. let(:overview) { Overview.first }
  6. let(:overview_sorting) { create(:user_overview_sorting, overview:, user:) }
  7. describe 'GET /user_overview_sortings' do
  8. it 'returns overviews and overview sortings' do
  9. overview_sorting
  10. get '/api/v1/user_overview_sortings'
  11. expect(json_response)
  12. .to include(
  13. 'overviews' => include(include('id' => overview.id)),
  14. 'overview_sortings' => include(include('id' => overview_sorting.id))
  15. )
  16. end
  17. end
  18. describe 'POST /user_overview_sortings_prio' do
  19. it 'calls sorting creation service', aggregate_failures: true do
  20. allow(Service::User::Overview::UpdateOrder)
  21. .to receive(:new)
  22. .and_call_original
  23. expect_any_instance_of(Service::User::Overview::UpdateOrder)
  24. .to receive(:execute)
  25. .and_call_original
  26. post '/api/v1/user_overview_sortings_prio',
  27. params: { prios: [[overview.id, 0]] }
  28. expect(Service::User::Overview::UpdateOrder)
  29. .to have_received(:new)
  30. expect(response).to have_http_status(:ok)
  31. end
  32. it 'triggers subscription' do
  33. allow(Gql::Subscriptions::User::Current::OverviewOrderingUpdates).to receive(:trigger_by)
  34. post '/api/v1/user_overview_sortings_prio',
  35. params: { prios: [[overview.id, 0]] }
  36. expect(Gql::Subscriptions::User::Current::OverviewOrderingUpdates)
  37. .to have_received(:trigger_by).with(user)
  38. end
  39. end
  40. describe 'DELETE /user_overview_sortings/:id' do
  41. it 'deletes given sorting' do
  42. expect { delete "/api/v1/user_overview_sortings/#{overview_sorting.id}" }
  43. .to change { User::OverviewSorting.exists? overview_sorting.id }
  44. .to false
  45. end
  46. it 'triggers subscription' do
  47. allow(Gql::Subscriptions::User::Current::OverviewOrderingUpdates).to receive(:trigger_by)
  48. delete "/api/v1/user_overview_sortings/#{overview_sorting.id}"
  49. expect(Gql::Subscriptions::User::Current::OverviewOrderingUpdates)
  50. .to have_received(:trigger_by).with(user)
  51. end
  52. end
  53. end