Skip to content

Commit 9b7820c

Browse files
committed
properly handle no credentials being provided to tests
1 parent 8ad1263 commit 9b7820c

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/commonTest/kotlin/com.adamratzman/spotify/Common.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,29 @@ val _clientSecret = getEnvironmentVariable("SPOTIFY_CLIENT_SECRET")
66
val _redirectUri = getEnvironmentVariable("SPOTIFY_REDIRECT_URI")
77
val _tokenString = getEnvironmentVariable("SPOTIFY_TOKEN_STRING")
88

9-
val api = {
10-
println(_redirectUri)
11-
println(_clientId)
12-
println(_redirectUri.isNullOrBlank())
13-
println(_clientId.isNullOrBlank())
14-
15-
}.let { when {
16-
_redirectUri?.isNotBlank() != true -> {
17-
spotifyAppApi {
9+
val api = when {
10+
_redirectUri?.isNotBlank() == true -> {
11+
spotifyClientApi {
1812
credentials {
1913
clientId = _clientId
2014
clientSecret = _clientSecret
15+
redirectUri = _redirectUri
16+
}
17+
authorization {
18+
tokenString = _tokenString
2119
}
2220
}.build()
2321
}
2422
_clientId?.isNotBlank() == true -> {
25-
spotifyClientApi {
23+
spotifyAppApi {
2624
credentials {
2725
clientId = _clientId
2826
clientSecret = _clientSecret
29-
redirectUri = _redirectUri
30-
}
31-
authorization {
32-
tokenString = _tokenString
3327
}
3428
}.build()
3529
}
3630
else -> null
3731
}
38-
}
3932

4033
expect fun getEnvironmentVariable(name: String): String?
4134

src/commonTest/kotlin/com.adamratzman/spotify/utilities/UtilityTests.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class UtilityTests : Spek({
5959
}
6060

6161
it("Refresh on invalid token") {
62+
if (api == null) return@it
6263
val api = spotifyAppApi {
6364
credentials {
6465
clientId = getEnvironmentVariable("SPOTIFY_CLIENT_ID")
@@ -68,6 +69,7 @@ class UtilityTests : Spek({
6869
}
6970

7071
it("Automatic refresh") {
72+
if (api == null) return@it
7173
val api = spotifyAppApi {
7274
credentials {
7375
clientId = getEnvironmentVariable("SPOTIFY_CLIENT_ID")

0 commit comments

Comments
 (0)