@@ -9,7 +9,12 @@ import com.posthog.generateEvent
99import org.junit.Rule
1010import org.junit.rules.TemporaryFolder
1111import java.io.File
12+ import java.io.StringWriter
13+ import java.math.BigDecimal
14+ import java.math.BigInteger
1215import java.text.ParsePosition
16+ import java.util.Date
17+ import java.util.UUID
1318import kotlin.test.AfterTest
1419import kotlin.test.Test
1520import kotlin.test.assertEquals
@@ -156,4 +161,60 @@ internal class PostHogSerializerTest {
156161 }
157162 assertEquals(16 , events.size)
158163 }
164+
165+ @Test
166+ fun `serializes different types in personProperties` () {
167+ data class CustomTestData (val field1 : String , val field2 : Int )
168+
169+ val sut = getSut()
170+ val personProperties =
171+ mapOf<String , Any ?>(
172+ " string_prop" to " test_value" ,
173+ " int_prop" to 42 ,
174+ " long_prop" to 1234567890L ,
175+ " double_prop" to 3.14159 ,
176+ " boolean_prop" to true ,
177+ " date_prop" to Date (1234567890000L ),
178+ " uuid_prop" to UUID .fromString(" 12345678-90ab-cdef-1234-567890abcdef" ),
179+ " bigint_prop" to BigInteger .valueOf(9223372036854775807L ),
180+ " bigdecimal_prop" to BigDecimal (" 123.456" ),
181+ " custom_prop" to CustomTestData (" custom" , 999 ),
182+ " null_prop" to null ,
183+ )
184+
185+ val flagsRequest =
186+ PostHogFlagsRequest (
187+ apiKey = API_KEY ,
188+ distinctId = " test_user" ,
189+ personProperties = personProperties,
190+ )
191+
192+ val serialized = StringWriter ()
193+ sut.serialize(flagsRequest, serialized)
194+ val actualJson = serialized.toString()
195+ val expectedJson =
196+ """
197+ {
198+ "${' $' } properties": {
199+ "string_prop": "test_value",
200+ "int_prop": 42,
201+ "long_prop": 1234567890,
202+ "double_prop": 3.14159,
203+ "boolean_prop": true,
204+ "date_prop": "2009-02-13T23:31:30.000Z",
205+ "uuid_prop": "12345678-90ab-cdef-1234-567890abcdef",
206+ "bigint_prop": 9223372036854775807,
207+ "bigdecimal_prop": 123.456,
208+ "custom_prop": {
209+ "field1": "custom",
210+ "field2": 999
211+ }
212+ },
213+ "api_key": "_6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI",
214+ "distinct_id": "test_user"
215+ }
216+ """ .replace(" " , " " ).replace(" \n " , " " )
217+
218+ assertEquals(expectedJson, actualJson)
219+ }
159220}
0 commit comments