translation_update_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'KnowledgeBase translation update', type: :request, authenticated_as: :current_user do
  4. include_context 'basic Knowledge Base'
  5. let(:new_title) { 'new title for update test' }
  6. let(:current_user) { create(user_identifier) if defined?(user_identifier) }
  7. let(:params_for_updating) do
  8. {
  9. translations_attributes: [
  10. {
  11. title: new_title,
  12. footer_note: 'new footer',
  13. id: knowledge_base.kb_locales.first.id
  14. }
  15. ]
  16. }
  17. end
  18. let(:request) do
  19. patch "/api/v1/knowledge_bases/#{knowledge_base.id}?full=true", params: params_for_updating, as: :json
  20. end
  21. describe 'changes KB translation title' do
  22. describe 'as editor' do
  23. let(:user_identifier) { :admin }
  24. it 'updates title' do
  25. expect { request }.to change { knowledge_base.reload.translations.first.title }.to(new_title)
  26. end
  27. end
  28. describe 'as reader' do
  29. let(:user_identifier) { :agent }
  30. it 'does not change title' do
  31. expect { request }.not_to change { knowledge_base.reload.translations.first.title }
  32. end
  33. end
  34. describe 'as non-KB user' do
  35. let(:user_identifier) { :customer }
  36. it 'does not change title' do
  37. expect { request }.not_to change { knowledge_base.reload.translations.first.title }
  38. end
  39. end
  40. describe 'as a guest' do
  41. it 'does not change title' do
  42. expect { request }.not_to change { knowledge_base.reload.translations.first.title }
  43. end
  44. end
  45. end
  46. describe 'can make request to KB translation' do
  47. before { request }
  48. describe 'as editor' do
  49. let(:user_identifier) { :admin }
  50. it { expect(response).to have_http_status(:ok) }
  51. it { expect(json_response).to be_a_kind_of(Hash) }
  52. end
  53. describe 'as reader' do
  54. let(:user_identifier) { :agent }
  55. it { expect(response).to have_http_status(:forbidden) }
  56. end
  57. describe 'as non-KB user' do
  58. let(:user_identifier) { :customer }
  59. it { expect(response).to have_http_status(:forbidden) }
  60. end
  61. describe 'as a guest' do
  62. it { expect(response).to have_http_status(:forbidden) }
  63. end
  64. end
  65. end