diff --git a/app/controllers/knowledge_base/search_controller.rb b/app/controllers/knowledge_base/search_controller.rb index 010107171..b9b2bb94d 100644 --- a/app/controllers/knowledge_base/search_controller.rb +++ b/app/controllers/knowledge_base/search_controller.rb @@ -70,7 +70,7 @@ class KnowledgeBase::SearchController < ApplicationController end if include_locale && (system_locale = object.kb_locale.system_locale) - output[:title] += " (#{system_locale.name})" + output[:title] += " (#{system_locale.locale.upcase})" end output diff --git a/spec/requests/knowledge_base/search_with_details_spec.rb b/spec/requests/knowledge_base/search_with_details_spec.rb index 287217fd8..14d01332d 100644 --- a/spec/requests/knowledge_base/search_with_details_spec.rb +++ b/spec/requests/knowledge_base/search_with_details_spec.rb @@ -88,6 +88,27 @@ RSpec.describe 'Knowledge Base search with details', type: :request, searchindex end end + context 'when using include_locale parameter' do + context 'when no multiple locales exists' do + it 'no locale added to title' do + post endpoint, params: { query: published_answer.translations.first.title, include_locale: true } + expect(json_response['details'][0]['title']).to not_include('(EN-US)') + end + end + + context 'when multiple locales exists' do + before do + # Create a alternative knowledge base locale. + alternative_locale + end + + it 'locale added to title' do + post endpoint, params: { query: published_answer.translations.first.title, include_locale: true } + expect(json_response['details'][0]['title']).to include('(EN-US)') + end + end + end + context 'when using paging' do let(:answers) do Array.new(20) do |nth|