Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a952232cc9 | |||
| 4dc3f22784 |
@@ -11,15 +11,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ActionNativeFeedback = "sys_action_like_component"
|
ActionNativeFeedback = "sys_action_like_component"
|
||||||
ActionFeedbackUp = "dobotai_feedback_up"
|
ActionFeedbackUp = "dobotai_feedback_up"
|
||||||
ActionFeedbackDown = "dobotai_feedback_down"
|
ActionFeedbackDown = "dobotai_feedback_down"
|
||||||
ActionReasonIncorrect = "dobotai_reason_incorrect"
|
ActionReasonIncorrect = "dobotai_reason_incorrect"
|
||||||
ActionReasonNotResolved = "dobotai_reason_not_resolved"
|
ActionReasonNotResolved = "dobotai_reason_not_resolved"
|
||||||
ActionReasonIrrelevant = "dobotai_reason_irrelevant"
|
ActionReasonIrrelevant = "dobotai_reason_irrelevant"
|
||||||
ActionReasonUnclear = "dobotai_reason_unclear"
|
ActionReasonUnclear = "dobotai_reason_unclear"
|
||||||
ActionReasonOutdated = "dobotai_reason_outdated"
|
ActionReasonOutdated = "dobotai_reason_outdated"
|
||||||
ActionReasonOther = "dobotai_reason_other"
|
ActionReasonOther = "dobotai_reason_other"
|
||||||
|
ActionReasonContentMismatch = "dobotai_reason_content_mismatch"
|
||||||
|
ActionReasonContentIncomplete = "dobotai_reason_content_incomplete"
|
||||||
|
ActionReasonIllogical = "dobotai_reason_illogical_expression"
|
||||||
|
ActionReasonFactualError = "dobotai_reason_factual_error"
|
||||||
|
ActionReasonSensitiveContent = "dobotai_reason_sensitive_content"
|
||||||
|
ActionReasonAnswerNotWanted = "dobotai_reason_answer_not_wanted"
|
||||||
)
|
)
|
||||||
|
|
||||||
var nativeReasonByTag = map[string]string{
|
var nativeReasonByTag = map[string]string{
|
||||||
@@ -166,6 +172,18 @@ func oneFeedbackAction(action string) (string, string, bool) {
|
|||||||
return feedbackdomain.ValueDown, feedbackdomain.ReasonOutdated, true
|
return feedbackdomain.ValueDown, feedbackdomain.ReasonOutdated, true
|
||||||
case ActionReasonOther:
|
case ActionReasonOther:
|
||||||
return feedbackdomain.ValueDown, feedbackdomain.ReasonOther, true
|
return feedbackdomain.ValueDown, feedbackdomain.ReasonOther, true
|
||||||
|
case ActionReasonContentMismatch:
|
||||||
|
return feedbackdomain.ValueDown, feedbackdomain.ReasonContentMismatch, true
|
||||||
|
case ActionReasonContentIncomplete:
|
||||||
|
return feedbackdomain.ValueDown, feedbackdomain.ReasonContentIncomplete, true
|
||||||
|
case ActionReasonIllogical:
|
||||||
|
return feedbackdomain.ValueDown, feedbackdomain.ReasonIllogical, true
|
||||||
|
case ActionReasonFactualError:
|
||||||
|
return feedbackdomain.ValueDown, feedbackdomain.ReasonFactualError, true
|
||||||
|
case ActionReasonSensitiveContent:
|
||||||
|
return feedbackdomain.ValueDown, feedbackdomain.ReasonSensitiveContent, true
|
||||||
|
case ActionReasonAnswerNotWanted:
|
||||||
|
return feedbackdomain.ValueDown, feedbackdomain.ReasonAnswerNotWanted, true
|
||||||
default:
|
default:
|
||||||
return "", "", false
|
return "", "", false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,36 @@ func TestCardFeedbackRejectsMalformedNativeEvents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCardFeedbackMapsCustomExactReasons(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
action string
|
||||||
|
reason string
|
||||||
|
}{
|
||||||
|
{ActionReasonContentMismatch, feedbackdomain.ReasonContentMismatch},
|
||||||
|
{ActionReasonContentIncomplete, feedbackdomain.ReasonContentIncomplete},
|
||||||
|
{ActionReasonIllogical, feedbackdomain.ReasonIllogical},
|
||||||
|
{ActionReasonFactualError, feedbackdomain.ReasonFactualError},
|
||||||
|
{ActionReasonSensitiveContent, feedbackdomain.ReasonSensitiveContent},
|
||||||
|
{ActionReasonAnswerNotWanted, feedbackdomain.ReasonAnswerNotWanted},
|
||||||
|
}
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.action, func(t *testing.T) {
|
||||||
|
service := &fakeFeedbackService{result: feedbackdomain.Result{Changed: true, Value: feedbackdomain.ValueDown, ReasonCode: tc.reason}}
|
||||||
|
handler, _ := NewCardFeedbackHandler(service)
|
||||||
|
response, err := handler.HandleSDK(context.Background(), cardRequest(tc.action))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if service.calls != 1 || service.command.Value != feedbackdomain.ValueDown || service.command.ReasonCode != tc.reason {
|
||||||
|
t.Fatalf("calls=%d command=%+v", service.calls, service.command)
|
||||||
|
}
|
||||||
|
if response == nil || response.UserPrivateData == nil || response.UserPrivateData.CardParamMap["feedbackReasonSelected"] != tc.reason {
|
||||||
|
t.Fatalf("response=%+v", response)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCardFeedbackMapsWhitelistedActions(t *testing.T) {
|
func TestCardFeedbackMapsWhitelistedActions(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
action string
|
action string
|
||||||
|
|||||||
Reference in New Issue
Block a user