list_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::User::Overview::List do
  4. subject(:service) { described_class.new(user) }
  5. let(:user) { create(:agent) }
  6. let(:overview_1) { create(:overview, prio: 1) }
  7. let(:overview_2) { create(:overview, prio: 4) }
  8. let(:overview_3) { create(:overview, prio: 3) }
  9. let(:overview_4) { create(:overview, prio: 2) }
  10. before do
  11. Overview.destroy_all
  12. [overview_1, overview_2, overview_3, overview_4].each do |elem|
  13. elem.users << user
  14. end
  15. end
  16. context 'when no custom sorting exists' do
  17. it 'returns overviews in correct order' do
  18. expect(service.execute).to eq([overview_1, overview_4, overview_3, overview_2])
  19. end
  20. end
  21. context 'when custom sorting exists' do
  22. before do
  23. create(:user_overview_sorting, overview: overview_1, prio: 2, user:)
  24. create(:user_overview_sorting, overview: overview_2, prio: 1, user:)
  25. create(:user_overview_sorting, overview: overview_3, prio: 3, user:)
  26. create(:user_overview_sorting, overview: overview_4, prio: 4, user:)
  27. end
  28. it 'returns overviews in correct order' do
  29. expect(service.execute).to eq([overview_2, overview_1, overview_3, overview_4])
  30. end
  31. end
  32. context 'when some overviews are custom sorted' do
  33. before do
  34. create(:user_overview_sorting, overview: overview_2, prio: 3, user:)
  35. create(:user_overview_sorting, overview: overview_4, prio: 2, user:)
  36. end
  37. it 'returns overviews in correct order' do
  38. expect(service.execute).to eq([overview_4, overview_2, overview_1, overview_3])
  39. end
  40. end
  41. end