search_knowledge_base_backend_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. require 'rails_helper'
  2. RSpec.describe SearchKnowledgeBaseBackend do
  3. include_context 'basic Knowledge Base'
  4. let(:instance) { described_class.new options }
  5. let(:user) { create(:admin) }
  6. let(:options) do
  7. {
  8. knowledge_base: knowledge_base,
  9. locale: primary_locale,
  10. scope: nil
  11. }
  12. end
  13. context 'with ES', searchindex: true do
  14. before do
  15. configure_elasticsearch(required: true, rebuild: true) do
  16. published_answer
  17. end
  18. end
  19. describe '#search' do
  20. context 'when highlight enabled' do
  21. let(:options) do
  22. {
  23. knowledge_base: knowledge_base,
  24. locale: primary_locale,
  25. scope: nil,
  26. highlight_enabled: true
  27. }
  28. end
  29. # https://github.com/zammad/zammad/issues/3070
  30. it 'lists item with an attachment' do
  31. expect(instance.search('Hello World', user: user)).to be_present
  32. end
  33. end
  34. end
  35. end
  36. context 'with (out) ES is identical' do
  37. [true, false].each do |val|
  38. context "when ES=#{val}", searchindex: val do
  39. before do
  40. if val
  41. configure_elasticsearch(required: true, rebuild: true) do
  42. published_answer
  43. end
  44. else
  45. published_answer
  46. end
  47. end
  48. let(:first_result) { instance.search(published_answer.translations.first.title, user: user).first }
  49. it 'ID is an Integer' do
  50. expect(first_result.dig(:id)).to be_a(Integer)
  51. end
  52. end
  53. end
  54. end
  55. end