-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Clear User Session feature (#93)
* exposing clear user session in dart * implementig method on fake * ready status serializer fix * exposing clear user session in android * removed moreBtn * added clear user session implementation for ios * linting * changelog * updates to 2.13.2 --------- Co-authored-by: leonardo briotto <[email protected]>
- Loading branch information
1 parent
cc52f0d
commit fe34aed
Showing
31 changed files
with
594 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
android/src/main/kotlin/com/usercentrics/sdk/flutter/bridge/ClearUserSessionBridge.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.usercentrics.sdk.flutter.bridge | ||
|
||
import com.usercentrics.sdk.flutter.api.FlutterMethodCall | ||
import com.usercentrics.sdk.flutter.api.FlutterResult | ||
import com.usercentrics.sdk.flutter.api.UsercentricsProxy | ||
import com.usercentrics.sdk.flutter.api.UsercentricsProxySingleton | ||
import com.usercentrics.sdk.flutter.serializer.serialize | ||
|
||
internal class ClearUserSessionBridge( | ||
private val usercentrics: UsercentricsProxy = UsercentricsProxySingleton | ||
) : MethodBridge { | ||
|
||
companion object { | ||
private const val clearUserSessionErrorCode = | ||
"usercentrics_flutter_clearUserSession_error" | ||
} | ||
|
||
override val name: String | ||
get() = "clearUserSession" | ||
|
||
override fun invoke(call: FlutterMethodCall, result: FlutterResult) { | ||
assert(name == call.method) | ||
usercentrics.instance.clearUserSession( | ||
onSuccess = { | ||
result.success(it.serialize()) | ||
}, | ||
onError = { | ||
result.error( | ||
clearUserSessionErrorCode, | ||
it.message, | ||
it | ||
) | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
android/src/test/java/com/usercentrics/sdk/flutter/bridge/ClearUserSessionBridgeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.usercentrics.sdk.flutter.bridge | ||
|
||
import com.usercentrics.sdk.UsercentricsReadyStatus | ||
import com.usercentrics.sdk.UsercentricsSDK | ||
import com.usercentrics.sdk.errors.UsercentricsError | ||
import com.usercentrics.sdk.flutter.api.FakeFlutterMethodCall | ||
import com.usercentrics.sdk.flutter.api.FakeFlutterResult | ||
import com.usercentrics.sdk.flutter.api.FakeUsercentricsProxy | ||
import com.usercentrics.sdk.flutter.mock.ClearUserSessionMock | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertThrows | ||
import org.junit.Test | ||
|
||
class ClearUserSessionBridgeTest { | ||
|
||
@Test | ||
fun testName() { | ||
val instance = ClearUserSessionBridge(FakeUsercentricsProxy()) | ||
assertEquals("clearUserSession", instance.name) | ||
} | ||
|
||
@Test | ||
fun testInvokeWithOtherName() { | ||
val instance = ClearUserSessionBridge(FakeUsercentricsProxy()) | ||
val call = FakeFlutterMethodCall(method = "otherName", arguments = null) | ||
|
||
assertThrows(AssertionError::class.java) { | ||
instance.invoke(call, FakeFlutterResult()) | ||
} | ||
} | ||
|
||
@Test | ||
fun testInvokeWithSuccess() { | ||
val usercentricsSDK = mockk<UsercentricsSDK>() | ||
every { usercentricsSDK.clearUserSession(any(), any()) } | ||
.answers() { | ||
(arg(0) as (UsercentricsReadyStatus) -> Unit)(ClearUserSessionMock.fake) | ||
} | ||
val usercentricsProxy = FakeUsercentricsProxy(instanceAnswer = usercentricsSDK) | ||
val instance = ClearUserSessionBridge(usercentricsProxy) | ||
val result = FakeFlutterResult() | ||
|
||
instance.invoke(ClearUserSessionMock.call, result) | ||
|
||
verify(exactly = 1) { usercentricsSDK.clearUserSession(any(), any()) } | ||
|
||
assertEquals(1, result.successCount) | ||
assertEquals(ClearUserSessionMock.expected, result.successResultArgument) | ||
} | ||
|
||
@Test | ||
fun testInvokeWithError() { | ||
val error = mockk<UsercentricsError>(relaxed = true) | ||
val errorMessage = "The error message" | ||
every { error.message }.returns(errorMessage) | ||
|
||
val usercentricsSDK = mockk<UsercentricsSDK>() | ||
every { usercentricsSDK.clearUserSession(any(), any()) } | ||
.answers() { | ||
(arg(1) as (UsercentricsError) -> Unit)(error) | ||
} | ||
|
||
val usercentricsProxy = FakeUsercentricsProxy(usercentricsSDK) | ||
val instance = ClearUserSessionBridge(usercentricsProxy) | ||
val result = FakeFlutterResult() | ||
|
||
instance.invoke(ClearUserSessionMock.call, result) | ||
|
||
verify(exactly = 1) { usercentricsSDK.clearUserSession(any(), any()) } | ||
|
||
assertEquals(1, result.errorCount) | ||
assertEquals("usercentrics_flutter_clearUserSession_error", result.errorCodeArgument) | ||
assertEquals(errorMessage, result.errorMessageArgument) | ||
assertEquals(error, result.errorDetailsArgument) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
android/src/test/java/com/usercentrics/sdk/flutter/mock/ClearUserSessionMock.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.usercentrics.sdk.flutter.mock | ||
|
||
import com.usercentrics.sdk.GeolocationRuleset | ||
import com.usercentrics.sdk.UsercentricsConsentHistoryEntry | ||
import com.usercentrics.sdk.UsercentricsReadyStatus | ||
import com.usercentrics.sdk.UsercentricsServiceConsent | ||
import com.usercentrics.sdk.flutter.api.FakeFlutterMethodCall | ||
import com.usercentrics.sdk.models.settings.UsercentricsConsentType | ||
import com.usercentrics.sdk.v2.location.data.UsercentricsLocation | ||
|
||
internal object ClearUserSessionMock { | ||
val fake = UsercentricsReadyStatus( | ||
shouldCollectConsent = true, | ||
consents = listOf( | ||
UsercentricsServiceConsent( | ||
templateId = "ocv9HNX_g", | ||
status = false, | ||
dataProcessor = "Facebook SDK", | ||
type = UsercentricsConsentType.EXPLICIT, | ||
version = "1.0.1", | ||
isEssential = true, | ||
history = listOf( | ||
UsercentricsConsentHistoryEntry( | ||
status = true, | ||
type = UsercentricsConsentType.EXPLICIT, | ||
timestampInMillis = 123, | ||
) | ||
) | ||
) | ||
), | ||
geolocationRuleset = GeolocationRuleset(activeSettingsId = "settingsId", bannerRequiredAtLocation = true), | ||
location = UsercentricsLocation(countryCode = "PT", regionCode = "PT11") | ||
) | ||
|
||
// From the debugger | ||
val call = | ||
FakeFlutterMethodCall( | ||
method = "clearUserSession", | ||
arguments = "" | ||
) | ||
val expected = mapOf( | ||
"shouldCollectConsent" to true, | ||
"consents" to listOf( | ||
mapOf( | ||
"templateId" to "ocv9HNX_g", | ||
"status" to false, | ||
"type" to "EXPLICIT", | ||
"version" to "1.0.1", | ||
"dataProcessor" to "Facebook SDK", | ||
"isEssential" to true, | ||
"history" to listOf( | ||
mapOf( | ||
"status" to true, "timestampInMillis" to 123L, "type" to "EXPLICIT", | ||
) | ||
) | ||
) | ||
), | ||
"geolocationRuleset" to mapOf("activeSettingsId" to "settingsId", "bannerRequiredAtLocation" to true), | ||
"location" to mapOf( | ||
"countryCode" to "PT", "regionCode" to "PT11", "isInEU" to true, "isInUS" to false, "isInCalifornia" to false | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.