2019-09-24 15:44:32 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
RSpec.describe 'KnowledgeBase loading initial data', type: :request, searchindex: true, authenticated_as: :current_user do
|
2019-09-24 15:44:32 +00:00
|
|
|
include_context 'basic Knowledge Base' do
|
|
|
|
before do
|
|
|
|
draft_answer
|
|
|
|
internal_answer
|
|
|
|
published_answer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
post '/api/v1/knowledge_bases/init'
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
let(:current_user) { create(user_identifier) if defined?(user_identifier) }
|
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
shared_examples 'returning valid JSON' do
|
|
|
|
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 'for admin' do
|
|
|
|
let(:user_identifier) { :admin }
|
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it_behaves_like 'returning valid JSON'
|
|
|
|
|
|
|
|
it 'returns assets for all KB objects' do
|
|
|
|
expect(json_response).to include_assets_of(knowledge_base, category, draft_answer, internal_answer, published_answer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
describe 'for agent' do
|
|
|
|
let(:user_identifier) { :agent }
|
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it_behaves_like 'returning valid JSON'
|
|
|
|
|
|
|
|
it 'returns assets for all KB objects except drafts' do
|
|
|
|
expect(json_response)
|
|
|
|
.to include_assets_of(knowledge_base, category, internal_answer, published_answer)
|
|
|
|
.and not_include_assets_of(draft_answer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
describe 'for customer' do
|
|
|
|
let(:user_identifier) { :customer }
|
|
|
|
|
2019-09-24 15:44:32 +00:00
|
|
|
it_behaves_like 'returning valid JSON'
|
|
|
|
|
|
|
|
it 'only returns assets for KB itself' do
|
|
|
|
expect(json_response)
|
|
|
|
.to include_assets_of(knowledge_base)
|
|
|
|
.and not_include_assets_of(category, draft_answer, internal_answer, published_answer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'for guests without authorization' do
|
2021-02-04 08:28:41 +00:00
|
|
|
it { expect(response).to have_http_status(:forbidden) }
|
2019-09-24 15:44:32 +00:00
|
|
|
end
|
|
|
|
end
|