loading_initial_data_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'KnowledgeBase loading initial data', authenticated_as: :current_user, searchindex: true, type: :request do
  4. include_context 'basic Knowledge Base' do
  5. before do
  6. draft_answer
  7. internal_answer
  8. published_answer
  9. end
  10. end
  11. before do
  12. post '/api/v1/knowledge_bases/init'
  13. end
  14. let(:current_user) { create(user_identifier) if defined?(user_identifier) }
  15. shared_examples 'returning valid JSON' do
  16. it { expect(response).to have_http_status(:ok) }
  17. it { expect(json_response).to be_a(Hash) }
  18. end
  19. describe 'for admin' do
  20. let(:user_identifier) { :admin }
  21. it_behaves_like 'returning valid JSON'
  22. it 'returns assets for all KB objects' do
  23. expect(json_response).to include_assets_of(knowledge_base, category, draft_answer, internal_answer, published_answer)
  24. end
  25. end
  26. describe 'for agent' do
  27. let(:user_identifier) { :agent }
  28. it_behaves_like 'returning valid JSON'
  29. it 'returns assets for all KB objects except drafts' do
  30. expect(json_response)
  31. .to include_assets_of(knowledge_base, category, internal_answer, published_answer)
  32. .and not_include_assets_of(draft_answer)
  33. end
  34. end
  35. describe 'for customer' do
  36. let(:user_identifier) { :customer }
  37. it_behaves_like 'returning valid JSON'
  38. it 'only returns assets for KB itself' do
  39. expect(json_response)
  40. .to include_assets_of(knowledge_base)
  41. .and not_include_assets_of(category, draft_answer, internal_answer, published_answer)
  42. end
  43. end
  44. describe 'for guests without authorization' do
  45. it { expect(response).to have_http_status(:forbidden) }
  46. end
  47. end