58 lines
2.6 KiB
Go
58 lines
2.6 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.cin.su/m/Assistant/contracts/identity"
|
|
"git.cin.su/m/Assistant/contracts/interaction"
|
|
)
|
|
|
|
func TestNewHumanUtteranceClassifiesQuestionAndRequiresCognition(t *testing.T) {
|
|
conversation := interaction.Conversation{ID: "conversation-1", ActorID: "actor-1", PrincipalID: "principal-1", Channel: interaction.ChannelWebChat, State: interaction.ConversationOpen}
|
|
utterance, intent, relations, err := NewHumanUtterance(conversation, interaction.ChatMessageRequest{Message: "Кто ты?"}, time.Unix(10, 0))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if utterance.SpeechAct != interaction.SpeechActQuestion || !NeedsCognition(utterance.SpeechAct) {
|
|
t.Fatalf("expected cognitive question, got %s", utterance.SpeechAct)
|
|
}
|
|
if intent.Text != "Кто ты?" || len(relations) != 0 {
|
|
t.Fatalf("unexpected intent or relations")
|
|
}
|
|
}
|
|
|
|
func TestNewHumanUtteranceAppendsCorrectionRelation(t *testing.T) {
|
|
conversation := interaction.Conversation{ID: "conversation-1", ActorID: "actor-1", PrincipalID: "principal-1", Channel: interaction.ChannelWebChat, State: interaction.ConversationOpen}
|
|
utterance, _, relations, err := NewHumanUtterance(conversation, interaction.ChatMessageRequest{Message: "исправь прошлое", CorrectsUtteranceID: "utterance-0"}, time.Unix(10, 0))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if utterance.SpeechAct != interaction.SpeechActCorrection {
|
|
t.Fatalf("expected correction, got %s", utterance.SpeechAct)
|
|
}
|
|
if len(relations) != 1 || relations[0].Kind != interaction.RelationCorrects || relations[0].ToUtteranceID != "utterance-0" {
|
|
t.Fatalf("unexpected correction relation: %#v", relations)
|
|
}
|
|
}
|
|
|
|
func TestNewHumanUtteranceClassifiesReminderAndCapabilityConnectionAsDirective(t *testing.T) {
|
|
conversation := interaction.Conversation{ID: "conversation-1", ActorID: "actor-1", PrincipalID: "principal-1", Channel: interaction.ChannelWebChat, State: interaction.ConversationOpen}
|
|
for _, message := range []string{"Напомни завтра позвонить врачу.", "Подключи интеграцию с неизвестным сервисом."} {
|
|
utterance, _, _, err := NewHumanUtterance(conversation, interaction.ChatMessageRequest{Message: message}, time.Unix(10, 0))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if utterance.SpeechAct != interaction.SpeechActDirective {
|
|
t.Fatalf("expected directive for %q, got %s", message, utterance.SpeechAct)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNewConversationRequiresActorAndPrincipal(t *testing.T) {
|
|
_, err := NewConversation(identity.ActorID(""), identity.PrincipalID("principal-1"), time.Unix(10, 0))
|
|
if err == nil {
|
|
t.Fatal("expected invalid principal")
|
|
}
|
|
}
|