Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload TbdexHttpClient.getExchange to accept TypeId #175

Merged
merged 1 commit into from
Feb 20, 2024
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
@@ -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
Loading