Skip to content

Commit 965bd2e

Browse files
committed
added unit test to guard against broken logic
1 parent 9149401 commit 965bd2e

File tree

5 files changed

+11
-34
lines changed

5 files changed

+11
-34
lines changed

demo-app/src/main/java/co/thepeer/KEYS.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

demo-app/src/main/java/co/thepeer/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MainActivity : AppCompatActivity() {
2626
//initialize ThePeer SDK
2727
val thePeer = ThePeer.Builder(
2828
activity = this,
29-
amount = BigDecimal(10000.00),
29+
amount = BigDecimal(10000000),
3030
currency = ThePeerCurrency.NGN,
3131
userReference = getString(R.string.user_reference),
3232
resultListener = resultListener

thepeer-android/src/main/java/co/thepeer/sdk/ui/fragments/HostDialogFragment.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,15 @@ class HostDialogFragment(private val thePeerParam: ThePeerParam) :
6161

6262
activity?.let {
6363
binding.webViewPeer.addJavascriptInterface(WebInterface { results ->
64-
handleRedirect(results)
64+
redirectWithResult(results)
6565
}, "Android")
6666
}
6767

6868
binding.webViewPeer.loadUrl(transactionUrl)
6969
}
7070

71-
private fun handleRedirect(result: ThePeerResult) {
72-
val resultData = Intent()
73-
resultData.putExtra(ThePeerConstants.TRANSACTION_RESULT, result)
74-
activity?.setResult(AppCompatActivity.RESULT_OK, resultData)
75-
activity?.finish()
76-
}
71+
72+
7773
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
7874
val dialog = context?.let { BottomSheetDialog(it, R.style.CustomBottomSheetDialogTheme) }
7975
binding = FragmentHostDialogBinding.inflate(layoutInflater)
@@ -113,5 +109,4 @@ class HostDialogFragment(private val thePeerParam: ThePeerParam) :
113109
}
114110

115111

116-
117112
}

thepeer-android/src/main/java/co/thepeer/sdk/utils/WebInterface.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class WebInterface(private val redirect: (ThePeerResult) -> Unit ) {
2121
private val DIRECT_CHARGE_INSUFFICIENT_FUNDS = "direct_debit.insufficient_funds"
2222
private val DIRECT_CHARGE_USER_INSUFFICIENT_FUNDS =
2323
"direct_debit.user_insufficient_funds"
24-
private val DIRECT_DEBIT_SUCCESS = "direct_debit.success"
24+
private val DIRECT_CHARGE_SUCCESS = "direct_debit.success"
2525
private val DIRECT_CHARGE_BUSINESS_DECLINE = "direct_debit.business_decline"
2626
private val DIRECT_CHARGE_USER_DECLINE = "direct_debit.user_decline"
2727
private val CHECKOUT_INSUFFICIENT_FUNDS = "checkout.insufficient_funds"
@@ -30,7 +30,7 @@ internal class WebInterface(private val redirect: (ThePeerResult) -> Unit ) {
3030
private val CHECKOUT_BUSINESS_DECLINE = "checkout.business_decline"
3131
private val CHECKOUT_USER_DECLINE = "checkout.user_decline"
3232
private val SEND_CLOSE = "send.close"
33-
private val DIRECT_DEBIT_CLOSE = "direct_debit.close"
33+
private val DIRECT_CHARGE_CLOSE = "direct_debit.close"
3434
private val CHECKOUT_CLOSE = "checkout.close"
3535

3636

@@ -49,7 +49,7 @@ internal class WebInterface(private val redirect: (ThePeerResult) -> Unit ) {
4949
redirect(ThePeerResult.Cancelled)
5050
}
5151
else -> {
52-
redirect(ThePeerResult.Error(Throwable(event.event)))
52+
redirect(ThePeerResult.Error(Throwable(event.event.getLastPart())))
5353
}
5454
}
5555

@@ -73,10 +73,10 @@ internal class WebInterface(private val redirect: (ThePeerResult) -> Unit ) {
7373
fun handleDirectDebitEvent(event: ThePeerEvent) {
7474

7575
when (event.event) {
76-
DIRECT_DEBIT_SUCCESS -> {
76+
DIRECT_CHARGE_SUCCESS -> {
7777
redirect(ThePeerResult.Success(event.data))
7878
}
79-
DIRECT_DEBIT_CLOSE -> {
79+
DIRECT_CHARGE_CLOSE -> {
8080
redirect(ThePeerResult.Cancelled)
8181
}
8282
else -> {

thepeer-android/src/test/java/co/thepeer/sdk/WebInterfaceTest.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ class WebInterfaceTest {
5454

5555
}
5656

57-
@Test
58-
fun `handle send event - is error`() {
59-
val event = webInterface.convertToGsonFromString(MockData.sendError) as ThePeerEvent
60-
webInterface.sendResponse(MockData.sendError)
61-
verify {
62-
webInterface.handleSendEvent(event)
63-
}
64-
65-
assertEquals("send.user_insufficient_funds", event.event)
66-
67-
}
68-
6957
@Test
7058
fun `handle checkout event - success`() {
7159
val event = webInterface.convertToGsonFromString(MockData.checkoutSuccess) as ThePeerEvent
@@ -92,7 +80,8 @@ class WebInterfaceTest {
9280

9381
@Test
9482
fun `handle direct debit event - success`() {
95-
val event = webInterface.convertToGsonFromString(MockData.directDebitSuccess) as ThePeerEvent
83+
val event =
84+
webInterface.convertToGsonFromString(MockData.directDebitSuccess) as ThePeerEvent
9685
webInterface.sendResponse(MockData.directDebitSuccess)
9786
verify {
9887
webInterface.handleDirectDebitEvent(event)

0 commit comments

Comments
 (0)