Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PropertiesModel's deserialization of tags to not use Model.initializeFromJson #1884

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ open class Model(
Float::class.java, java.lang.Float::class.java -> data[property] = jsonObject.getDouble(property).toFloat()
Int::class.java, java.lang.Integer::class.java -> data[property] = jsonObject.getInt(property)
Boolean::class.java, java.lang.Boolean::class.java -> data[property] = jsonObject.getBoolean(property)
String::class.java, java.lang.String::class.java -> data[property] = jsonObject.getString(property)
else -> data[property] = jsonObject.get(property)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ class PropertiesModel : Model() {
override fun createModelForProperty(property: String, jsonObject: JSONObject): Model? {
if (property == ::tags.name) {
val model = MapModel<String>(this, ::tags.name)
model.initializeFromJson(jsonObject)
for (key in jsonObject.keys()) {
model.setStringProperty(key, jsonObject.getString(key))
}
return model
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.onesignal.user.internal.properties

import com.onesignal.common.putJSONObject
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
import org.json.JSONObject
import org.junit.runner.RunWith

@RunWith(KotestTestRunner::class)
class PropertiesModelTests : FunSpec({

test("successfully initializes varying tag names") {
/* Given */
val varyingTags = JSONObject()
.putJSONObject(PropertiesModel::tags.name) {
it.put("value", "data1")
.put("isEmpty", "data2")
.put("object", "data3")
.put("1", "data4")
.put("false", "data5")
.put("15.7", "data6")
}
val propertiesModel = PropertiesModel()

/* When */
propertiesModel.initializeFromJson(varyingTags)
val tagsModel = propertiesModel.tags

/* Then */
tagsModel["value"] shouldBe "data1"
tagsModel["isEmpty"] shouldBe "data2"
tagsModel["object"] shouldBe "data3"
tagsModel["1"] shouldBe "data4"
tagsModel["false"] shouldBe "data5"
tagsModel["15.7"] shouldBe "data6"
}
})