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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AppFunctionInstrumentationTest {
.getAppFunctionData(ExecuteAppFunctionResponse.Success.PROPERTY_RETURN_VALUE)
?.getString("message"),
)
.isEqualTo("Message sent to recipient: Alice Smith.")
.isEqualTo("Message sent to: Alice Smith.")
// Verify that the message was actually saved in the repository
val messages = messageRepository.getMessages(testRecipient.id).first()
assertThat(messages).isNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,12 @@ class AppFunctionsTest {
appFunctions.makeCall(testContext, endpointValue = "nonexistent_id")
}
}

@Test(expected = AppFunctionInvalidArgumentException::class)
fun makeCall_duplicateContactName_fails() {
runBlocking {
// "Bob Johnson" has two entries (ID 2 and ID 7)
appFunctions.makeCall(testContext, contactName = "Bob Johnson")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class CallManager
?: recipientsRepository.getGroupById(recipientId)?.let {
Recipient(it.id, it.name, "")
}
?: recipientsRepository.getRecipientByName(recipientId)
?: recipientsRepository.getRecipientByName(recipientId).let { list ->
if (list.size == 1) list.first() else null
}
?: Recipient(recipientId, recipientId, "")
startCall(recipient)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RecipientsRepository
Recipient(id = "4", name = "David Wilson", email = "david@example.com"),
Recipient(id = "5", name = "Eve Davis", email = "eve@example.com"),
Recipient(id = "6", name = "Frank Miller", email = "frank@example.com"),
Recipient(id = "7", name = "Bob Johnson", email = "bob2@example.com"),
Comment thread
corinac123 marked this conversation as resolved.
)

private val groups =
Expand Down Expand Up @@ -159,7 +160,7 @@ class RecipientsRepository

fun getRecipientById(id: String): Recipient? = recipients.singleOrNull { it.id == id }

fun getRecipientByName(name: String): Recipient? = recipients.singleOrNull { it.name == name }
fun getRecipientByName(name: String): List<Recipient> = recipients.filter { it.name == name }

fun getGroupById(id: String): ChatGroup? = groups.singleOrNull { it.id == id }
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class ChatViewModel
?: recipientsRepository.getGroupById(recipientId)?.let {
Recipient(it.id, it.name, "")
}
?: recipientsRepository.getRecipientByName(recipientId)
?: recipientsRepository.getRecipientByName(recipientId).let { list ->
if (list.size == 1) list.first() else null
}
?: if (recipientId == "bot") {
Recipient("bot", "Assistant", "bot@example.com")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,18 @@ class AppFunctions
val recipient =
with(recipientsRepository) {
if (endpointValue == null) {
getRecipientByName(checkNotNull(contactName))
?: throw AppFunctionElementNotFoundException(
val matches = getRecipientByName(checkNotNull(contactName))
if (matches.isEmpty()) {
throw AppFunctionElementNotFoundException(
"No recipient exists for contactName: $contactName",
)
}
if (matches.size > 1) {
throw AppFunctionInvalidArgumentException(
"Multiple contacts found with name $contactName. Please be more specific.",
)
}
matches.first()
} else {
getRecipientById(endpointValue)
?: throw AppFunctionElementNotFoundException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class CallManager
?: recipientsRepository.getGroupById(recipientId)?.let {
Recipient(it.id, it.name, "")
}
?: recipientsRepository.getRecipientByName(recipientId)
?: recipientsRepository.getRecipientByName(recipientId).let { list ->
if (list.size == 1) list.first() else null
}
?: Recipient(recipientId, recipientId, "")
startCall(recipient)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RecipientsRepository
Recipient(id = "4", name = "David Wilson", email = "david@example.com"),
Recipient(id = "5", name = "Eve Davis", email = "eve@example.com"),
Recipient(id = "6", name = "Frank Miller", email = "frank@example.com"),
Recipient(id = "7", name = "Bob Johnson", email = "bob2@example.com"),
Comment thread
corinac123 marked this conversation as resolved.
)

private val groups =
Expand Down Expand Up @@ -159,7 +160,7 @@ class RecipientsRepository

fun getRecipientById(id: String): Recipient? = recipients.singleOrNull { it.id == id }

fun getRecipientByName(name: String): Recipient? = recipients.singleOrNull { it.name == name }
fun getRecipientByName(name: String): List<Recipient> = recipients.filter { it.name == name }

fun getGroupById(id: String): ChatGroup? = groups.singleOrNull { it.id == id }
}