base_examples.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'base channel management' do |factory:, path:|
  3. describe "GET /api/v1/channels_admin/#{path}" do
  4. let(:channel) { create(factory) }
  5. before { channel }
  6. it 'lists channels' do
  7. get "/api/v1/channels/admin/#{path}", as: :json
  8. expect(json_response).to include(
  9. 'channel_ids' => [channel.id],
  10. 'assets' => be_present
  11. )
  12. end
  13. end
  14. describe "GET /api/v1/channels_admin/#{path}/ID/enable" do
  15. let(:channel) { create(factory, active: false) }
  16. before { channel }
  17. it 'enables channel' do
  18. expect { post "/api/v1/channels/admin/#{path}/#{channel.id}/enable", as: :json }
  19. .to change { channel.reload.active }
  20. .to true
  21. end
  22. end
  23. describe "GET /api/v1/channels_admin/#{path}/ID/disable" do
  24. let(:channel) { create(factory, active: true) }
  25. before { channel }
  26. it 'disables channel' do
  27. expect { post "/api/v1/channels/admin/#{path}/#{channel.id}/disable", as: :json }
  28. .to change { channel.reload.active }
  29. .to false
  30. end
  31. end
  32. describe "GET /api/v1/channels_admin/#{path}/ID/destroy" do
  33. let(:channel) { create(factory, active: true) }
  34. before { channel }
  35. it 'deletes channel' do
  36. expect { delete "/api/v1/channels/admin/#{path}/#{channel.id}", as: :json }
  37. .to change { Channel.exists? channel.id }
  38. .to false
  39. end
  40. end
  41. end