Skip to content

Commit e84adfb

Browse files
dtmeadowsstainless-app[bot]
authored andcommitted
fix(api): mark redirect_uri as optional for getAccessToken helper (#260)
* fix(api): mark redirect_uri as optional * fix(internal): fix test package * add async test
1 parent 956bb5f commit e84adfb

6 files changed

Lines changed: 158 additions & 10 deletions

File tree

finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface FinchClient {
3434
clientId: String,
3535
clientSecret: String,
3636
code: String,
37-
redirectUri: String
37+
redirectUri: String?
3838
): String
3939

4040
fun getAuthUrl(products: String, redirectUri: String, sandbox: Boolean): String
@@ -45,7 +45,7 @@ interface FinchClient {
4545
@JsonProperty("client_id") val clientId: String,
4646
@JsonProperty("client_secret") val clientSecret: String,
4747
@JsonProperty("code") val code: String,
48-
@JsonProperty("redirect_uri") val redirectUri: String,
48+
@JsonProperty("redirect_uri") val redirectUri: String?,
4949
)
5050

5151
private data class GetAccessTokenResponse(

finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsync.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface FinchClientAsync {
3535
clientId: String,
3636
clientSecret: String,
3737
code: String,
38-
redirectUri: String
38+
redirectUri: String?
3939
): CompletableFuture<String>
4040

4141
fun getAuthUrl(products: String, redirectUri: String, sandbox: Boolean): String
@@ -46,7 +46,7 @@ interface FinchClientAsync {
4646
@JsonProperty("client_id") val clientId: String,
4747
@JsonProperty("client_secret") val clientSecret: String,
4848
@JsonProperty("code") val code: String,
49-
@JsonProperty("redirect_uri") val redirectUri: String,
49+
@JsonProperty("redirect_uri") val redirectUri: String?,
5050
)
5151

5252
private data class GetAccessTokenResponse(

finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsyncImpl.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.tryfinch.api.core.http.HttpRequest
99
import com.tryfinch.api.core.http.HttpResponse.Handler
1010
import com.tryfinch.api.errors.FinchError
1111
import com.tryfinch.api.errors.FinchException
12-
import com.tryfinch.api.models.*
1312
import com.tryfinch.api.services.async.*
1413
import com.tryfinch.api.services.errorHandler
1514
import com.tryfinch.api.services.json
@@ -76,7 +75,7 @@ constructor(
7675
clientId: String,
7776
clientSecret: String,
7877
code: String,
79-
redirectUri: String
78+
redirectUri: String?
8079
): CompletableFuture<String> {
8180
if (clientOptions.clientId == null) {
8281
throw FinchException("clientId must be set in order to call getAccessToken")
@@ -137,7 +136,7 @@ constructor(
137136
@JsonProperty("client_id") val clientId: String,
138137
@JsonProperty("client_secret") val clientSecret: String,
139138
@JsonProperty("code") val code: String,
140-
@JsonProperty("redirect_uri") val redirectUri: String,
139+
@JsonProperty("redirect_uri") val redirectUri: String?,
141140
)
142141

143142
private data class GetAccessTokenResponse(

finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ constructor(
7373
clientId: String,
7474
clientSecret: String,
7575
code: String,
76-
redirectUri: String
76+
redirectUri: String?
7777
): String {
7878
if (clientOptions.clientId == null) {
7979
throw FinchException("clientId must be set in order to call getAccessToken")
@@ -134,7 +134,7 @@ constructor(
134134
@JsonProperty("client_id") val clientId: String,
135135
@JsonProperty("client_secret") val clientSecret: String,
136136
@JsonProperty("code") val code: String,
137-
@JsonProperty("redirect_uri") val redirectUri: String,
137+
@JsonProperty("redirect_uri") val redirectUri: String?,
138138
)
139139

140140
private data class GetAccessTokenResponse(
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// File generated from our OpenAPI spec by Stainless.
2+
3+
package com.tryfinch.api.client
4+
5+
import com.github.tomakehurst.wiremock.client.WireMock.*
6+
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo
7+
import com.github.tomakehurst.wiremock.junit5.WireMockTest
8+
import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync
9+
import com.tryfinch.api.models.*
10+
import org.assertj.core.api.Assertions.assertThat
11+
import org.assertj.guava.api.Assertions.assertThat
12+
import org.junit.jupiter.api.BeforeEach
13+
import org.junit.jupiter.api.Test
14+
15+
@WireMockTest
16+
class FinchClientAsyncTest {
17+
private lateinit var client: FinchClientAsync
18+
19+
@BeforeEach
20+
fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) {
21+
client =
22+
FinchOkHttpClientAsync.builder()
23+
.baseUrl(wmRuntimeInfo.getHttpBaseUrl())
24+
.accessToken("My Access Token")
25+
.clientId("My Client ID")
26+
.clientSecret("My Client Secret")
27+
.sandboxClientId("My Sandbox Client ID")
28+
.sandboxClientSecret("My Sandbox Client Secret")
29+
.webhookSecret("My Webhook Secret")
30+
.build()
31+
}
32+
33+
@Test
34+
fun getAccessTokenWithRedirectUri() {
35+
val expectedToken = "My Token"
36+
val expectedJsonResponse = "{\"accessToken\":\"My Token\"}"
37+
val expectedJsonRequest =
38+
"{\"client_id\":\"our-client-id\",\"client_secret\":\"our-client-secret\",\"code\":\"finch-auth-code\",\"redirect_uri\":\"our-redirect-uri\"}"
39+
40+
stubFor(
41+
post(urlPathEqualTo("/auth/token"))
42+
.withRequestBody(equalToJson(expectedJsonRequest))
43+
.willReturn(ok().withBody(expectedJsonResponse))
44+
)
45+
46+
assertThat(
47+
client
48+
.getAccessToken(
49+
"our-client-id",
50+
"our-client-secret",
51+
"finch-auth-code",
52+
"our-redirect-uri"
53+
)
54+
.get()
55+
)
56+
.isEqualTo(expectedToken)
57+
}
58+
59+
@Test
60+
fun getAccessTokenWithoutRedirectUri() {
61+
val expectedToken = "My Token"
62+
val expectedJsonResponse = "{\"accessToken\":\"My Token\"}"
63+
val expectedJsonRequest =
64+
"{\"client_id\":\"our-client-id\",\"client_secret\":\"our-client-secret\",\"code\":\"finch-auth-code\"}"
65+
66+
stubFor(
67+
post(urlPathEqualTo("/auth/token"))
68+
.withRequestBody(equalToJson(expectedJsonRequest))
69+
.willReturn(ok().withBody(expectedJsonResponse))
70+
)
71+
72+
assertThat(
73+
client
74+
.getAccessToken("our-client-id", "our-client-secret", "finch-auth-code", null)
75+
.get()
76+
)
77+
.isEqualTo(expectedToken)
78+
}
79+
}

finch-java-core/src/test/kotlin/com/tryfinch/api/client/FinchClientTest.kt

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,74 @@
22

33
package com.tryfinch.api.client
44

5-
class FinchClientTest {}
5+
import com.github.tomakehurst.wiremock.client.WireMock.*
6+
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo
7+
import com.github.tomakehurst.wiremock.junit5.WireMockTest
8+
import com.tryfinch.api.client.okhttp.FinchOkHttpClient
9+
import com.tryfinch.api.models.*
10+
import org.assertj.core.api.Assertions.assertThat
11+
import org.assertj.guava.api.Assertions.assertThat
12+
import org.junit.jupiter.api.BeforeEach
13+
import org.junit.jupiter.api.Test
14+
15+
@WireMockTest
16+
class FinchClientTest {
17+
private lateinit var client: FinchClient
18+
19+
@BeforeEach
20+
fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) {
21+
client =
22+
FinchOkHttpClient.builder()
23+
.baseUrl(wmRuntimeInfo.getHttpBaseUrl())
24+
.accessToken("My Access Token")
25+
.clientId("My Client ID")
26+
.clientSecret("My Client Secret")
27+
.sandboxClientId("My Sandbox Client ID")
28+
.sandboxClientSecret("My Sandbox Client Secret")
29+
.webhookSecret("My Webhook Secret")
30+
.build()
31+
}
32+
33+
@Test
34+
fun getAccessTokenWithRedirectUri() {
35+
val expectedToken = "My Token"
36+
val expectedJsonResponse = "{\"accessToken\":\"My Token\"}"
37+
val expectedJsonRequest =
38+
"{\"client_id\":\"our-client-id\",\"client_secret\":\"our-client-secret\",\"code\":\"finch-auth-code\",\"redirect_uri\":\"our-redirect-uri\"}"
39+
40+
stubFor(
41+
post(urlPathEqualTo("/auth/token"))
42+
.withRequestBody(equalToJson(expectedJsonRequest))
43+
.willReturn(ok().withBody(expectedJsonResponse))
44+
)
45+
46+
assertThat(
47+
client.getAccessToken(
48+
"our-client-id",
49+
"our-client-secret",
50+
"finch-auth-code",
51+
"our-redirect-uri"
52+
)
53+
)
54+
.isEqualTo(expectedToken)
55+
}
56+
57+
@Test
58+
fun getAccessTokenWithoutRedirectUri() {
59+
val expectedToken = "My Token"
60+
val expectedJsonResponse = "{\"accessToken\":\"My Token\"}"
61+
val expectedJsonRequest =
62+
"{\"client_id\":\"our-client-id\",\"client_secret\":\"our-client-secret\",\"code\":\"finch-auth-code\"}"
63+
64+
stubFor(
65+
post(urlPathEqualTo("/auth/token"))
66+
.withRequestBody(equalToJson(expectedJsonRequest))
67+
.willReturn(ok().withBody(expectedJsonResponse))
68+
)
69+
70+
assertThat(
71+
client.getAccessToken("our-client-id", "our-client-secret", "finch-auth-code", null)
72+
)
73+
.isEqualTo(expectedToken)
74+
}
75+
}

0 commit comments

Comments
 (0)