list_examples.rb 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'Taskbar::List' do
  3. let(:user) { create(:user) }
  4. describe '.reorder_list' do
  5. let(:user) { create(:user) }
  6. let(:taskbar_1) { create(:taskbar, user:) }
  7. let(:taskbar_2) { create(:taskbar, user:) }
  8. let(:taskbar_3) { create(:taskbar, user:) }
  9. let(:taskbar_other) { create(:taskbar) }
  10. let(:target_order) do
  11. [
  12. { id: taskbar_1.id, prio: 3 },
  13. { id: taskbar_2.id, prio: 1 },
  14. { id: taskbar_3.id, prio: 2 },
  15. ]
  16. end
  17. before { taskbar_1 && taskbar_2 && taskbar_3 }
  18. it 'update order with given details' do
  19. described_class.reorder_list(user, target_order)
  20. scope = TaskbarPolicy::Scope.new(user, Taskbar)
  21. expect(scope.resolve).to eq([taskbar_2, taskbar_3, taskbar_1])
  22. end
  23. it 'works if non-existant ID included' do
  24. target_order.push({ id: 1234, prio: 1234 })
  25. described_class.reorder_list(user, target_order)
  26. scope = TaskbarPolicy::Scope.new(user, Taskbar)
  27. expect(scope.resolve).to eq([taskbar_2, taskbar_3, taskbar_1])
  28. end
  29. it 'ignores inaccessible taskbar' do
  30. test_prio = 1234
  31. target_order.push({ id: taskbar_other.id, prio: test_prio })
  32. described_class.reorder_list(user, target_order)
  33. expect(taskbar_other.reload).not_to have_attributes(prio: test_prio)
  34. end
  35. it 'trigger subscription after updating' do
  36. allow(described_class).to receive(:trigger_list_update)
  37. described_class.reorder_list(user, target_order)
  38. expect(described_class).to have_received(:trigger_list_update).with(user, 'desktop')
  39. end
  40. it 'do not trigger other subscriptions', aggregate_failures: true do
  41. allow(Gql::Subscriptions::TicketLiveUserUpdates).to receive(:trigger)
  42. allow(Gql::Subscriptions::User::Current::TaskbarItemUpdates).to receive(:trigger)
  43. allow(Gql::Subscriptions::User::Current::TaskbarItemStateUpdates).to receive(:trigger)
  44. described_class.reorder_list(user, target_order)
  45. expect(Gql::Subscriptions::TicketLiveUserUpdates).not_to have_received(:trigger)
  46. expect(Gql::Subscriptions::User::Current::TaskbarItemUpdates).not_to have_received(:trigger)
  47. expect(Gql::Subscriptions::User::Current::TaskbarItemStateUpdates).not_to have_received(:trigger)
  48. end
  49. end
  50. describe '.trigger_list_update' do
  51. it 'calls subscription with given params' do
  52. allow(Gql::Subscriptions::User::Current::TaskbarItem::ListUpdates).to receive(:trigger)
  53. described_class.trigger_list_update(user, 'test')
  54. expect(Gql::Subscriptions::User::Current::TaskbarItem::ListUpdates)
  55. .to have_received(:trigger)
  56. .with(nil, arguments: { user_id: user.to_global_id.to_s, app: 'test' })
  57. end
  58. end
  59. end