@@ -10,7 +10,6 @@ import androidx.work.ListenableWorker
1010import androidx.work.WorkerParameters
1111import androidx.work.workDataOf
1212import com.synonym.bitkitcore.IcJitEntry
13- import kotlinx.coroutines.flow.flowOf
1413import org.junit.After
1514import org.junit.Before
1615import org.junit.Test
@@ -33,16 +32,12 @@ import to.bitkit.CurrentActivity
3332import to.bitkit.R
3433import to.bitkit.androidServices.LightningNodeService
3534import to.bitkit.data.CacheStore
36- import to.bitkit.data.SettingsData
37- import to.bitkit.data.SettingsStore
3835import to.bitkit.domain.commands.ReceivedNotificationContent
3936import to.bitkit.ext.createChannelDetails
4037import to.bitkit.ext.mock
4138import to.bitkit.ext.notificationManager
42- import to.bitkit.models.BITCOIN_SYMBOL
4339import to.bitkit.models.BlocktankNotificationType
4440import to.bitkit.models.NotificationDetails
45- import to.bitkit.models.formatToModernDisplay
4641import to.bitkit.repositories.ActivityRepo
4742import to.bitkit.repositories.BlocktankRepo
4843import to.bitkit.repositories.LightningRepo
@@ -51,7 +46,6 @@ import to.bitkit.test.BaseUnitTest
5146import kotlin.test.assertEquals
5247import kotlin.test.assertNotNull
5348import kotlin.test.assertNull
54- import kotlin.test.assertTrue
5549
5650@Config(sdk = [34 ])
5751@RunWith(RobolectricTestRunner ::class )
@@ -61,19 +55,17 @@ class WakeNodeWorkerTest : BaseUnitTest() {
6155 private val lightningRepo = mock<LightningRepo >()
6256 private val blocktankRepo = mock<BlocktankRepo >()
6357 private val activityRepo = mock<ActivityRepo >()
64- private val settingsStore = mock<SettingsStore >()
6558 private val cacheStore = mock<CacheStore >()
6659 private val receivedNotificationContent = mock<ReceivedNotificationContent >()
6760
6861 private val channelId = " channel-1"
69- private val viaNewChannel by lazy { context.getString(R .string.notification__received__body_channel ) }
62+ private val receivedTitle by lazy { context.getString(R .string.notification__received__title ) }
7063
7164 @Before
7265 fun setUp () {
7366 whenever(workerParams.inputData).thenReturn(
7467 workDataOf(" type" to BlocktankNotificationType .cjitPaymentArrived.name),
7568 )
76- whenever(settingsStore.data).thenReturn(flowOf(SettingsData (showNotificationDetails = true )))
7769
7870 val app = context as Application
7971 Shadows .shadowOf(app).grantPermissions(Manifest .permission.POST_NOTIFICATIONS )
@@ -90,22 +82,19 @@ class WakeNodeWorkerTest : BaseUnitTest() {
9082 }
9183
9284 @Test
93- fun `cjit channel ready formats amount with thousands separators` () = test {
85+ fun `cjit channel ready delivers rich notification content with fiat` () = test {
86+ val body = $$" Received ₿ 48 064 ($30.79)"
87+ whenever(receivedNotificationContent.build(48_064L )).thenReturn(NotificationDetails (receivedTitle, body))
9488 val channel = cjitChannel(sats = 48_064 )
9589 stubChannel(channel, cjitEntry = IcJitEntry .mock())
9690 stubStartFiring(channelReadyEvent())
9791
9892 val result = worker().doWork()
9993
10094 assertEquals(ListenableWorker .Result .success(), result)
101- val notification = findNotification(viaNewChannel )
95+ val notification = findNotificationByTitle(receivedTitle )
10296 assertNotNull(notification, " CJIT notification should be delivered when app is killed" )
103- assertEquals(
104- " $BITCOIN_SYMBOL ${48_064L .formatToModernDisplay()} " ,
105- notification?.extras?.getString(Notification .EXTRA_TITLE ),
106- )
107- // sanity: a thousands separator is actually present
108- assertTrue(48_064L .formatToModernDisplay().contains(' ' ), " amount should be grouped" )
97+ assertEquals(body, notification?.extras?.getString(Notification .EXTRA_TEXT ))
10998 verify(activityRepo).insertActivityFromCjit(any(), any())
11099 }
111100
@@ -118,7 +107,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
118107 val result = worker().doWork()
119108
120109 assertEquals(ListenableWorker .Result .success(), result)
121- assertNull(findNotification(viaNewChannel ), " A non-CJIT channel must not show a 'via new channel' notification" )
110+ assertNull(findNotificationByTitle(receivedTitle ), " A non-CJIT channel must not show a payment notification" )
122111 verify(activityRepo, never()).insertActivityFromCjit(any(), any())
123112 verify(cacheStore, never()).setBackgroundReceive(any())
124113 }
@@ -133,7 +122,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
133122 val result = worker().doWork()
134123
135124 assertEquals(ListenableWorker .Result .success(), result)
136- assertNull(findNotification(viaNewChannel ), " Notification is deduped when the foreground service handles it" )
125+ assertNull(findNotificationByTitle(receivedTitle ), " Deduped when the foreground service handles it" )
137126 // Activity is still recorded so the receive is not lost
138127 verify(activityRepo).insertActivityFromCjit(any(), any())
139128 }
@@ -148,7 +137,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
148137 val result = worker().doWork()
149138
150139 assertEquals(ListenableWorker .Result .success(), result)
151- assertNull(findNotification(viaNewChannel ), " A duplicate CJIT channel ready must not notify again" )
140+ assertNull(findNotificationByTitle(receivedTitle ), " A duplicate CJIT channel ready must not notify again" )
152141 verify(cacheStore, never()).setBackgroundReceive(any())
153142 }
154143
@@ -162,7 +151,7 @@ class WakeNodeWorkerTest : BaseUnitTest() {
162151 val result = worker().doWork()
163152
164153 assertEquals(ListenableWorker .Result .success(), result)
165- assertNull(findNotification(viaNewChannel ), " Notification is deduped when the in-app UI handles it" )
154+ assertNull(findNotificationByTitle(receivedTitle ), " Notification is deduped when the in-app UI handles it" )
166155 verify(activityRepo).insertActivityFromCjit(any(), any())
167156 }
168157
@@ -211,7 +200,6 @@ class WakeNodeWorkerTest : BaseUnitTest() {
211200 lightningRepo = lightningRepo,
212201 blocktankRepo = blocktankRepo,
213202 activityRepo = activityRepo,
214- settingsStore = settingsStore,
215203 cacheStore = cacheStore,
216204 receivedNotificationContent = receivedNotificationContent,
217205 )
@@ -250,11 +238,6 @@ class WakeNodeWorkerTest : BaseUnitTest() {
250238 }
251239 }
252240
253- private fun findNotification (body : String ): Notification ? {
254- val shadows = Shadows .shadowOf(context.notificationManager)
255- return shadows.allNotifications.find { it.extras.getString(Notification .EXTRA_TEXT ) == body }
256- }
257-
258241 private fun findNotificationByTitle (title : String ): Notification ? {
259242 val shadows = Shadows .shadowOf(context.notificationManager)
260243 return shadows.allNotifications.find { it.extras.getString(Notification .EXTRA_TITLE ) == title }
0 commit comments