Skip to content

Commit

Permalink
chore: misc update on support (#4399)
Browse files Browse the repository at this point in the history
* chore: misc update on support

* fix: linting

---------

Co-authored-by: Nicolas Burtey <[email protected]>
  • Loading branch information
nicolasburtey and Nicolas Burtey authored Apr 30, 2024
1 parent 494fc3c commit 7887a02
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
38 changes: 38 additions & 0 deletions bats/core/api/support.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load "../../helpers/user.bash"

setup_file() {
create_user 'alice'
}

@test "support: ask 2 questions and then reset the chat" {
exec_graphql 'alice' 'support-chat'
messages="$(graphql_output '.data.me.supportChat')"
[[ "$messages" == "[]" ]] || exit 1

local variables=$(
jq -n \
'{input: {message: "Hello"}}'
)
exec_graphql 'alice' 'support-chat-message-add' "$variables"
messages="$(graphql_output '.data.supportChatMessageAdd.supportMessage')"
length=$(echo "$messages" | jq '. | length')
[[ $length -eq 4 ]] || exit 1

local variables=$(
jq -n \
'{input: {message: "My transaction is stuck"}}'
)
exec_graphql 'alice' 'support-chat-message-add' "$variables"
messages="$(graphql_output '.data.supportChatMessageAdd.supportMessage')"
length=$(echo "$messages" | jq '. | length')
[[ $length -eq 6 ]] || exit 1

exec_graphql 'alice' 'support-chat-reset' "$variables"
success="$(graphql_output '.data.supportChatReset.success')"
[[ "$success" == "true" ]] || exit 1

exec_graphql 'alice' 'support-chat'
messages="$(graphql_output '.data.me.supportChat')"
length=$(echo "$messages" | jq '. | length')
[[ $length -eq 2 ]] || exit 1
}
33 changes: 0 additions & 33 deletions bats/core/api/user.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,3 @@ setup_file() {
language="$(graphql_output '.data.me.language')"
[[ "$language" == "$new_language" ]] || exit 1
}

@test "support: ask 2 questions and then reset the chat" {
exec_graphql 'alice' 'support-chat'
messages="$(graphql_output '.data.me.supportChat')"
[[ "$messages" == "[]" ]] || exit 1

local variables=$(
jq -n \
'{input: {message: "Hello"}}'
)
exec_graphql 'alice' 'support-chat-message-add' "$variables"
messages="$(graphql_output '.data.supportChatMessageAdd.supportMessage')"
length=$(echo "$messages" | jq '. | length')
[[ $length -eq 4 ]] || exit 1

local variables=$(
jq -n \
'{input: {message: "My transaction is stuck"}}'
)
exec_graphql 'alice' 'support-chat-message-add' "$variables"
messages="$(graphql_output '.data.supportChatMessageAdd.supportMessage')"
length=$(echo "$messages" | jq '. | length')
[[ $length -eq 6 ]] || exit 1

exec_graphql 'alice' 'support-chat-reset' "$variables"
success="$(graphql_output '.data.supportChatReset.success')"
[[ "$success" == "true" ]] || exit 1

exec_graphql 'alice' 'support-chat'
messages="$(graphql_output '.data.me.supportChat')"
length=$(echo "$messages" | jq '. | length')
[[ $length -eq 2 ]] || exit 1
}
6 changes: 4 additions & 2 deletions core/api/src/app/support/chat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Users } from "@/app"
import { RepositoryError, CouldNotFindError } from "@/domain/errors"
import { ChatAssistantNotFoundError } from "@/domain/support/errors"
import { AccountsRepository, UsersRepository } from "@/services/mongoose"
import { SupportChatRepository } from "@/services/mongoose/support-chat"
import { NotificationsService } from "@/services/notifications"
import { Assistant } from "@/services/openai"

const getMessages = async ({
Expand Down Expand Up @@ -34,7 +34,9 @@ export const initializeSupportChat = async ({

const countryCode = user.phoneMetadata?.countryCode ?? "unknown"
const level = account.level
const language = await Users.getUserLanguage(user.id)
const setting = await NotificationsService().getUserNotificationSettings(user.id)
if (setting instanceof Error) return setting
const language = setting.language ?? "en"

const supportChatId = await Assistant().initialize({
level,
Expand Down

0 comments on commit 7887a02

Please sign in to comment.