From d90e994ed61d91463734dba4bdbdaba85b847889 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 6 Nov 2024 21:17:25 -0800 Subject: [PATCH] add back the test --- .../org/xmtp/android/example/ClientManager.kt | 2 +- .../org/xmtp/android/library/FramesTest.kt | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 library/src/androidTest/java/org/xmtp/android/library/FramesTest.kt diff --git a/example/src/main/java/org/xmtp/android/example/ClientManager.kt b/example/src/main/java/org/xmtp/android/example/ClientManager.kt index 178cfbe2a..725549d9d 100644 --- a/example/src/main/java/org/xmtp/android/example/ClientManager.kt +++ b/example/src/main/java/org/xmtp/android/example/ClientManager.kt @@ -29,7 +29,7 @@ object ClientManager { isSecure = true ), appContext = appContext, - dbEncryptionKey = encryptionKey!! + dbEncryptionKey = encryptionKey ) } diff --git a/library/src/androidTest/java/org/xmtp/android/library/FramesTest.kt b/library/src/androidTest/java/org/xmtp/android/library/FramesTest.kt new file mode 100644 index 000000000..9df314e2c --- /dev/null +++ b/library/src/androidTest/java/org/xmtp/android/library/FramesTest.kt @@ -0,0 +1,71 @@ +package org.xmtp.android.library + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import kotlinx.coroutines.runBlocking +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Test +import org.junit.runner.RunWith +import org.xmtp.android.library.frames.ConversationActionInputs +import org.xmtp.android.library.frames.DmActionInputs +import org.xmtp.android.library.frames.FrameActionInputs +import org.xmtp.android.library.frames.FramePostPayload +import org.xmtp.android.library.frames.FramesClient +import org.xmtp.android.library.frames.GetMetadataResponse +import java.net.HttpURLConnection +import java.net.URL + +@RunWith(AndroidJUnit4::class) +class FramesTest { + @Test + fun testFramesClient() { + val frameUrl = "https://fc-polls-five.vercel.app/polls/01032f47-e976-42ee-9e3d-3aac1324f4b8" + val fixtures = fixtures() + val aliceClient = fixtures.alixClient + + val framesClient = FramesClient(xmtpClient = aliceClient) + val conversationTopic = "foo" + val participantAccountAddresses = listOf("alix", "bo") + val metadata: GetMetadataResponse + runBlocking { + metadata = framesClient.proxy.readMetadata(url = frameUrl) + } + + val dmInputs = DmActionInputs( + conversationTopic = conversationTopic, + participantAccountAddresses = participantAccountAddresses + ) + val conversationInputs = ConversationActionInputs.Dm(dmInputs) + val frameInputs = FrameActionInputs( + frameUrl = frameUrl, + buttonIndex = 1, + inputText = null, + state = null, + conversationInputs = conversationInputs + ) + val signedPayload: FramePostPayload + runBlocking { + signedPayload = framesClient.signFrameAction(inputs = frameInputs) + } + val postUrl = metadata.extractedTags["fc:frame:post_url"] + assertNotNull(postUrl) + val response: GetMetadataResponse + runBlocking { + response = framesClient.proxy.post(url = postUrl!!, payload = signedPayload) + } + + assertEquals(response.extractedTags["fc:frame"], "vNext") + + val imageUrl = response.extractedTags["fc:frame:image"] + assertNotNull(imageUrl) + + val mediaUrl = framesClient.proxy.mediaUrl(url = imageUrl!!) + + val url = URL(mediaUrl) + val connection = url.openConnection() as HttpURLConnection + connection.requestMethod = "GET" + val responseCode = connection.responseCode + assertEquals(responseCode, 200) + assertEquals(connection.contentType, "image/png") + } +} \ No newline at end of file