Skip to content

Commit

Permalink
Merge pull request #152 from MyPureCloud/develop
Browse files Browse the repository at this point in the history
2.2.0 - Participant Name and Avatar release.
  • Loading branch information
AfanasievAnton authored Jan 23, 2023
2 parents 16b68cb + 01a34f0 commit 777c4a6
Show file tree
Hide file tree
Showing 37 changed files with 1,086 additions and 531 deletions.
2 changes: 1 addition & 1 deletion androidComposePrototype/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ dependencies {
// Integration with activities
implementation "androidx.activity:activity-compose:$activity_compose_version"

testImplementation 'junit:junit:4.+'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation "com.jaredrummler:android-device-names:2.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.test.uiautomator.Until

open class BasePage(val activity: Activity) {

val waitTime = 20.toLong()
val waitTime = 40.toLong()

// Initialize activity
init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import com.genesys.cloud.messenger.uitest.support.testConfig
import java.lang.Thread.sleep

class OpeningPage(activity: Activity) : BasePage(activity) {

val title = "Deployment ID"
val regionDefault = "inindca.com"
val prodRegion = ""

// Wait until android compose prototype begins
fun verifyPageIsVisible(waitTime: Long = 20) {
Expand All @@ -23,11 +26,21 @@ class OpeningPage(activity: Activity) : BasePage(activity) {
}

// Enter the deployment ID contained in the assets>testConfig.json file
fun enterDeploymentID() {
fun enterDeploymentID(deploymentId: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val deploymentIdField = mDevice.findObject(UiSelector().text(title))
deploymentIdField.click()
deploymentIdField.clearTextField()
deploymentIdField.legacySetText(testConfig.deploymentId)
deploymentIdField.legacySetText(deploymentId)
val regionField = mDevice.findObject(UiSelector().text(regionDefault))
regionField.click()
sleep(2000)
if (testConfig.domain != regionDefault) {
val prodRegionField = mDevice.findObject(UiSelector().text(testConfig.domain))
prodRegionField.click()
} else {
val dcaRegionField = mDevice.findObject(UiSelector().text(regionDefault))
dcaRegionField.click()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import java.util.concurrent.atomic.AtomicBoolean
class API : IdlingResource {

val mapper = jacksonObjectMapper()
val token = testConfig.token
val agentId = testConfig.agentId
val agentToken = testConfig.agentToken
val agentEmail = testConfig.agentEmail

fun publicApiCall(httpMethod: String, httpURL: String, payload: ByteArray? = null): JsonNode? {
val url = URL("https://api.inindca.com$httpURL")
val url = URL("${testConfig.apiBaseAddress}$httpURL")
var output: JsonNode? = null
setIdle(false)
println("Sending $httpMethod to $httpURL.")

with(url.openConnection() as HttpURLConnection) {
requestMethod = httpMethod
setRequestProperty("Authorization", "bearer $token")
setRequestProperty("Authorization", "bearer $agentToken")
setRequestProperty("User-Agent", "Android-MTSDK-Testing")
setRequestProperty("Content-Type", "application/json")

Expand All @@ -43,7 +43,7 @@ class API : IdlingResource {
}
} catch (error: FileNotFoundException) {
// FileNotFoundException can be received when a 404 is returned by an endpoint.
throw Error("An error was received while sending an HTTP Request. The target endpoint was: $error.message \n$responseCode \n$responseMessage")
throw Error("An error was received while sending an HTTP Request. The target endpoint was: ${error.message} \n$responseCode \n$responseMessage")
setIdle(false)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.genesys.cloud.messenger.uitest.support.ApiHelper

import android.util.Log
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.databind.JsonNode
import com.genesys.cloud.messenger.androidcomposeprototype.ui.testbed.TestBedViewModel
import com.genesys.cloud.messenger.uitest.support.testConfig
import org.awaitility.Awaitility
import java.lang.Thread.sleep
import java.util.concurrent.TimeUnit

private val TAG = TestBedViewModel::class.simpleName

@JsonIgnoreProperties(ignoreUnknown = true)
data class Conversation(
val id: String,
Expand Down Expand Up @@ -37,8 +41,6 @@ data class Participant(
var messages: Array<CallDetails>
)

var statusPayload = "{\"state\": \"CONNECTED\"}"

@JsonIgnoreProperties(ignoreUnknown = true)
data class CallDetails(
val state: String,
Expand Down Expand Up @@ -69,12 +71,12 @@ fun API.waitForConversation(): Conversation? {
}

fun API.getAllConversations(): Array<Conversation> {
val result = publicApiCall(httpMethod = "GET", httpURL = "/api/v2/conversations")?.get("entities")?.toList()
val result = publicApiCall("GET", "/api/v2/conversations")?.get("entities")?.toList()
return parseJsonToClass(result)
}

fun API.getConversationInfo(conversationId: String): Conversation {
val result = publicApiCall(httpMethod = "GET", httpURL = "/api/v2/conversations/$conversationId")
val result = publicApiCall("GET", "/api/v2/conversations/$conversationId")
return parseJsonToClass(result)
}

Expand All @@ -85,6 +87,13 @@ fun API.sendTypingIndicatorFromAgentToUser(conversationInfo: Conversation) {
publicApiCall("POST", "/api/v2/conversations/messages/${conversationInfo.id}/communications/${conversationInfo.getCommunicationId(participant!!)}/typing", payload = payload)
}

fun API.sendOutboundMessageFromAgentToUser(conversationInfo: Conversation, message: String) {
val agentParticipant = conversationInfo.getParticipantFromPurpose("agent")
val communicationId = conversationInfo.getCommunicationId(agentParticipant!!)
val payload = "{\"textBody\": \"${message}\"}".toByteArray()
publicApiCall("POST", "/api/v2/conversations/messages/${conversationInfo.id}/communications/$communicationId/messages", payload)
}

fun API.answerNewConversation(): Conversation? {
changePresence("On Queue", testConfig.agentUserId)
val conversation = waitForConversation()
Expand All @@ -98,15 +107,18 @@ fun API.answerNewConversation(): Conversation? {
}

fun API.sendConnectOrDisconnect(conversationInfo: Conversation, connecting: Boolean, wrapup: Boolean = true) {
var statusPayload = ""
println("Sending $connecting request to: ${conversationInfo.id} from a conversation.")
val agentParticipant = conversationInfo.getParticipantFromPurpose("agent")
var wrapupCodePayload: JsonNode? = null
if (!connecting) {
statusPayload = "{\"state\": \"DISCONNECTED\"}"
wrapupCodePayload = getDefaultWrapupCodeId(conversationInfo.id, agentParticipant!!.id!!)
wrapupCodePayload = getDefaultWrapupCodeId(conversationInfo.id, agentParticipant!!.id)
} else {
statusPayload = "{\"state\": \"CONNECTED\"}"
}
// Send requests to disconnect the conversation and send the wrapup code.
sendStatusToParticipant(conversationInfo.id, agentParticipant!!.id)
// Send requests to connect/disconnect the conversation and send the wrapup code.
sendStatusToParticipant(conversationInfo.id, agentParticipant!!.id, statusPayload)
if (connecting) {
waitForParticipantToConnect(conversationInfo.id)
} else if (wrapup) {
Expand All @@ -129,7 +141,7 @@ private fun API.waitForParticipantToConnect(conversationId: String) {
}
}

fun API.sendStatusToParticipant(conversationId: String, participantId: String) {
fun API.sendStatusToParticipant(conversationId: String, participantId: String, statusPayload: String) {
publicApiCall("PATCH", "/api/v2/conversations/messages/$conversationId/participants/$participantId", statusPayload.toByteArray())
}

Expand All @@ -142,3 +154,11 @@ fun API.sendWrapupCode(conversationInfo: Conversation, wrapupPayload: JsonNode?)
("{ \"code\": \"${wrapupPayload?.get("id")}\", \"notes\": \"\"}").toByteArray()
)
}

fun API.disconnectAllConversations() {
val conversationList = getAllConversations()
conversationList.forEach { conversation ->
Log.i(TAG, "disconnecting conversationId: ${conversation.id}")
sendConnectOrDisconnect(conversation, false, true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import com.fasterxml.jackson.module.kotlin.readValue
val testConfig by lazy { pullConfig() }

data class Config(
val token: String,
val agentId: String,
val agentToken: String,
val agentEmail: String,
val agentUserId: String,
val deploymentId: String,
val password: String
val humanizeDisableDeploymentId: String,
val botDeploymentId: String,
val botName: String,
val password: String,
val domain: String,
val apiBaseAddress: String
)

private fun pullConfig(): Config {
Expand Down
Loading

0 comments on commit 777c4a6

Please sign in to comment.