NSBolus unit tests
This commit is contained in:
parent
dbc73f22f4
commit
fb265f959e
|
@ -21,7 +21,8 @@ data class NSBolus(
|
|||
override val pumpSerial: String?,
|
||||
override var app: String? = null,
|
||||
val insulin: Double,
|
||||
val type: BolusType
|
||||
val type: BolusType,
|
||||
val isBasalInsulin: Boolean
|
||||
|
||||
) : NSTreatment {
|
||||
enum class BolusType {
|
||||
|
|
|
@ -17,10 +17,21 @@ import info.nightscout.sdk.remotemodel.RemoteTreatment
|
|||
import org.json.JSONObject
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Convert to [RemoteTreatment] and back to [NSTreatment]
|
||||
* testing purpose only
|
||||
*
|
||||
* @param treatment original
|
||||
*
|
||||
* @return treatment after double conversion
|
||||
*/
|
||||
fun NSTreatment.convertToRemoteAndBack(): NSTreatment? =
|
||||
toRemoteTreatment()?.toTreatment()
|
||||
|
||||
internal fun RemoteTreatment.toTreatment(): NSTreatment? {
|
||||
val treatmentTimestamp = timestamp()
|
||||
when {
|
||||
insulin != null && insulin > 0 ->
|
||||
insulin != null && insulin > 0 ->
|
||||
return NSBolus(
|
||||
date = treatmentTimestamp,
|
||||
device = this.device,
|
||||
|
@ -40,6 +51,7 @@ internal fun RemoteTreatment.toTreatment(): NSTreatment? {
|
|||
pumpSerial = this.pumpSerial,
|
||||
insulin = this.insulin,
|
||||
type = NSBolus.BolusType.fromString(this.type),
|
||||
isBasalInsulin = isBasalInsulin ?: false
|
||||
)
|
||||
|
||||
carbs != null && carbs > 0 ->
|
||||
|
@ -355,7 +367,8 @@ internal fun NSTreatment.toRemoteTreatment(): RemoteTreatment? =
|
|||
pumpType = pumpType,
|
||||
pumpSerial = pumpSerial,
|
||||
insulin = insulin,
|
||||
type = type.name
|
||||
type = type.name,
|
||||
isBasalInsulin = isBasalInsulin
|
||||
)
|
||||
|
||||
is NSCarbs -> RemoteTreatment(
|
||||
|
|
|
@ -76,7 +76,8 @@ internal data class RemoteTreatment(
|
|||
@SerializedName("rate") val rate: Double? = null, // Double "Temp Basal" absolute rate (could be calculated with percent and profile information...)
|
||||
@SerializedName("extendedEmulated") val extendedEmulated: RemoteTreatment? = null, // Gson of emulated EB
|
||||
@SerializedName("timeshift") val timeshift: Long? = null, // integer "Profile Switch"
|
||||
@SerializedName("percentage") val percentage: Int? = null // integer "Profile Switch"
|
||||
@SerializedName("percentage") val percentage: Int? = null, // integer "Profile Switch"
|
||||
@SerializedName("isBasalInsulin") val isBasalInsulin: Boolean? = null // boolean "Bolus"
|
||||
) {
|
||||
|
||||
fun timestamp(): Long {
|
||||
|
|
|
@ -49,7 +49,7 @@ data class Bolus(
|
|||
var insulinConfiguration: InsulinConfiguration? = null
|
||||
) : TraceableDBEntry, DBEntryWithTime {
|
||||
|
||||
private fun contentEqualsTo(other: Bolus): Boolean =
|
||||
fun contentEqualsTo(other: Bolus): Boolean =
|
||||
isValid == other.isValid &&
|
||||
timestamp == other.timestamp &&
|
||||
utcOffset == other.utcOffset &&
|
||||
|
@ -58,6 +58,16 @@ data class Bolus(
|
|||
notes == other.notes &&
|
||||
isBasalInsulin == other.isBasalInsulin
|
||||
|
||||
fun interfaceIdsEqualsTo(other: Bolus): Boolean =
|
||||
interfaceIDs.nightscoutId == interfaceIDs.nightscoutId &&
|
||||
interfaceIDs.nightscoutSystemId == interfaceIDs.nightscoutSystemId &&
|
||||
interfaceIDs.pumpType == interfaceIDs.pumpType &&
|
||||
interfaceIDs.pumpSerial == interfaceIDs.pumpSerial &&
|
||||
interfaceIDs.temporaryId == interfaceIDs.temporaryId &&
|
||||
interfaceIDs.pumpId == interfaceIDs.pumpId &&
|
||||
interfaceIDs.startId == interfaceIDs.startId &&
|
||||
interfaceIDs.endId == interfaceIDs.endId
|
||||
|
||||
fun onlyNsIdAdded(previous: Bolus): Boolean =
|
||||
previous.id != id &&
|
||||
contentEqualsTo(previous) &&
|
||||
|
|
|
@ -14,6 +14,7 @@ fun NSBolus.toBolus(): Bolus =
|
|||
amount = insulin,
|
||||
type = type.toBolusType(),
|
||||
notes = notes,
|
||||
isBasalInsulin = isBasalInsulin,
|
||||
interfaceIDs_backing = InterfaceIDs(nightscoutId = identifier, pumpId = pumpId, pumpType = InterfaceIDs.PumpType.fromString(pumpType), pumpSerial = pumpSerial, endId = endId)
|
||||
)
|
||||
|
||||
|
@ -34,6 +35,7 @@ fun Bolus.toNSBolus(): NSBolus =
|
|||
insulin = amount,
|
||||
type = type.toBolusType(),
|
||||
notes = notes,
|
||||
isBasalInsulin = isBasalInsulin,
|
||||
identifier = interfaceIDs.nightscoutId,
|
||||
pumpId = interfaceIDs.pumpId,
|
||||
pumpType = interfaceIDs.pumpType?.name,
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.database.entities.Bolus
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.NSBolus
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import org.junit.jupiter.api.Assertions
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal class BolusExtensionKtTest {
|
||||
|
||||
@Test
|
||||
fun toBolus() {
|
||||
var bolus = Bolus(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
amount = 1.0,
|
||||
type = Bolus.Type.SMB,
|
||||
notes = "aaaa",
|
||||
isBasalInsulin = false,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
|
||||
var bolus2 = (bolus.toNSBolus().convertToRemoteAndBack() as NSBolus).toBolus()
|
||||
Assertions.assertTrue(bolus.contentEqualsTo(bolus2))
|
||||
Assertions.assertTrue(bolus.interfaceIdsEqualsTo(bolus2))
|
||||
|
||||
bolus = Bolus(
|
||||
timestamp = 10000,
|
||||
isValid = false,
|
||||
amount = 1.0,
|
||||
type = Bolus.Type.NORMAL,
|
||||
notes = "aaaa",
|
||||
isBasalInsulin = true,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
|
||||
bolus2 = (bolus.toNSBolus().convertToRemoteAndBack() as NSBolus).toBolus()
|
||||
Assertions.assertTrue(bolus.contentEqualsTo(bolus2))
|
||||
Assertions.assertTrue(bolus.interfaceIdsEqualsTo(bolus2))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue