Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/app/therapy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func relayTherapyMessage(text string, session *Session) {
//coverage:ignore
// Send immediate feedback message to let user know we're processing
thinkingMessageKey := getRandomThinkingMessage(session)
setOutputText(thinkingMessageKey, session)
sendMessage(thinkingMessageKey, session)

// Send the actual request to the therapy endpoint
reply := callTherapySessionEndpoint(text, session)
Expand Down
139 changes: 26 additions & 113 deletions internal/app/therapy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,13 @@ func TestRelayTherapyMessage(t *testing.T) {

relayTherapyMessage("hi", session)

if len(session.Job.Output) < 2 {
t.Fatalf("expected at least two outputs (immediate feedback + response)")
}

// First output should be a thinking message
firstOutput := session.Job.Output[0]
validThinkingKeys := []string{
"therapy_thinking_1",
"therapy_thinking_2",
"therapy_thinking_3",
"therapy_thinking_4",
"therapy_thinking_5",
}

found := false
for _, validKey := range validThinkingKeys {
if firstOutput.TextID == validKey {
found = true
break
}
// The thinking message is sent immediately via sendMessage, so it won't be in the output
// Only the actual therapy response should be in the output
if len(session.Job.Output) == 0 {
t.Fatalf("expected at least one output (therapy response)")
}

if !found {
t.Fatalf("expected first output to be a thinking message, got %s", firstOutput.TextID)
}

// Second output should be the actual therapy response
if session.Job.Output[1].TextID != "Hello, I'm here for you." {
t.Fatalf("unexpected relay text: %s", session.Job.Output[1].TextID)
if session.Job.Output[0].TextID != "Hello, I'm here for you." {
t.Fatalf("unexpected relay text: %s", session.Job.Output[0].TextID)
}
}

Expand Down Expand Up @@ -173,35 +151,13 @@ func TestHandleSession_ForwardDuringActive(t *testing.T) {

handleSession(session)

if len(session.Job.Output) < 2 {
t.Fatalf("expected at least two outputs (immediate feedback + response), got %v", session.Job.Output)
}

// First output should be a thinking message
firstOutput := session.Job.Output[0]
validThinkingKeys := []string{
"therapy_thinking_1",
"therapy_thinking_2",
"therapy_thinking_3",
"therapy_thinking_4",
"therapy_thinking_5",
}

found := false
for _, validKey := range validThinkingKeys {
if firstOutput.TextID == validKey {
found = true
break
}
// The thinking message is sent immediately via sendMessage, so it won't be in the output
// Only the actual therapy response should be in the output
if len(session.Job.Output) == 0 {
t.Fatalf("expected at least one output (therapy response)")
}

if !found {
t.Fatalf("expected first output to be a thinking message, got %s", firstOutput.TextID)
}

// Second output should be the actual therapy response
if session.Job.Output[1].TextID != "Therapist reply" {
t.Fatalf("expected Therapist reply in second output, got %v", session.Job.Output)
if session.Job.Output[0].TextID != "Therapist reply" {
t.Fatalf("expected Therapist reply, got %v", session.Job.Output)
}
}

Expand Down Expand Up @@ -239,35 +195,13 @@ func TestRelayTherapyMessage_ExistingSessionContinues(t *testing.T) {

relayTherapyMessage("hi", session)

if len(session.Job.Output) < 2 {
t.Fatalf("expected at least two outputs (immediate feedback + response)")
}

// First output should be a thinking message
firstOutput := session.Job.Output[0]
validThinkingKeys := []string{
"therapy_thinking_1",
"therapy_thinking_2",
"therapy_thinking_3",
"therapy_thinking_4",
"therapy_thinking_5",
}

found := false
for _, validKey := range validThinkingKeys {
if firstOutput.TextID == validKey {
found = true
break
}
// The thinking message is sent immediately via sendMessage, so it won't be in the output
// Only the actual therapy response should be in the output
if len(session.Job.Output) == 0 {
t.Fatalf("expected at least one output (therapy response)")
}

if !found {
t.Fatalf("expected first output to be a thinking message, got %s", firstOutput.TextID)
}

// Second output should be the actual therapy response
if session.Job.Output[1].TextID != "Hello again" {
t.Fatalf("unexpected relay text: %s", session.Job.Output[1].TextID)
if session.Job.Output[0].TextID != "Hello again" {
t.Fatalf("unexpected relay text: %s", session.Job.Output[0].TextID)
}
}

Expand Down Expand Up @@ -359,37 +293,16 @@ func TestRelayTherapyMessageWithImmediateFeedback(t *testing.T) {
// Call relayTherapyMessage
relayTherapyMessage("I'm feeling anxious about work", session)

// Check that we got at least 2 outputs: immediate feedback + actual response
if len(session.Job.Output) < 2 {
t.Fatalf("expected at least 2 outputs, got %d", len(session.Job.Output))
}

// Check that the first output is a thinking message
firstOutput := session.Job.Output[0]
validThinkingKeys := []string{
"therapy_thinking_1",
"therapy_thinking_2",
"therapy_thinking_3",
"therapy_thinking_4",
"therapy_thinking_5",
}

found := false
for _, validKey := range validThinkingKeys {
if firstOutput.TextID == validKey {
found = true
break
}
}

if !found {
t.Fatalf("expected first output to be a thinking message, got %s", firstOutput.TextID)
// The thinking message is sent immediately via sendMessage, so it won't be in the output
// Only the actual therapy response should be in the output
if len(session.Job.Output) == 0 {
t.Fatalf("expected at least one output (therapy response)")
}

// Check that the second output is the actual therapy response
secondOutput := session.Job.Output[1]
if !strings.Contains(secondOutput.TextID, "I understand your concerns") {
t.Fatalf("expected therapy response in second output TextID, got: %s", secondOutput.TextID)
// Check that the output is the actual therapy response
output := session.Job.Output[0]
if !strings.Contains(output.TextID, "I understand your concerns") {
t.Fatalf("expected therapy response in output TextID, got: %s", output.TextID)
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/translator/translations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const translationsJSON = `{
"therapy_session_ended": "Your therapy session has ended. You can start a new one anytime with /therapy.",
"your_last_note": "Here’s your most recent note 👇\n\n",
"no_notes": "You haven’t added any entries yet. Start by sharing your thoughts and feelings with CapyMind.",
"commands_hint": "Here are the commands you can use to interact with CapyMind 👇\n\n/start Begin using the bot\n/note Make a journal entry\n/last View your most recent entry\n/analysis Receive an analysis of your journal\n/settings Settings\n/language Set your language preference\n/timezone Set your time zone\n/feedback Give feedback \n/help Get assistance with using CapyMind\n",
"commands_hint": "Here are the commands you can use to interact with CapyMind 👇\n\n/start Begin using the bot\n/note Make a journal entry\n/last View your most recent entry\n/analysis Receive an analysis of your journal\n/therapy Start therapy session\n/settings Settings\n/language Set your language preference\n/timezone Set your time zone\n/feedback Give feedback \n/help Get assistance with using CapyMind\n",
"locale_set": "Your language settings have been successfully updated 🌍",
"language_select": "Select your preferred language 👇",
"timezone_select": "Select your time zone 👇",
Expand Down Expand Up @@ -107,7 +107,7 @@ const translationsJSON = `{
"therapy_session_ended": "Сесію терапії завершено. Ви можете розпочати нову командою /therapy.",
"your_last_note": "Ось ваш останній запис 👇\n\n",
"no_notes": "Ви ще не додали жодних записів. Почніть, поділившись своїми думками та почуттями з CapyMind.",
"commands_hint": "Ось команди, які ви можете використовувати для взаємодії з CapyMind 👇\n\n/start Почати використання бота\n/note Зробити запис у журнал\n/last Переглянути ваш останній запис\n/analysis Отримати аналіз вашого журналу\n/settings Налаштування\n/language Встановити мову\n/timezone Встановити ваш часовий пояс\n/feedback Залишити відгук\n/help Отримати допомогу з використання CapyMind\n",
"commands_hint": "Ось команди, які ви можете використовувати для взаємодії з CapyMind 👇\n\n/start Почати використання бота\n/note Зробити запис у журнал\n/last Переглянути ваш останній запис\n/analysis Отримати аналіз вашого журналу\n/therapy Розпочати сесію терапії\n/settings Налаштування\n/language Встановити мову\n/timezone Встановити ваш часовий пояс\n/feedback Залишити відгук\n/help Отримати допомогу з використання CapyMind\n",
"locale_set": "Ваші налаштування мови успішно оновлено 🌍",
"language_select": "Виберіть вашу мову 👇",
"timezone_select": "Виберіть свій часовий пояс 👇",
Expand Down