answers_spec.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'KnowledgeBase public answers', type: :request do
  4. include_context 'basic Knowledge Base'
  5. describe '#show' do
  6. context 'when visitor is a guest' do
  7. it 'returns OK for published answer' do
  8. get help_answer_path(locale_name, category, published_answer)
  9. expect(response).to have_http_status :ok
  10. end
  11. it 'returns NOT FOUND for draft answer' do
  12. get help_answer_path(locale_name, category, draft_answer)
  13. expect(response).to have_http_status :not_found
  14. end
  15. end
  16. context 'when visitor is an editor' do
  17. before do
  18. published_answer && draft_answer
  19. authenticated_as(create(:admin), via: :browser)
  20. end
  21. it 'returns OK for published answer' do
  22. get help_answer_path(locale_name, category, published_answer)
  23. expect(response).to have_http_status :ok
  24. end
  25. it 'returns OK for draft answer' do
  26. get help_answer_path(locale_name, category, draft_answer)
  27. expect(response).to have_http_status :ok
  28. end
  29. end
  30. end
  31. describe '#render_alternative' do
  32. context 'when a translation is available' do
  33. before { create(:knowledge_base_translation, kb_locale: alternative_locale) }
  34. it 'returns OK for published answer' do
  35. get help_answer_path(alternative_locale.system_locale.locale, category, published_answer)
  36. expect(response).to have_http_status :ok
  37. end
  38. it 'returns NOT FOUND for draft answer' do
  39. get help_answer_path(alternative_locale.system_locale.locale, category, draft_answer)
  40. expect(response).to have_http_status :not_found
  41. end
  42. # https://github.com/zammad/zammad/issues/3931
  43. context 'when the category has been updated' do
  44. let(:new_category) { create(:knowledge_base_category, knowledge_base: knowledge_base) }
  45. it 'returns NOT FOUND for published answer if old category is used' do
  46. published_answer.update! category_id: new_category.id
  47. get help_answer_path(alternative_locale.system_locale.locale, category, published_answer)
  48. expect(response).to have_http_status :not_found
  49. end
  50. it 'returns OK for published answer if new category is used' do
  51. published_answer.update! category_id: new_category.id
  52. get help_answer_path(alternative_locale.system_locale.locale, new_category, published_answer)
  53. expect(response).to have_http_status :ok
  54. end
  55. end
  56. end
  57. end
  58. end