Skip to content

Commit

Permalink
fix passing serverState when authorizing service
Browse files Browse the repository at this point in the history
  • Loading branch information
vkanellopoulos committed Nov 14, 2024
1 parent 755b4ea commit 54c6c45
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ systemProp.sonar.host.url=https://sonarcloud.io
systemProp.sonar.gradle.skipCompile=true
systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml,build/reports/jacoco/testReleaseUnitTestCoverage/testReleaseUnitTestCoverage.xml
systemProp.sonar.projectName=eudi-lib-android-rqes-core
VERSION_NAME=0.0.2-SNAPSHOT
VERSION_NAME=0.0.3-SNAPSHOT

SONATYPE_HOST=S01
SONATYPE_AUTOMATIC_RELEASE=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ class RQESServiceImpl(
serverState = Uuid.random().toString()
return try {
with(getOrCreateClient()) {
val authorizationCodeURL = prepareServiceAuthorizationRequest().getOrThrow()
.also { serviceAuthRequestPrepared = it }
.value.authorizationCodeURL
val authorizationCodeURL =
prepareServiceAuthorizationRequest(walletState = serverState)
.getOrThrow()
.also { serviceAuthRequestPrepared = it }
.value.authorizationCodeURL
Result.success(authorizationCodeURL)
}
} catch (e: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.slot
import io.mockk.spyk
import io.mockk.unmockkAll
import io.mockk.verify
Expand All @@ -43,6 +44,7 @@ import kotlin.test.BeforeTest
import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertNull
import kotlin.test.assertTrue

class RQESServiceImplTest {

Expand Down Expand Up @@ -100,19 +102,22 @@ class RQESServiceImplTest {
fun `verify getServiceAuthorizationUrl initializes the serviceAuthRequestPrepared property and return the authorization url `() =
runTest {
assertNull(service.serviceAuthRequestPrepared)

val stateSlot = slot<String>()
val mockAuthorizationCodeURL = HttpsUrl("https://example.com/auth").getOrThrow()
val authorizationRequestPrepared = mockk<AuthorizationRequestPrepared>() {
val authorizationRequestPrepared = mockk<AuthorizationRequestPrepared> {
every { authorizationCodeURL } returns mockAuthorizationCodeURL
}
val serviceAuthorizationRequestPrepared =
ServiceAuthorizationRequestPrepared(authorizationRequestPrepared)
coEvery { mockClient.prepareServiceAuthorizationRequest() } returns Result.success(
coEvery { mockClient.prepareServiceAuthorizationRequest(capture(stateSlot)) } returns Result.success(
serviceAuthorizationRequestPrepared
)

val authorizationUrl = service.getServiceAuthorizationUrl().getOrThrow()

assertTrue(stateSlot.isCaptured)
assertEquals(service.serverState, stateSlot.captured)

assertEquals(serviceAuthorizationRequestPrepared, service.serviceAuthRequestPrepared)
assertEquals(mockAuthorizationCodeURL, authorizationUrl)
}
Expand Down

0 comments on commit 54c6c45

Please sign in to comment.