Skip to content

Commit

Permalink
fix(parser): provide ability to parse location messages with triggers…
Browse files Browse the repository at this point in the history
… generated by iOS devices (timer / beacon)

Fixes #1768
  • Loading branch information
growse committed Jul 26, 2024
1 parent a94752e commit 5ce4f80
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ open class MessageLocation(
RESPONSE("r"), // Triggered by a remote reportLocation command
CIRCULAR("c"), // Region enter / leave event
PING("p"), // Issued by the periodic ping worker
TIMER("t"), // Generated by iOS devices
BEACON("b"), // Generated by iOS beacons
DEFAULT("")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,70 @@ class ParserTest {
assertEquals("inputTestId", message.messageId)
}

@Test
fun `a location message with a timer trigger can be parsed`() {
`when`(encryptionProvider.isPayloadEncryptionEnabled).thenReturn(false)
val parser = Parser(encryptionProvider)
val input =
"""
{
"_type": "location",
"acc": 5,
"alt": 84,
"batt": 34,
"bs": 1,
"cog": 277,
"conn": "m",
"lat": -25.762245,
"lon": 126.074502,
"m": 2,
"p": 100.477,
"tid": "AA",
"t": "t",
"tst": 1721896446,
"vac": 3,
"vel": 79
}
"""
.trimIndent()
val messageBase = parser.fromJson(input)
assertEquals(MessageLocation::class.java, messageBase.javaClass)
val message = messageBase as MessageLocation
assertEquals(MessageLocation.ReportType.TIMER, message.trigger)
}

@Test
fun `a location message with a beacon trigger can be parsed`() {
`when`(encryptionProvider.isPayloadEncryptionEnabled).thenReturn(false)
val parser = Parser(encryptionProvider)
val input =
"""
{
"_type": "location",
"acc": 5,
"alt": 84,
"batt": 34,
"bs": 1,
"cog": 277,
"conn": "m",
"lat": -25.762245,
"lon": 126.074502,
"m": 2,
"p": 100.477,
"tid": "AA",
"t": "b",
"tst": 1721896446,
"vac": 3,
"vel": 79
}
"""
.trimIndent()
val messageBase = parser.fromJson(input)
assertEquals(MessageLocation::class.java, messageBase.javaClass)
val message = messageBase as MessageLocation
assertEquals(MessageLocation.ReportType.BEACON, message.trigger)
}

@Test
fun `Parser can serialize a location message`() {
`when`(encryptionProvider.isPayloadEncryptionEnabled).thenReturn(false)
Expand Down

0 comments on commit 5ce4f80

Please sign in to comment.