Skip to content

Commit

Permalink
chore: added startNotification() testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
mhochsto committed Aug 14, 2024
1 parent e0c8495 commit 574d330
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
7 changes: 6 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests.all {
useJUnitPlatform()
}
}
}

repositories {
Expand Down Expand Up @@ -102,4 +107,4 @@ dependencies {

androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.bluetooth.BluetoothManager
import android.content.Context
import android.os.ParcelUuid
import android.util.Log
import com.evva.xesar.abrevva.ble.BleManager
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Promise
Expand Down Expand Up @@ -65,12 +64,13 @@ class AbrevvaBleModuleTest {
}


/* https://github.com/mockk/mockk/issues/586#issuecomment-1404973825 */
@SuppressLint("MissingPermission")
@Test
fun `startNotifications notification recieved closure should generate key correctly`() {
mockkConstructor(BleManager::class)
val callbackSlot = slot<(data: ByteArray) -> Unit>()
val keySlot = slot<String>()
val successCallback = slot<(success: Boolean) -> Unit>()
val deviceId = "e7f635ac-27ae-4bc6-a5ca-3f07872f49e9"
val service = "01a660db-5dbd-488a-bd01-b42449817c82"
val characteristic = "d0d71305-05b2-4add-9ea9-bcd1cc82211c"
Expand All @@ -81,24 +81,25 @@ class AbrevvaBleModuleTest {
"characteristic" to characteristic
)
)
mockkConstructor(BleManager::class)
mockkStatic(Log::class)
every { Log.e(any(), any()) } returns 0
every { Arguments.createMap() } returns options
every {
anyConstructed<BleManager>().startNotifications(
any(),
any(),
any(),
capture(successCallback),
capture(callbackSlot)
any(),
capture(callbackSlot),
any()
)
} returns Unit
every { anyConstructed<BleManager>().isBleEnabled() } returns false
every { contextMock.emitDeviceEvent(capture(keySlot), any()) } returns Unit
abrevvaBleModule.startNotifications(options, promiseMock)
abrevvaBleModule = AbrevvaBleModule(contextMock)

abrevvaBleModule.startNotifications(
options, promiseMock
)
callbackSlot.captured.invoke(ByteArray(0))

callbackSlot.captured(ByteArray(1))
assert(keySlot.captured == "notification|e7f635ac-27ae-4bc6-a5ca-3f07872f49e9|01a660db-5dbd-488a-bd01-b42449817c82|d0d71305-05b2-4add-9ea9-bcd1cc82211c")
}

Expand Down

0 comments on commit 574d330

Please sign in to comment.