Skip to content

Commit

Permalink
Overload TbdexHttpClient.getExchange to accept TypeId
Browse files Browse the repository at this point in the history
  • Loading branch information
diehuxx committed Feb 14, 2024
1 parent 835f76d commit b427c5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions httpclient/src/main/kotlin/tbdex/sdk/httpclient/TbdexHttpClient.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tbdex.sdk.httpclient

import com.fasterxml.jackson.module.kotlin.convertValue
import de.fxlae.typeid.TypeId
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -100,6 +101,19 @@ object TbdexHttpClient {
}
}

/**
* Fetches a specific exchange identified by its ID from the PFI.
*
* @param pfiDid The decentralized identifier of the PFI.
* @param requesterDid The decentralized identifier of the entity requesting the exchange.
* @param exchangeId The unique identifier of the exchange to be fetched.
* @return An [Exchange] containing the requested exchange.
* @throws TbdexResponseException for request or response errors.
*/
fun getExchange(pfiDid: String, requesterDid: Did, exchangeId: TypeId): Exchange {
return this.getExchange(pfiDid, requesterDid, exchangeId.toString())
}

/**
* Fetches a specific exchange identified by its ID from the PFI.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ class TbdexHttpClientTest {
assertEquals("400", exception.errors?.get(0)?.status)
}

@Test
fun `get exchange TypeId overload success via mockwebserver`() {
val offeringId = TypeId.generate("offering")
val exchange = listOf(rfq(offeringId), quote())
val mockResponseString = Json.jsonMapper.writeValueAsString(mapOf("data" to exchange))
server.enqueue(MockResponse().setBody(mockResponseString).setResponseCode(HttpURLConnection.HTTP_OK))

val response = TbdexHttpClient.getExchange(pfiDid.uri, alice, TypeId.generate("rfq"))

assertEquals(offeringId, (response[0] as Rfq).data.offeringId)
}

@Test
fun `get exchange success via mockwebserver`() {
val offeringId = TypeId.generate("offering")
Expand Down

0 comments on commit b427c5c

Please sign in to comment.