preview_spec.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'KnowledgeBase preview', authenticated_as: :user, type: :request do
  4. include_context 'basic Knowledge Base'
  5. let(:user) { create(:admin) }
  6. describe '#preview' do
  7. context 'when no custom URL is set' do
  8. it 'redirects to given knowledge base' do
  9. get "/api/v1/knowledge_bases/preview/KnowledgeBase/#{knowledge_base.id}/en"
  10. expect(response).to redirect_to(%r{^http://www.example.com/help/en})
  11. end
  12. it 'redirects to given category' do
  13. get "/api/v1/knowledge_bases/preview/KnowledgeBaseCategory/#{category.id}/en"
  14. expect(response).to redirect_to(%r{^http://www.example.com/help/en/#{category.id}})
  15. end
  16. it 'redirects to given answer' do
  17. get "/api/v1/knowledge_bases/preview/KnowledgeBaseCategory/#{published_answer.id}/en"
  18. expect(response).to redirect_to(%r{^http://www.example.com/help/en/#{published_answer.id}})
  19. end
  20. end
  21. context 'when custom path is set' do
  22. before do
  23. knowledge_base.update! custom_address: '/kb'
  24. end
  25. it 'redirects to given knowledge base' do
  26. get "/api/v1/knowledge_bases/preview/KnowledgeBase/#{knowledge_base.id}/en"
  27. expect(response).to redirect_to(%r{^http://www.example.com/kb/en})
  28. end
  29. it 'redirects to given category' do
  30. get "/api/v1/knowledge_bases/preview/KnowledgeBaseCategory/#{category.id}/en"
  31. expect(response).to redirect_to(%r{^http://www.example.com/kb/en/#{category.id}})
  32. end
  33. it 'redirects to given answer' do
  34. get "/api/v1/knowledge_bases/preview/KnowledgeBaseCategory/#{published_answer.id}/en"
  35. expect(response).to redirect_to(%r{^http://www.example.com/kb/en/#{published_answer.id}})
  36. end
  37. end
  38. context 'when custom URL is set' do
  39. before do
  40. knowledge_base.update! custom_address: 'kb.example.org'
  41. end
  42. it 'redirects to given knowledge base' do
  43. get "/api/v1/knowledge_bases/preview/KnowledgeBase/#{knowledge_base.id}/en"
  44. expect(response).to redirect_to(%r{^http://kb.example.org/en})
  45. end
  46. it 'redirects to given category' do
  47. get "/api/v1/knowledge_bases/preview/KnowledgeBaseCategory/#{category.id}/en"
  48. expect(response).to redirect_to(%r{^http://kb.example.org/en/#{category.id}})
  49. end
  50. it 'redirects to given answer' do
  51. get "/api/v1/knowledge_bases/preview/KnowledgeBaseCategory/#{published_answer.id}/en"
  52. expect(response).to redirect_to(%r{^http://kb.example.org/en/#{published_answer.id}})
  53. end
  54. end
  55. end
  56. end