Skip to content

Commit 58cbb87

Browse files
authored
Fix instrumented tests after the API v3 and weight-validation changes (#41)
f4c3a19 replaced OpenScaleMeasurementValue's key/typeId with the namespaced identity, but SyncServiceInstrumentedTest still built its measurements with the old constructor, so :app:compileDebugAndroidTestKotlin failed. Build the weight value with the builtin.weight identity instead. Once the suite compiles, four tests fail on a device: since 8a216f6 submit() refuses inserts and updates without a usable weight, and these tests started the service without any values. Send a value set with a weight, and expect the garbage-values case to be refused rather than dispatched.
1 parent 03c32b5 commit 58cbb87

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎src/app/src/androidTest/java/com/health/openscale/sync/core/service/SyncServiceInstrumentedTest.kt‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ class SyncServiceInstrumentedTest {
7474

7575
@Test
7676
fun insert_isDispatched() {
77-
start("mode" to "insert", "id" to 7, "userId" to 1, "date" to 1000L)
77+
start("mode" to "insert", "id" to 7, "userId" to 1, "date" to 1000L, "values" to WEIGHT_80)
7878
awaitWire { it.contains("insert#7@1000") }
7979
}
8080

8181
@Test
8282
fun update_isDispatched() {
83-
start("mode" to "update", "id" to 7, "userId" to 1, "date" to 1000L)
83+
start("mode" to "update", "id" to 7, "userId" to 1, "date" to 1000L, "values" to WEIGHT_80)
8484
awaitWire { it.contains("update#7@1000") }
8585
}
8686

@@ -132,13 +132,14 @@ class SyncServiceInstrumentedTest {
132132

133133
@Test
134134
fun insert_withGarbageValues_doesNotCrash() {
135+
// Unparseable values leave the measurement without a weight, which submit() refuses.
135136
start("mode" to "insert", "id" to 7, "userId" to 1, "date" to 1000L, "values" to "not-json")
136-
awaitWire { it.contains("insert#7@1000") } // values ignored, weight derived to 0
137+
assertNoDispatch()
137138
}
138139

139140
@Test
140141
fun insert_withMissingExtras_usesDefaults() {
141-
start("mode" to "insert") // no id/userId/date → 0/0/0
142+
start("mode" to "insert", "values" to WEIGHT_80) // no id/userId/date → 0/0/0
142143
awaitWire { it.contains("insert#0@0") }
143144
}
144145

@@ -167,7 +168,7 @@ class SyncServiceInstrumentedTest {
167168
private fun m(id: Int, timeMs: Long, weight: Float = 80f, user: Int = 1) =
168169
OpenScaleMeasurement.fromValues(
169170
id, user, Date(timeMs), "",
170-
listOf(OpenScaleMeasurementValue(0, "WEIGHT", "Weight", "kg", false, weight))
171+
listOf(OpenScaleMeasurementValue("builtin.weight", "Weight", "kg", false, weight))
171172
)
172173

173174
private fun start(vararg extras: Pair<String, Any>) {
@@ -202,6 +203,12 @@ class SyncServiceInstrumentedTest {
202203

203204
private fun snapshot(b: InstrFakeBackend): List<String> = synchronized(b.wire) { b.wire.toList() }
204205

206+
private companion object {
207+
/** A value set with a usable weight; submit() refuses inserts and updates without one.
208+
* No spaces: executeShellCommand() splits the am command line on whitespace. */
209+
const val WEIGHT_80 = """[{"identity":"builtin.weight","name":"Weight","unit":"kg","value":80.0}]"""
210+
}
211+
205212
private fun runShell(cmd: String): String {
206213
val pfd = instr.uiAutomation.executeShellCommand(cmd)
207214
return FileInputStream(pfd.fileDescriptor).use { it.readBytes().toString(Charsets.UTF_8) }

0 commit comments

Comments
 (0)