Skip to content

Commit

Permalink
Moving the validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
saperi22 committed Dec 12, 2023
1 parent 4cef02a commit 5f524a7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ class ShopperInsightsClient @VisibleForTesting internal constructor(
request: ShopperInsightsRequest,
callback: ShopperInsightsCallback
) {
if (request.email == null && request.phone == null) {
callback.onResult(
ShopperInsightsResult.Failure(
IllegalArgumentException(
"One of ShopperInsightsRequest.email or " +
"ShopperInsightsRequest.phone must be non-null."
)
)
)
return
}

// TODO: - Add isAppInstalled checks for PP & Venmo. DTBTSDK-3176
paymentReadyAPI.processRequest(request)
// Hardcoded result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ package com.braintreepayments.api
* Note: **This feature is in beta. It's public API may change in future releases.**
*/
data class ShopperInsightsRequest(
val email: String?,
val phone: BuyerPhone?
) {
init {
require(email != null || phone != null) {
"Both email and phone cannot be null."
}
}
}
var email: String?,
var phone: BuyerPhone?
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.braintreepayments.api

import io.mockk.mockk
import kotlin.test.assertEquals
import kotlin.test.assertIs
import org.junit.Assert.assertNotNull
import org.junit.Before
Expand Down Expand Up @@ -38,4 +39,19 @@ class ShopperInsightsClientUnitTest {
assertNotNull(successResult.response.isVenmoRecommended)
}
}

@Test
fun `testGetRecommendedPaymentMethods - request object has null properties`() {
val request = ShopperInsightsRequest(null, null)
sut.getRecommendedPaymentMethods(request) { result ->
assertNotNull(result)
val error = assertIs<ShopperInsightsResult.Failure>(result)
val iae = assertIs<IllegalArgumentException>(error.error)
assertEquals(
"One of ShopperInsightsRequest.email or " +
"ShopperInsightsRequest.phone must be non-null.",
iae.message
)
}
}
}

0 comments on commit 5f524a7

Please sign in to comment.