diff --git a/gradle.properties b/gradle.properties index e04106d..10772b1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/rqes-core/src/main/kotlin/eu/europa/ec/eudi/rqes/core/RQESServiceImpl.kt b/rqes-core/src/main/kotlin/eu/europa/ec/eudi/rqes/core/RQESServiceImpl.kt index 7d42ff2..9e8c4a9 100644 --- a/rqes-core/src/main/kotlin/eu/europa/ec/eudi/rqes/core/RQESServiceImpl.kt +++ b/rqes-core/src/main/kotlin/eu/europa/ec/eudi/rqes/core/RQESServiceImpl.kt @@ -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) { diff --git a/rqes-core/src/test/kotlin/eu/europa/ec/eudi/rqes/core/RQESServiceImplTest.kt b/rqes-core/src/test/kotlin/eu/europa/ec/eudi/rqes/core/RQESServiceImplTest.kt index dbff02c..9c324ea 100644 --- a/rqes-core/src/test/kotlin/eu/europa/ec/eudi/rqes/core/RQESServiceImplTest.kt +++ b/rqes-core/src/test/kotlin/eu/europa/ec/eudi/rqes/core/RQESServiceImplTest.kt @@ -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 @@ -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 { @@ -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() val mockAuthorizationCodeURL = HttpsUrl("https://example.com/auth").getOrThrow() - val authorizationRequestPrepared = mockk() { + val authorizationRequestPrepared = mockk { 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) }