checks_kb_client_notification_job_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe ChecksKbClientNotificationJob, type: :job, performs_jobs: true do
  4. include_context 'basic Knowledge Base'
  5. describe 'pushes to users who have access' do
  6. let(:admin) { create(:admin) }
  7. let(:agent) { create(:agent) }
  8. let(:customer) { create(:customer) }
  9. before do
  10. allow_any_instance_of(described_class) # rubocop:disable RSpec/AnyInstance
  11. .to receive(:active_users)
  12. .and_return([admin, agent, customer])
  13. allow(PushMessages).to receive(:send_to)
  14. described_class.perform_now 'KnowledgeBase::Answer', answer.id
  15. end
  16. shared_examples 'message pushed to given users' do |prefix, **args|
  17. context "when answer is #{prefix}" do
  18. let(:answer) { send("#{prefix}_answer") }
  19. args.each do |key, value|
  20. it "#{key} #{value ? 'is' : 'not'} notified" do
  21. expect(PushMessages).send(value ? :to : :not_to, have_received(:send_to).with(send(key).id, any_args))
  22. end
  23. end
  24. end
  25. end
  26. include_examples 'message pushed to given users', 'published', admin: true, agent: true, customer: false
  27. include_examples 'message pushed to given users', 'internal', admin: true, agent: true, customer: false
  28. include_examples 'message pushed to given users', 'draft', admin: true, agent: false, customer: false
  29. include_examples 'message pushed to given users', 'archived', admin: true, agent: false, customer: false
  30. end
  31. end