2019-09-24 15:44:32 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
RSpec.describe 'KnowledgeBase translation update', type: :request, authenticated_as: :current_user do
|
2019-09-24 15:44:32 +00:00
|
|
|
include_context 'basic Knowledge Base'
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
let(:new_title) { 'new title for update test' }
|
|
|
|
let(:current_user) { create(user_identifier) if defined?(user_identifier) }
|
2019-09-24 15:44:32 +00:00
|
|
|
|
|
|
|
let(:params_for_updating) do
|
|
|
|
{
|
2021-02-01 12:42:44 +00:00
|
|
|
translations_attributes: [
|
2019-09-24 15:44:32 +00:00
|
|
|
{
|
2021-02-01 12:42:44 +00:00
|
|
|
title: new_title,
|
|
|
|
footer_note: 'new footer',
|
|
|
|
id: knowledge_base.kb_locales.first.id
|
2019-09-24 15:44:32 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:request) do
|
|
|
|
patch "/api/v1/knowledge_bases/#{knowledge_base.id}?full=true", params: params_for_updating, as: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'changes KB translation title' do
|
2020-06-18 11:51:25 +00:00
|
|
|
describe 'as editor' do
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:user_identifier) { :admin }
|
2020-06-18 11:51:25 +00:00
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it 'updates title' do
|
|
|
|
expect { request }.to change { knowledge_base.reload.translations.first.title }.to(new_title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
describe 'as reader' do
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:user_identifier) { :agent }
|
2020-06-18 11:51:25 +00:00
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it 'does not change title' do
|
|
|
|
expect { request }.not_to change { knowledge_base.reload.translations.first.title }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
describe 'as non-KB user' do
|
|
|
|
let(:user_identifier) { :customer }
|
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it 'does not change title' do
|
|
|
|
expect { request }.not_to change { knowledge_base.reload.translations.first.title }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'as a guest' do
|
|
|
|
it 'does not change title' do
|
|
|
|
expect { request }.not_to change { knowledge_base.reload.translations.first.title }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'can make request to KB translation' do
|
|
|
|
before { request }
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
describe 'as editor' do
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:user_identifier) { :admin }
|
2020-06-18 11:51:25 +00:00
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
it { expect(json_response).to be_a_kind_of(Hash) }
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
describe 'as reader' do
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:user_identifier) { :agent }
|
2020-06-18 11:51:25 +00:00
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it { expect(response).to have_http_status(:unauthorized) }
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
describe 'as non-KB user' do
|
|
|
|
let(:user_identifier) { :customer }
|
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it { expect(response).to have_http_status(:unauthorized) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'as a guest' do
|
|
|
|
it { expect(response).to have_http_status(:unauthorized) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|