-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOB-183 - Fix transaction initialisation using access code. (#150)
* Fix transaction initialisation using access code. * Call notifyAll on singleton instance object in AuthActivity * Add tests for initiateTransaction * Add optional charge parameters to initialize request (#151)
- Loading branch information
1 parent
61343e5
commit 241f0e8
Showing
10 changed files
with
192 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ android.useAndroidX=true | |
org.gradle.daemon=true | ||
org.gradle.jvmargs=-Xmx2560m | ||
GROUP=co.paystack.android | ||
VERSION_NAME=3.2.0-alpha02 | ||
VERSION_NAME=3.3.0-alpha01 | ||
POM_DESCRIPTION=Android SDK for Paystack | ||
POM_URL=https://github.com/PaystackHQ/paystack-android | ||
POM_SCM_URL=https://github.com/PaystackHQ/paystack-android | ||
|
@@ -37,4 +37,4 @@ POM_LICENCE_DIST=repo | |
POM_DEVELOPER_ID=paystack | ||
POM_DEVELOPER_NAME=Paystack | ||
POM_DEVELOPER_EMAIL=[email protected] | ||
org.gradle.unsafe.configuration-cache=true | ||
org.gradle.unsafe.configuration-cache=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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package co.paystack.android.api | ||
|
||
import co.paystack.android.api.model.ChargeResponse | ||
import co.paystack.android.api.model.TransactionInitResponse | ||
import co.paystack.android.api.request.ChargeParams | ||
import co.paystack.android.api.request.TransactionInitRequestBody | ||
import co.paystack.android.api.service.PaystackApiService | ||
import co.paystack.android.model.Charge | ||
import com.nhaarman.mockitokotlin2.mock | ||
import com.nhaarman.mockitokotlin2.times | ||
import com.nhaarman.mockitokotlin2.verify | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.ArgumentMatchers.anyMap | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class PaystackRepositoryImplTest { | ||
private val apiService: PaystackApiService = mock() | ||
|
||
|
@@ -24,13 +31,51 @@ class PaystackRepositoryImplTest { | |
verify(apiService, times(1)).chargeCard(TEST_CHARGE_PARAMS.toRequestMap()) | ||
} | ||
|
||
@Test | ||
fun `initializeTransaction calls PaystackApiService with correct params`() { | ||
whenever(apiService.initializeTransaction(anyMap())) | ||
.thenReturn(FakeCall.success(TransactionInitResponse("success", "trans_id"))) | ||
val repository = PaystackRepositoryImpl(apiService) | ||
val apiCallback = mock<ApiCallback<TransactionInitResponse>>() | ||
val testMetadata = "internal_tag" to "tag_internal_example" | ||
val charge = Charge().apply { | ||
email = testEmail | ||
amount = testAmount | ||
currency = testCurrency | ||
reference = testReference | ||
subaccount = "subacc_13850248" | ||
transactionCharge = 1000 | ||
plan = "PLN_123456789" | ||
bearer = Charge.Bearer.subaccount | ||
putMetadata(testMetadata.first, testMetadata.second) | ||
} | ||
repository.initializeTransaction(testPublicKey, charge, testDeviceId, apiCallback) | ||
|
||
val expectedApiCallMap = mapOf( | ||
TransactionInitRequestBody.FIELD_KEY to testPublicKey, | ||
TransactionInitRequestBody.FIELD_EMAIL to charge.email, | ||
TransactionInitRequestBody.FIELD_AMOUNT to charge.amount, | ||
TransactionInitRequestBody.FIELD_CURRENCY to charge.currency, | ||
TransactionInitRequestBody.FIELD_METADATA to charge.metadata, | ||
TransactionInitRequestBody.FIELD_DEVICE to testDeviceId, | ||
TransactionInitRequestBody.FIELD_REFERENCE to charge.reference, | ||
TransactionInitRequestBody.FIELD_SUBACCOUNT to charge.subaccount, | ||
TransactionInitRequestBody.FIELD_TRANSACTION_CHARGE to charge.transactionCharge, | ||
TransactionInitRequestBody.FIELD_BEARER to charge.bearer.name, | ||
TransactionInitRequestBody.FIELD_PLAN to charge.plan, | ||
) | ||
|
||
verify(apiService).initializeTransaction(expectedApiCallMap) | ||
} | ||
|
||
companion object { | ||
const val testPublicKey = "pk_live_123445677555" | ||
const val testEmail = "[email protected]" | ||
const val testDeviceId = "test_device_id" | ||
const val testAmount = 10000 | ||
const val testCurrency = "NGN" | ||
const val testTransactionId = "123458685949" | ||
const val testReference = "ref_123458685949" | ||
|
||
val TEST_CHARGE_PARAMS = ChargeParams( | ||
clientData = "encryptedClientData", | ||
|