loading_initial_data_spec.rb 1.7 KB

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