Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Fix and test that rfq is wrapped in object in CreateExchange endpoint (
Browse files Browse the repository at this point in the history
…#177)

* Fix and test that rfq is wrapped in object in CreateExchange endpoint

* Compare parsed JSON
  • Loading branch information
Diane Huxley authored Feb 21, 2024
1 parent eea984c commit a9224b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ object TbdexHttpClient {
val kind = message.metadata.kind

val pfiServiceEndpoint = getPfiServiceEndpoint(pfiDid)
val url: String = if (kind == MessageKind.rfq) {
"$pfiServiceEndpoint/exchanges/$exchangeId"

val body: RequestBody
val url: String
if (kind == MessageKind.rfq) {
body = Json.stringify(CreateExchangeRequest(message as Rfq)).toRequestBody(jsonMediaType)
url = "$pfiServiceEndpoint/exchanges/$exchangeId"
} else {
"$pfiServiceEndpoint/exchanges/$exchangeId/$kind"
body = Json.stringify(message).toRequestBody(jsonMediaType)
url = "$pfiServiceEndpoint/exchanges/$exchangeId/$kind"
}

val body: RequestBody = Json.stringify(message).toRequestBody(jsonMediaType)

val request = buildRequest(url, body)

println("Attempting to send $kind message to: ${request.url}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package tbdex.sdk.httpclient

import de.fxlae.typeid.TypeId
import junit.framework.TestCase.assertEquals
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import tbdex.sdk.httpclient.models.CreateExchangeRequest
import tbdex.sdk.httpclient.models.ErrorDetail
import tbdex.sdk.httpclient.models.TbdexResponseException
import tbdex.sdk.protocol.models.Quote
Expand Down Expand Up @@ -84,7 +87,23 @@ class TbdexHttpClientTest {
}

@Test
fun `send RFQ success via mockwebserver`() {
fun `send RFQ without replyTo success via mockwebserver`() {

server.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_ACCEPTED))

val rfq = TestData.getRfq(pfiDid.uri, TypeId.generate("offering"))
assertDoesNotThrow { TbdexHttpClient.sendMessage(rfq) }

val request1 = server.takeRequest()
assertEquals(request1.path, "/exchanges/${rfq.metadata.exchangeId}")
assertEquals(
Json.jsonMapper.readTree(request1.body.readUtf8()),
Json.jsonMapper.readTree(Json.stringify(mapOf("rfq" to rfq)))
)
}

@Test
fun `send RFQ with replyTo success via mockwebserver`() {

server.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_ACCEPTED))

Expand Down

0 comments on commit a9224b0

Please sign in to comment.