Skip to content

Commit

Permalink
Implement PayPalDataCollector hasUserLocationConsent flag forwarding.
Browse files Browse the repository at this point in the history
  • Loading branch information
sshropshire committed Apr 1, 2024
1 parent d5c4723 commit 303a88d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PayPalDataCollector internal constructor(
.disableBeacon(false)
.setMagnesEnvironment(environment)
.setAppGuid(uuidHelper.getInstallationGUID(context))
.setHasUserLocationConsent(request.hasUserLocationConsent)
magnesSDK.setUp(magnesSettingsBuilder.build())
val result = magnesSDK.collectAndSubmit(
appContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import lib.android.paypal.com.magnessdk.MagnesSettings
import lib.android.paypal.com.magnessdk.MagnesSource
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import java.util.UUID

Expand All @@ -24,6 +26,13 @@ class PayPalDataCollectorUnitTest {
private val sandboxConfig = CoreConfig("fake-client-id", Environment.SANDBOX)
private val liveConfig = CoreConfig("fake-client-id", Environment.LIVE)

private lateinit var context: Context

@Before
fun beforeEach() {
context = mockk(relaxed = true)
}

@Test
fun `when environment is SANDBOX, magnes settings environment is STAGE`() {
val appGUID = UUID.randomUUID().toString()
Expand All @@ -33,11 +42,14 @@ class PayPalDataCollectorUnitTest {

every { mockUUIDHelper.getInstallationGUID(any()) } returns appGUID
val sut = PayPalDataCollector(sandboxConfig, mockMagnesSDK, mockUUIDHelper)
sut.collectDeviceData(mockk(relaxed = true))
sut.collectDeviceData(context, PayPalDataCollectorRequest(hasUserLocationConsent = false))
verify { mockMagnesSDK.setUp(capture(magnesSettingsSlot)) }

val magnesSettings = magnesSettingsSlot.captured
assertEquals(magnesSettings.environment, lib.android.paypal.com.magnessdk.Environment.SANDBOX)
assertEquals(
magnesSettings.environment,
lib.android.paypal.com.magnessdk.Environment.SANDBOX
)
assertFalse(magnesSettings.isDisableBeacon)
assertEquals(magnesSettings.appGuid, appGUID)
assertEquals(magnesSettings.magnesSource, MagnesSource.PAYPAL.version)
Expand All @@ -53,7 +65,7 @@ class PayPalDataCollectorUnitTest {
every { mockUUIDHelper.getInstallationGUID(any()) } returns appGUID

val sut = PayPalDataCollector(liveConfig, mockMagnesSDK, mockUUIDHelper)
sut.collectDeviceData(mockk(relaxed = true))
sut.collectDeviceData(context, PayPalDataCollectorRequest(hasUserLocationConsent = false))

verify { mockMagnesSDK.setUp(capture(magnesSettingsSlot)) }

Expand All @@ -64,14 +76,15 @@ class PayPalDataCollectorUnitTest {
@Test
fun `when appGUID is invalid, InvalidInputException is thrown`() {
mockkStatic(Log::class)
val errorMessage = "Application’s Globally Unique Identifier (AppGUID) does not match the criteria," +
" This is a string that identifies the merchant application that sets up Magnes on the mobile" +
" device. If the merchant app does not pass an AppGuid, Magnes creates one to identify" +
" the app. An AppGuid is an application identifier per-installation; that is," +
" if a new instance of the app is installed on the mobile device, or the app" +
" is reinstalled, it will have a new AppGuid.\n ***AppGuid Criteria*** \n " +
"Max length: 36 characters \n Min Length: 30 characters \n " +
"Regex: Letters, numbers and dashes only \n"
val errorMessage =
"Application’s Globally Unique Identifier (AppGUID) does not match the criteria," +
" This is a string that identifies the merchant application that sets up Magnes on the mobile" +
" device. If the merchant app does not pass an AppGuid, Magnes creates one to identify" +
" the app. An AppGuid is an application identifier per-installation; that is," +
" if a new instance of the app is installed on the mobile device, or the app" +
" is reinstalled, it will have a new AppGuid.\n ***AppGuid Criteria*** \n " +
"Max length: 36 characters \n Min Length: 30 characters \n " +
"Regex: Letters, numbers and dashes only \n"
val appGUID = "invalid_uuid"
val mockMagnesSDK = mockk<MagnesSDK>(relaxed = true)
val mockUUIDHelper = mockk<UUIDHelper>(relaxed = true)
Expand All @@ -80,7 +93,10 @@ class PayPalDataCollectorUnitTest {
every { mockUUIDHelper.getInstallationGUID(any()) } returns appGUID

val sut = PayPalDataCollector(sandboxConfig, mockMagnesSDK, mockUUIDHelper)
val result = sut.collectDeviceData(mockk(relaxed = true))
val result = sut.collectDeviceData(
context,
PayPalDataCollectorRequest(hasUserLocationConsent = false)
)

verify { Log.e(any(), any(), capture(exceptionSlot)) }

Expand All @@ -103,14 +119,38 @@ class PayPalDataCollectorUnitTest {
every { mockMagnesSDK.collectAndSubmit(any(), any(), any()) } returns magnesResult

val sut = PayPalDataCollector(sandboxConfig, mockMagnesSDK, mockUUIDHelper)
val result = sut.collectDeviceData(mockContext, clientMetadataId, HashMap())
val request = PayPalDataCollectorRequest(
hasUserLocationConsent = false,
clientMetadataId = clientMetadataId
)
val result = sut.collectDeviceData(mockContext, request)
assertEquals(result, clientMetadataId)
}

@Test
fun `when setLogging is called, System is called with correct value`() {
val sut = PayPalDataCollector(mockk(relaxed = true), mockk(relaxed = true), mockk(relaxed = true))
val sut =
PayPalDataCollector(mockk(relaxed = true), mockk(relaxed = true), mockk(relaxed = true))
sut.setLogging(true)
assertEquals(System.getProperty("magnes.debug.mode"), true.toString())
}

@Test
fun `collectDeviceData forwards hasUserLocationConsent value`() {
val appGUID = UUID.randomUUID().toString()
val mockMagnesSDK = mockk<MagnesSDK>(relaxed = true)
val mockUUIDHelper = mockk<UUIDHelper>(relaxed = true)
val magnesSettingsSlot = slot<MagnesSettings>()

every { mockUUIDHelper.getInstallationGUID(any()) } returns appGUID

val sut = PayPalDataCollector(liveConfig, mockMagnesSDK, mockUUIDHelper)
val request = PayPalDataCollectorRequest(hasUserLocationConsent = true)
sut.collectDeviceData(context, request)

verify { mockMagnesSDK.setUp(capture(magnesSettingsSlot)) }

val magnesSettings = magnesSettingsSlot.captured
assertTrue(magnesSettings.hasUserLocationConsent())
}
}

0 comments on commit 303a88d

Please sign in to comment.