fix(captain): allow FAQ approval across languages
This commit is contained in:
@@ -9,7 +9,6 @@ class Captain::FaqSuggestionApprovalService
|
||||
raise ActiveRecord::RecordNotFound unless suggestion.open?
|
||||
|
||||
suggestion.update!(attributes) if attributes.present?
|
||||
validate_language!
|
||||
|
||||
response = suggestion.assistant.responses.create!(
|
||||
question: suggestion.question,
|
||||
@@ -24,15 +23,4 @@ class Captain::FaqSuggestionApprovalService
|
||||
private
|
||||
|
||||
attr_reader :suggestion, :attributes
|
||||
|
||||
def validate_language!
|
||||
return if base_language(suggestion.language) == base_language(suggestion.account.locale)
|
||||
|
||||
suggestion.errors.add(:language, 'must match the account locale before approval')
|
||||
raise ActiveRecord::RecordInvalid, suggestion
|
||||
end
|
||||
|
||||
def base_language(language)
|
||||
language.to_s.tr('-', '_').split('_').first
|
||||
end
|
||||
end
|
||||
|
||||
+13
@@ -138,6 +138,19 @@ RSpec.describe 'Api::V1::Accounts::Captain::FaqSuggestions', type: :request do
|
||||
expect(suggestion.reload).to be_approved
|
||||
end
|
||||
|
||||
it 'approves a suggestion written in a language other than the account locale' do
|
||||
suggestion.update!(language: 'pt')
|
||||
|
||||
expect do
|
||||
post "/api/v1/accounts/#{account.id}/captain/faq_suggestions/#{suggestion.id}/approve",
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
end.to change(assistant.responses.approved, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(suggestion.reload).to be_approved
|
||||
end
|
||||
|
||||
it 'does not let an agent approve an inaccessible suggestion' do
|
||||
expect do
|
||||
post "/api/v1/accounts/#{account.id}/captain/faq_suggestions/#{suggestion.id}/approve",
|
||||
|
||||
Reference in New Issue
Block a user