Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit d857e6d

Browse files
committed
Add unit tests for transactions/summary endpoint
1 parent c6f4534 commit d857e6d

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

example/src/androidTest/java/org/wordpress/android/fluxc/mocked/MockedStack_WCInPersonPaymentsTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.wordpress.android.fluxc.mocked
22

33
import kotlinx.coroutines.runBlocking
4+
import org.hamcrest.CoreMatchers.instanceOf
45
import org.junit.Assert
56
import org.junit.Assert.assertEquals
7+
import org.junit.Assert.assertNotNull
68
import org.junit.Assert.assertNull
9+
import org.junit.Assert.assertThat
710
import org.junit.Assert.assertTrue
811
import org.junit.Test
912
import org.wordpress.android.fluxc.model.SiteModel
@@ -17,6 +20,7 @@ import org.wordpress.android.fluxc.model.payments.inperson.WCTerminalStoreLocati
1720
import org.wordpress.android.fluxc.model.payments.inperson.WCTerminalStoreLocationErrorType.MissingAddress
1821
import org.wordpress.android.fluxc.module.ResponseMockingInterceptor
1922
import org.wordpress.android.fluxc.network.rest.wpcom.wc.payments.inperson.InPersonPaymentsRestClient
23+
import org.wordpress.android.fluxc.store.WCInPersonPaymentsStore.InPersonPaymentsPluginType.STRIPE
2024
import org.wordpress.android.fluxc.store.WCInPersonPaymentsStore.InPersonPaymentsPluginType.WOOCOMMERCE_PAYMENTS
2125
import javax.inject.Inject
2226

@@ -215,4 +219,36 @@ class MockedStack_InPersonPaymentsTest : MockedStack_Base() {
215219
assertTrue(result.isError)
216220
assertTrue(result.error?.type is InvalidPostalCode)
217221
}
222+
223+
@Test
224+
fun whenFetchTransactionsSummaryDateParamShouldNotBeSent() = runBlocking {
225+
interceptor.respondWith("wc-pay-fetch-transactions-summary-response.json")
226+
227+
restClient.fetchTransactionsSummary(WOOCOMMERCE_PAYMENTS, testSite, null)
228+
229+
assertNull(interceptor.lastRequest?.url?.queryParameter("dateAfter"))
230+
}
231+
232+
@Test
233+
fun whenFetchTransactionsSummaryForSpecificTimeSlotDateParamShouldBeSent() = runBlocking {
234+
interceptor.respondWith("wc-pay-fetch-transactions-summary-response.json")
235+
236+
val dateAfterParam = "2023-01-01"
237+
restClient.fetchTransactionsSummary(WOOCOMMERCE_PAYMENTS, testSite, dateAfterParam)
238+
239+
assertTrue(interceptor.lastRequest!!.url.query!!.contains("\"date_after\":\"$dateAfterParam\""))
240+
}
241+
242+
@Test
243+
fun whenFetchTransactionsSummaryInvokedWithStripePluginShouldThrowException() = runBlocking {
244+
interceptor.respondWith("wc-pay-fetch-transactions-summary-response.json")
245+
try {
246+
restClient.fetchTransactionsSummary(STRIPE, testSite, null)
247+
} catch (e: IllegalStateException) {
248+
assertNotNull(e)
249+
assertThat(e, instanceOf(IllegalStateException::class.java))
250+
assertEquals("Stripe does not support fetching transactions summary", e.message)
251+
}
252+
Unit
253+
}
218254
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"data": {
3+
"count": 7,
4+
"currency": "usd",
5+
"total": 2231720,
6+
"fees": 58095,
7+
"net": 2173625,
8+
"store_currencies": [
9+
"usd"
10+
],
11+
"customer_currencies": [
12+
"usd"
13+
]
14+
}
15+
}

plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/payments/inperson/InPersonPaymentsRestClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class InPersonPaymentsRestClient @Inject constructor(private val wooNetwork: Woo
173173
return response.toWooPayload()
174174
}
175175

176-
internal suspend fun fetchTransactionsSummary(
176+
suspend fun fetchTransactionsSummary(
177177
activePlugin: InPersonPaymentsPluginType,
178178
site: SiteModel,
179179
dateAfter: String? = null,

0 commit comments

Comments
 (0)