File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed
OneSignalSDK/onesignal/core/src
test/java/com/onesignal/user/internal/properties Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ open class Model(
105
105
Float ::class .java, java.lang.Float ::class .java -> data[property] = jsonObject.getDouble(property).toFloat()
106
106
Int ::class .java, java.lang.Integer ::class .java -> data[property] = jsonObject.getInt(property)
107
107
Boolean ::class .java, java.lang.Boolean ::class .java -> data[property] = jsonObject.getBoolean(property)
108
+ String ::class .java, java.lang.String ::class .java -> data[property] = jsonObject.getString(property)
108
109
else -> data[property] = jsonObject.get(property)
109
110
}
110
111
}
Original file line number Diff line number Diff line change @@ -91,7 +91,9 @@ class PropertiesModel : Model() {
91
91
override fun createModelForProperty (property : String , jsonObject : JSONObject ): Model ? {
92
92
if (property == ::tags.name) {
93
93
val model = MapModel <String >(this , ::tags.name)
94
- model.initializeFromJson(jsonObject)
94
+ for (key in jsonObject.keys()) {
95
+ model.setStringProperty(key, jsonObject.getString(key))
96
+ }
95
97
return model
96
98
}
97
99
Original file line number Diff line number Diff line change
1
+ package com.onesignal.user.internal.properties
2
+
3
+ import com.onesignal.common.putJSONObject
4
+ import io.kotest.core.spec.style.FunSpec
5
+ import io.kotest.matchers.shouldBe
6
+ import io.kotest.runner.junit4.KotestTestRunner
7
+ import org.json.JSONObject
8
+ import org.junit.runner.RunWith
9
+
10
+ @RunWith(KotestTestRunner ::class )
11
+ class PropertiesModelTests : FunSpec ({
12
+
13
+ test("successfully initializes varying tag names") {
14
+ /* Given */
15
+ val varyingTags = JSONObject ()
16
+ .putJSONObject(PropertiesModel ::tags.name) {
17
+ it.put("value", "data1")
18
+ .put("isEmpty", "data2")
19
+ .put("object", "data3")
20
+ .put("1", "data4")
21
+ .put("false", "data5")
22
+ .put("15.7", "data6")
23
+ }
24
+ val propertiesModel = PropertiesModel ()
25
+
26
+ /* When */
27
+ propertiesModel.initializeFromJson(varyingTags)
28
+ val tagsModel = propertiesModel.tags
29
+
30
+ /* Then */
31
+ tagsModel[" value" ] shouldBe " data1"
32
+ tagsModel[" isEmpty" ] shouldBe " data2"
33
+ tagsModel[" object" ] shouldBe " data3"
34
+ tagsModel[" 1" ] shouldBe " data4"
35
+ tagsModel[" false" ] shouldBe " data5"
36
+ tagsModel[" 15.7" ] shouldBe " data6"
37
+ }
38
+ })
You can’t perform that action at this time.
0 commit comments