fix(captain): evita erro ao adicionar FAQ com pergunta longa
Some checks failed
Some checks failed
This commit is contained in:
parent
21f5fcce6a
commit
60079a1b9e
@ -2,7 +2,7 @@
|
||||
import { reactive, computed, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useVuelidate } from '@vuelidate/core';
|
||||
import { required, minLength } from '@vuelidate/validators';
|
||||
import { required, minLength, maxLength } from '@vuelidate/validators';
|
||||
import { useMapGetter } from 'dashboard/composables/store';
|
||||
|
||||
import Input from 'dashboard/components-next/input/Input.vue';
|
||||
@ -39,11 +39,17 @@ const initialState = {
|
||||
assistant_id: '',
|
||||
};
|
||||
|
||||
const QUESTION_MAX_LENGTH = 255;
|
||||
|
||||
const state = reactive({ ...initialState });
|
||||
|
||||
const validationRules = computed(() => {
|
||||
const rules = {
|
||||
question: { required, minLength: minLength(1) },
|
||||
question: {
|
||||
required,
|
||||
minLength: minLength(1),
|
||||
maxLength: maxLength(QUESTION_MAX_LENGTH),
|
||||
},
|
||||
answer: { required, minLength: minLength(1) },
|
||||
};
|
||||
|
||||
@ -123,6 +129,7 @@ watch(
|
||||
:placeholder="t('CAPTAIN.RESPONSES.FORM.QUESTION.PLACEHOLDER')"
|
||||
:message="formErrors.question"
|
||||
:message-type="formErrors.question ? 'error' : 'info'"
|
||||
:maxlength="QUESTION_MAX_LENGTH"
|
||||
/>
|
||||
<Editor
|
||||
v-model="state.answer"
|
||||
|
||||
@ -18,6 +18,8 @@ import NextButton from 'dashboard/components-next/button/Button.vue';
|
||||
import Editor from 'dashboard/components-next/Editor/Editor.vue';
|
||||
import { useUISettings } from 'dashboard/composables/useUISettings';
|
||||
|
||||
const FAQ_QUESTION_MAX_LENGTH = 255;
|
||||
|
||||
export default {
|
||||
components: {
|
||||
AddCannedModal,
|
||||
@ -93,6 +95,11 @@ export default {
|
||||
this.message.content_attributes ?? this.message.contentAttributes
|
||||
);
|
||||
},
|
||||
faqQuestion() {
|
||||
return (this.plainTextContent || '')
|
||||
.trim()
|
||||
.slice(0, FAQ_QUESTION_MAX_LENGTH);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleEnterKey(e) {
|
||||
@ -251,7 +258,7 @@ export default {
|
||||
ref="faqDialog"
|
||||
type="create"
|
||||
:selected-response="{
|
||||
question: plainTextContent,
|
||||
question: faqQuestion,
|
||||
assistant_id: copilotAssistant?.id,
|
||||
}"
|
||||
@close="hideFaqModal"
|
||||
|
||||
@ -30,7 +30,7 @@ class Captain::AssistantResponse < ApplicationRecord
|
||||
belongs_to :documentable, polymorphic: true, optional: true
|
||||
has_neighbors :embedding, normalize: true
|
||||
|
||||
validates :question, presence: true
|
||||
validates :question, presence: true, length: { maximum: 255 }
|
||||
validates :answer, presence: true
|
||||
|
||||
before_validation :ensure_account
|
||||
|
||||
@ -197,6 +197,22 @@ RSpec.describe 'Api::V1::Accounts::Captain::AssistantResponses', type: :request
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it 'returns unprocessable entity when question exceeds 255 characters' do
|
||||
long_question = 'a' * 256
|
||||
post "/api/v1/accounts/#{account.id}/captain/assistant_responses",
|
||||
params: {
|
||||
assistant_response: {
|
||||
question: long_question,
|
||||
answer: 'Test answer',
|
||||
assistant_id: assistant.id
|
||||
}
|
||||
},
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user