NTP-55678 | Added check of user loggedin & active transaction count for batman (#15864)
This commit is contained in:
@@ -23,6 +23,7 @@ import com.navi.pay.common.usecase.RefreshLinkedAccountsUseCase
|
||||
import com.navi.pay.common.usecase.RefreshUpiNumbersUseCase
|
||||
import com.navi.pay.common.usecase.SyncUpiLiteMandateInfoUseCase
|
||||
import com.navi.pay.common.usecase.UpiRequestIdUseCase
|
||||
import com.navi.pay.tstore.list.repository.OrderRepository
|
||||
import io.mockk.mockk
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import kotlinx.coroutines.test.runTest
|
||||
@@ -43,6 +44,7 @@ class DarkKnightWorkerTest {
|
||||
private val syncUpiLiteMandateInfoUseCase: SyncUpiLiteMandateInfoUseCase = mockk(relaxed = true)
|
||||
private val upiRequestIdUseCase: UpiRequestIdUseCase = mockk(relaxed = true)
|
||||
private val commonRepository: CommonRepository = mockk(relaxed = true)
|
||||
private val orderRepository: OrderRepository = mockk(relaxed = true)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
@@ -71,6 +73,7 @@ class DarkKnightWorkerTest {
|
||||
syncUpiLiteMandateInfoUseCase = syncUpiLiteMandateInfoUseCase,
|
||||
upiRequestIdUseCase = upiRequestIdUseCase,
|
||||
commonRepository = commonRepository,
|
||||
orderRepository = orderRepository,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.navi.pay.common.usecase.LinkedAccountsUseCase
|
||||
import com.navi.pay.common.usecase.NaviPayConfigUseCase
|
||||
import com.navi.pay.common.usecase.ValidateVpaUseCase
|
||||
import com.navi.pay.common.utils.DeviceInfoImplTest
|
||||
import com.navi.pay.entry.NaviPayActivityDataProvider
|
||||
import com.navi.pay.network.testsetup.NaviPayAndroidTest
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import io.mockk.coEvery
|
||||
@@ -36,6 +37,7 @@ class UpiIdViewModelUnitTest : NaviPayAndroidTest() {
|
||||
private var naviPaySessionHelper: NaviPaySessionHelper = mockk()
|
||||
private var validateVpaUseCase: ValidateVpaUseCase = mockk()
|
||||
private var resourceProvider: ResourceProvider = mockk()
|
||||
private var naviPayActivityDataProvider: NaviPayActivityDataProvider = mockk()
|
||||
|
||||
private lateinit var upiIdInputViewModel: UPIIdInputViewModel
|
||||
|
||||
@@ -60,6 +62,7 @@ class UpiIdViewModelUnitTest : NaviPayAndroidTest() {
|
||||
naviPaySessionHelper,
|
||||
validateVpaUseCase,
|
||||
resourceProvider,
|
||||
naviPayActivityDataProvider,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -229,6 +229,14 @@ class NaviPayDarkKnightWorker {
|
||||
eventValues = mapOf("message" to message),
|
||||
)
|
||||
}
|
||||
|
||||
fun onUserNotLoggedIn() {
|
||||
NaviTrackEvent.trackEventOnClickStream(eventName = "NaviPay_DarkKnight_UserNotLoggedIn")
|
||||
}
|
||||
|
||||
fun onNoActiveTransaction() {
|
||||
NaviTrackEvent.trackEventOnClickStream(eventName = "NaviPay_DarkKnight_NoActiveTransaction")
|
||||
}
|
||||
}
|
||||
|
||||
class NaviPayAnalytics private constructor() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.content.Context
|
||||
import androidx.hilt.work.HiltWorker
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import com.navi.base.utils.BaseUtils
|
||||
import com.navi.base.utils.DateUtils
|
||||
import com.navi.base.utils.TrustedTimeAccessor
|
||||
import com.navi.base.utils.log
|
||||
@@ -29,6 +30,8 @@ import com.navi.pay.common.usecase.SyncUpiLiteMandateInfoUseCase
|
||||
import com.navi.pay.common.usecase.UpiRequestIdUseCase
|
||||
import com.navi.pay.common.utils.getMetricInfo
|
||||
import com.navi.pay.npcicl.NpciKeysResponse
|
||||
import com.navi.pay.tstore.list.model.view.OrderStatusOfView
|
||||
import com.navi.pay.tstore.list.repository.OrderRepository
|
||||
import com.navi.pay.utils.DARK_KNIGHT_WORKER
|
||||
import com.navi.pay.utils.DATE_TIME_FORMAT_DATE_MONTH_NAME_YEAR_AT_TIME
|
||||
import com.navi.pay.utils.NAVI_PAY_LITMUS_EXPERIMENTS
|
||||
@@ -57,11 +60,13 @@ constructor(
|
||||
private val syncUpiLiteMandateInfoUseCase: SyncUpiLiteMandateInfoUseCase,
|
||||
private val upiRequestIdUseCase: UpiRequestIdUseCase,
|
||||
private val commonRepository: CommonRepository,
|
||||
private val orderRepository: OrderRepository,
|
||||
) : CoroutineWorker(context, workerParams) {
|
||||
|
||||
private val screenName = DARK_KNIGHT_WORKER
|
||||
|
||||
private val naviPayAnalytics: NaviPayDarkKnightWorker = NaviPayDarkKnightWorker()
|
||||
private val activeTransactionThresholdInDays = 7
|
||||
|
||||
override suspend fun doWork(): Result =
|
||||
withContext(
|
||||
@@ -82,6 +87,24 @@ constructor(
|
||||
)
|
||||
)
|
||||
|
||||
if (!BaseUtils.isUserLoggedIn()) {
|
||||
naviPayAnalytics.onUserNotLoggedIn()
|
||||
return@withContext Result.success()
|
||||
}
|
||||
|
||||
val activeTransactionCount =
|
||||
orderRepository.getTransactionCountByStatusAndDate(
|
||||
orderStatusOfView = OrderStatusOfView.Debit,
|
||||
startDate =
|
||||
DateTime(TrustedTimeAccessor.getCurrentTimeMillis())
|
||||
.minusDays(activeTransactionThresholdInDays),
|
||||
)
|
||||
|
||||
if (activeTransactionCount == 0) {
|
||||
naviPayAnalytics.onNoActiveTransaction()
|
||||
return@withContext Result.success()
|
||||
}
|
||||
|
||||
val tasks = mutableListOf<Deferred<Any>>()
|
||||
|
||||
tasks.add(
|
||||
|
||||
@@ -17,6 +17,7 @@ import androidx.room.Upsert
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.navi.pay.tstore.list.model.view.OrderEntity
|
||||
import com.navi.pay.tstore.list.model.view.OrderHistoryEntity
|
||||
import com.navi.pay.tstore.list.model.view.OrderStatusOfView
|
||||
import com.navi.pay.utils.NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import org.joda.time.DateTime
|
||||
@@ -104,4 +105,12 @@ interface OrderDao {
|
||||
minDateTime: DateTime,
|
||||
maxDateTime: DateTime,
|
||||
): List<OrderHistoryEntity>
|
||||
|
||||
@Query(
|
||||
"SELECT COUNT(*) FROM $NAVI_PAY_DATABASE_T_STORE_ORDER_HISTORY_TABLE_NAME WHERE orderStatusOfView = :orderStatusOfView AND orderTimestamp >= :startDate"
|
||||
)
|
||||
suspend fun getTransactionCountByStatusAndDate(
|
||||
orderStatusOfView: OrderStatusOfView,
|
||||
startDate: DateTime,
|
||||
): Int
|
||||
}
|
||||
|
||||
@@ -324,6 +324,15 @@ constructor(
|
||||
return orderDao.getLatestOrderTimestamp()
|
||||
}
|
||||
|
||||
suspend fun getTransactionCountByStatusAndDate(
|
||||
orderStatusOfView: OrderStatusOfView,
|
||||
startDate: DateTime,
|
||||
) =
|
||||
orderDao.getTransactionCountByStatusAndDate(
|
||||
orderStatusOfView = orderStatusOfView,
|
||||
startDate = startDate,
|
||||
)
|
||||
|
||||
private suspend fun insertOrderEntityListDataIntoVpaTransactionInsightsDb(
|
||||
orderEntityList: List<OrderEntity>
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user