|
1 | 1 | package com.onesignal.user.internal.properties
|
2 | 2 |
|
3 | 3 | import com.onesignal.common.putJSONObject
|
| 4 | +import com.onesignal.user.internal.identity.IdentityModel |
4 | 5 | import io.kotest.core.spec.style.FunSpec
|
5 | 6 | import io.kotest.matchers.shouldBe
|
6 | 7 | import org.json.JSONObject
|
| 8 | +import java.util.UUID |
7 | 9 |
|
8 |
| -class PropertiesModelTests : FunSpec({ |
9 |
| - |
10 |
| - test("successfully initializes varying tag names") { |
11 |
| - // Given |
12 |
| - val varyingTags = |
13 |
| - JSONObject() |
14 |
| - .putJSONObject(PropertiesModel::tags.name) { |
15 |
| - it.put("value", "data1") |
16 |
| - .put("isEmpty", "data2") |
17 |
| - .put("object", "data3") |
18 |
| - .put("1", "data4") |
19 |
| - .put("false", "data5") |
20 |
| - .put("15.7", "data6") |
21 |
| - } |
22 |
| - val propertiesModel = PropertiesModel() |
23 |
| - |
24 |
| - // When |
25 |
| - propertiesModel.initializeFromJson(varyingTags) |
26 |
| - val tagsModel = propertiesModel.tags |
27 |
| - |
28 |
| - // Then |
29 |
| - tagsModel["value"] shouldBe "data1" |
30 |
| - tagsModel["isEmpty"] shouldBe "data2" |
31 |
| - tagsModel["object"] shouldBe "data3" |
32 |
| - tagsModel["1"] shouldBe "data4" |
33 |
| - tagsModel["false"] shouldBe "data5" |
34 |
| - tagsModel["15.7"] shouldBe "data6" |
35 |
| - } |
36 |
| -}) |
| 10 | +class PropertiesModelTests : |
| 11 | + FunSpec({ |
| 12 | + |
| 13 | + test("successfully initializes varying tag names") { |
| 14 | + // Given |
| 15 | + val varyingTags = |
| 16 | + JSONObject() |
| 17 | + .putJSONObject(PropertiesModel::tags.name) { |
| 18 | + it |
| 19 | + .put("value", "data1") |
| 20 | + .put("isEmpty", "data2") |
| 21 | + .put("object", "data3") |
| 22 | + .put("1", "data4") |
| 23 | + .put("false", "data5") |
| 24 | + .put("15.7", "data6") |
| 25 | + } |
| 26 | + val propertiesModel = PropertiesModel() |
| 27 | + |
| 28 | + // When |
| 29 | + propertiesModel.initializeFromJson(varyingTags) |
| 30 | + val tagsModel = propertiesModel.tags |
| 31 | + |
| 32 | + // Then |
| 33 | + tagsModel["value"] shouldBe "data1" |
| 34 | + tagsModel["isEmpty"] shouldBe "data2" |
| 35 | + tagsModel["object"] shouldBe "data3" |
| 36 | + tagsModel["1"] shouldBe "data4" |
| 37 | + tagsModel["false"] shouldBe "data5" |
| 38 | + tagsModel["15.7"] shouldBe "data6" |
| 39 | + } |
| 40 | + |
| 41 | + test("successfully initializes varying of identities") { |
| 42 | + // Given |
| 43 | + val onesignalId = UUID.randomUUID().toString() |
| 44 | + val varyingIdentities = |
| 45 | + JSONObject() |
| 46 | + .put("onesignal_id", onesignalId) |
| 47 | + .put("external_id", "myExtId") |
| 48 | + .put("a", "test1") |
| 49 | + .put("al", "test2") |
| 50 | + .put("b", "test3") |
| 51 | + .put("value", "test4") |
| 52 | + .put("isEmpty", "test5") |
| 53 | + .put("object", "test6") |
| 54 | + .put("id", "test7") |
| 55 | + .put("os", "test8") |
| 56 | + .put("myid", "test9") |
| 57 | + .put("facebookID", "test10") |
| 58 | + val identityModel = IdentityModel() |
| 59 | + |
| 60 | + // When |
| 61 | + identityModel.initializeFromJson(varyingIdentities) |
| 62 | + |
| 63 | + // Then |
| 64 | + identityModel.onesignalId shouldBe onesignalId |
| 65 | + identityModel.externalId shouldBe "myExtId" |
| 66 | + identityModel.getValue("a") shouldBe "test1" |
| 67 | + identityModel.getValue("al") shouldBe "test2" |
| 68 | + identityModel.getValue("b") shouldBe "test3" |
| 69 | + identityModel.getValue("value") shouldBe "test4" |
| 70 | + identityModel.getValue("isEmpty") shouldBe "test5" |
| 71 | + identityModel.getValue("object") shouldBe "test6" |
| 72 | + identityModel.getValue("id") shouldBe "test7" |
| 73 | + identityModel.getValue("os") shouldBe "test8" |
| 74 | + identityModel.getValue("myid") shouldBe "test9" |
| 75 | + identityModel.getValue("facebookID") shouldBe "test10" |
| 76 | + } |
| 77 | + }) |
0 commit comments