Skip to content

Commit 544bce1

Browse files
committed
Fix linting errors
1 parent 94a0d30 commit 544bce1

File tree

2 files changed

+112
-85
lines changed

2 files changed

+112
-85
lines changed

OneSignalSDK/onesignal/in-app-messages/src/test/java/com/onesignal/inAppMessages/internal/InAppMessagesTests.kt

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,35 @@ package com.onesignal.inAppMessages.internal
33
import com.onesignal.OneSignal
44
import com.onesignal.debug.LogLevel
55
import com.onesignal.debug.internal.logging.Logging
6-
import com.onesignal.inAppMessages.IInAppMessageDidDismissEvent
7-
import com.onesignal.inAppMessages.IInAppMessageDidDisplayEvent
8-
import com.onesignal.inAppMessages.IInAppMessageLifecycleListener
9-
import com.onesignal.inAppMessages.IInAppMessageWillDismissEvent
10-
import com.onesignal.inAppMessages.IInAppMessageWillDisplayEvent
116
import com.onesignal.inAppMessages.internal.InAppMessagingHelpers.Companion.buildTestMessageWithRedisplay
127
import io.kotest.core.spec.style.FunSpec
138
import io.kotest.matchers.shouldBe
149
import io.kotest.matchers.shouldNotBe
1510
import java.util.UUID
1611

17-
1812
class InAppMessagesTests : FunSpec({
19-
val IAM_CLICK_ID = "button_id_123"
20-
val LIMIT = 5
21-
val DELAY: Long = 60
22-
23-
fun setLocalTriggerValue(key: String, localValue: String) {
24-
if (localValue != null) OneSignal.InAppMessages.addTrigger(
25-
key,
26-
localValue
27-
) else OneSignal.InAppMessages.removeTrigger(key)
13+
val iamClickId = "button_id_123"
14+
val limit = 5
15+
val delay: Long = 60
16+
17+
fun setLocalTriggerValue(
18+
key: String,
19+
localValue: String,
20+
) {
21+
if (localValue != null) {
22+
OneSignal.InAppMessages.addTrigger(
23+
key,
24+
localValue,
25+
)
26+
} else {
27+
OneSignal.InAppMessages.removeTrigger(key)
28+
}
2829
}
2930

3031
fun comparativeOperatorTest(
3132
operator: Trigger.OSTriggerOperator,
3233
triggerValue: String,
33-
localValue: String
34+
localValue: String,
3435
): Boolean {
3536
// TODO
3637
// setLocalTriggerValue("test_property", localValue)
@@ -52,7 +53,7 @@ class InAppMessagesTests : FunSpec({
5253
Trigger.OSTriggerKind.SESSION_TIME,
5354
null,
5455
Trigger.OSTriggerOperator.GREATER_THAN_OR_EQUAL_TO.toString(),
55-
3
56+
3,
5657
)
5758
}
5859

@@ -87,12 +88,12 @@ class InAppMessagesTests : FunSpec({
8788

8889
test("testBuiltMessageReDisplay") {
8990
// Given
90-
val message = buildTestMessageWithRedisplay(LIMIT, DELAY)
91+
val message = buildTestMessageWithRedisplay(limit, delay)
9192

9293
// Then
9394
message.redisplayStats.isRedisplayEnabled shouldBe true
94-
message.redisplayStats.displayLimit shouldBe LIMIT
95-
message.redisplayStats.displayDelay shouldBe DELAY
95+
message.redisplayStats.displayLimit shouldBe limit
96+
message.redisplayStats.displayDelay shouldBe delay
9697
message.redisplayStats.lastDisplayTime shouldBe -1
9798
message.redisplayStats.displayQuantity shouldBe 0
9899

@@ -102,7 +103,7 @@ class InAppMessagesTests : FunSpec({
102103
Trigger.OSTriggerKind.SESSION_TIME,
103104
null,
104105
Trigger.OSTriggerOperator.GREATER_THAN_OR_EQUAL_TO.toString(),
105-
3
106+
3,
106107
)
107108

108109
// Then
@@ -116,56 +117,55 @@ class InAppMessagesTests : FunSpec({
116117
test("testBuiltMessageRedisplayLimit") {
117118
val message: InAppMessagingHelpers.OSTestInAppMessageInternal =
118119
buildTestMessageWithRedisplay(
119-
LIMIT,
120-
DELAY
120+
limit,
121+
delay,
121122
)
122-
for (i in 0 until LIMIT) {
123+
for (i in 0 until limit) {
123124
message.redisplayStats.shouldDisplayAgain() shouldBe true
124125
message.redisplayStats.incrementDisplayQuantity()
125126
}
126127
message.redisplayStats.incrementDisplayQuantity()
127128
message.redisplayStats.shouldDisplayAgain() shouldBe false
128129
}
129130

130-
131131
test("testBuiltMessageRedisplayDelay") {
132132
// TODO
133133
}
134134

135135
test("testBuiltMessageRedisplayCLickId") {
136136
val message: InAppMessagingHelpers.OSTestInAppMessageInternal =
137137
buildTestMessageWithRedisplay(
138-
LIMIT,
139-
DELAY
138+
limit,
139+
delay,
140140
)
141141

142142
message.clickedClickIds.isEmpty() shouldBe true
143-
message.isClickAvailable(IAM_CLICK_ID)
143+
message.isClickAvailable(iamClickId)
144144

145-
message.addClickId(IAM_CLICK_ID)
145+
message.addClickId(iamClickId)
146146
message.clearClickIds()
147147

148148
message.clickedClickIds.isEmpty() shouldBe true
149149

150-
message.addClickId(IAM_CLICK_ID)
151-
message.addClickId(IAM_CLICK_ID)
150+
message.addClickId(iamClickId)
151+
message.addClickId(iamClickId)
152152
message.clickedClickIds.size shouldBe 1
153153

154-
message.isClickAvailable(IAM_CLICK_ID) shouldBe false
154+
message.isClickAvailable(iamClickId) shouldBe false
155155

156156
val messageWithoutDisplay2: InAppMessagingHelpers.OSTestInAppMessageInternal =
157157
InAppMessagingHelpers.buildTestMessageWithSingleTrigger(
158158
Trigger.OSTriggerKind.SESSION_TIME,
159159
null,
160160
Trigger.OSTriggerOperator.GREATER_THAN_OR_EQUAL_TO.toString(),
161-
3
161+
3,
162162
)
163163

164-
messageWithoutDisplay2.addClickId(IAM_CLICK_ID)
165-
messageWithoutDisplay2.isClickAvailable(IAM_CLICK_ID) shouldBe false
164+
messageWithoutDisplay2.addClickId(iamClickId)
165+
messageWithoutDisplay2.isClickAvailable(iamClickId) shouldBe false
166166
}
167167

168-
test ("testBuiltMessageTrigger") {
168+
test("testBuiltMessageTrigger") {
169169
// TODO
170170
}
171171

@@ -233,15 +233,13 @@ class InAppMessagesTests : FunSpec({
233233
// }
234234
// OneSignal.InAppMessages.addClickListener(clickListener)
235235

236-
237-
//assertMainThread()
238-
//threadAndTaskWait()
236+
// assertMainThread()
237+
// threadAndTaskWait()
239238

240239
// call onMessageActionOccurredOnMessage
241240

242241
// Ensure we make REST call to OneSignal to report click.
243242

244-
245243
// Ensure we fire public callback that In-App was clicked.
246244
}
247245

@@ -257,11 +255,11 @@ class InAppMessagesTests : FunSpec({
257255
// TODO
258256
}
259257

260-
261-
/* Tests for IAM Lifecycle */
258+
// Tests for IAM Lifecycle
262259
// var iamLifecycleCounter = 0
263260

264261
test("testIAMLifecycleEventsFlow") {
262+
265263
// TODO
266264
// add listener and incremenet counter
267265
// val lifecycleListener = object : IInAppMessageLifecycleListener {

OneSignalSDK/onesignal/in-app-messages/src/test/java/com/onesignal/inAppMessages/internal/InAppMessagingHelpers.kt

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class InAppMessagingHelpers {
2525

2626
internal fun onMessageActionOccurredOnMessage(
2727
message: InAppMessage,
28-
clickResult: InAppMessageClickResult
28+
clickResult: InAppMessageClickResult,
2929
) {
3030
val mockInAppMessageManager = mockk<InAppMessagesManager>()
3131
mockInAppMessageManager.onMessageActionOccurredOnMessage(message, clickResult)
@@ -41,18 +41,26 @@ class InAppMessagingHelpers {
4141
kind: Trigger.OSTriggerKind,
4242
key: String?,
4343
operator: String?,
44-
value: Any?
44+
value: Any?,
4545
): OSTestInAppMessageInternal {
46-
val triggersJson = basicTrigger(
47-
kind, key,
48-
operator!!, value!!
49-
)
46+
val triggersJson =
47+
basicTrigger(
48+
kind,
49+
key,
50+
operator!!,
51+
value!!,
52+
)
5053
return buildTestMessageWithLiquid(triggersJson)
5154
}
5255

5356
// Most tests build a test message using only one trigger.
5457
// This convenience method makes it easy to build such a message
55-
internal fun buildTestMessageWithSingleTrigger(kind: Trigger.OSTriggerKind, key: String?, operator: String, value: Any): OSTestInAppMessageInternal {
58+
internal fun buildTestMessageWithSingleTrigger(
59+
kind: Trigger.OSTriggerKind,
60+
key: String?,
61+
operator: String,
62+
value: Any,
63+
): OSTestInAppMessageInternal {
5664
val triggersJson = basicTrigger(kind, key, operator, value)
5765
return buildTestMessage(triggersJson)
5866
}
@@ -65,17 +73,18 @@ class InAppMessagingHelpers {
6573
kind: Trigger.OSTriggerKind,
6674
key: String?,
6775
operator: String,
68-
value: Any
76+
value: Any,
6977
): JSONArray {
70-
val triggerJson: JSONObject = object : JSONObject() {
71-
init {
72-
put("id", UUID.randomUUID().toString())
73-
put("kind", kind.toString())
74-
put("property", key)
75-
put("operator", operator)
76-
put("value", value)
78+
val triggerJson: JSONObject =
79+
object : JSONObject() {
80+
init {
81+
put("id", UUID.randomUUID().toString())
82+
put("kind", kind.toString())
83+
put("property", key)
84+
put("operator", operator)
85+
put("value", value)
86+
}
7787
}
78-
}
7988

8089
return wrap(wrap(triggerJson))
8190
}
@@ -88,22 +97,28 @@ class InAppMessagingHelpers {
8897
}
8998
}
9099

91-
fun buildTestMessageWithRedisplay(limit: Int, delay: Long): OSTestInAppMessageInternal {
100+
fun buildTestMessageWithRedisplay(
101+
limit: Int,
102+
delay: Long,
103+
): OSTestInAppMessageInternal {
92104
return buildTestMessageWithMultipleDisplays(null, limit, delay)
93105
}
94106

95107
private fun buildTestMessageWithMultipleDisplays(
96108
triggerJson: JSONArray?,
97109
limit: Int,
98-
delay: Long
110+
delay: Long,
99111
): OSTestInAppMessageInternal {
100112
val json = basicIAMJSONObject(triggerJson)
101-
json.put("redisplay", object : JSONObject() {
102-
init {
103-
put("limit", limit)
104-
put("delay", delay) //in seconds
105-
}
106-
})
113+
json.put(
114+
"redisplay",
115+
object : JSONObject() {
116+
init {
117+
put("limit", limit)
118+
put("delay", delay) // in seconds
119+
}
120+
},
121+
)
107122

108123
return OSTestInAppMessageInternal(json)
109124
}
@@ -114,21 +129,30 @@ class InAppMessagingHelpers {
114129
jsonObject.put("clickIds", JSONArray(listOf("clickId1", "clickId2", "clickId3")))
115130
// shouldn't hard-code?
116131
jsonObject.put("displayedInSession", true)
117-
jsonObject.put("variants", JSONObject().apply {
118-
put("android", JSONObject().apply {
119-
put("es", TEST_SPANISH_ANDROID_VARIANT_ID)
120-
put("en", TEST_ENGLISH_ANDROID_VARIANT_ID)
121-
})
122-
})
132+
jsonObject.put(
133+
"variants",
134+
JSONObject().apply {
135+
put(
136+
"android",
137+
JSONObject().apply {
138+
put("es", TEST_SPANISH_ANDROID_VARIANT_ID)
139+
put("en", TEST_ENGLISH_ANDROID_VARIANT_ID)
140+
},
141+
)
142+
},
143+
)
123144
jsonObject.put("max_display_time", 30)
124145
if (triggerJson != null) {
125146
jsonObject.put("triggers", triggerJson)
126147
} else {
127148
jsonObject.put("triggers", JSONArray())
128149
}
129-
jsonObject.put("actions", JSONArray().apply {
130-
put(buildTestActionJson())
131-
})
150+
jsonObject.put(
151+
"actions",
152+
JSONArray().apply {
153+
put(buildTestActionJson())
154+
},
155+
)
132156

133157
return jsonObject
134158
}
@@ -143,17 +167,21 @@ class InAppMessagingHelpers {
143167
put("url_target", "webview")
144168
put("close", true)
145169
put("pageId", IAM_PAGE_ID)
146-
put("data", object : JSONObject() {
147-
init {
148-
put("test", "value")
149-
}
150-
})
170+
put(
171+
"data",
172+
object : JSONObject() {
173+
init {
174+
put("test", "value")
175+
}
176+
},
177+
)
151178
}
152179
}
153180
}
154181
}
155182

156183
// WIP
184+
157185
/** IAM Lifecycle */
158186
internal fun onMessageWillDisplay(message: InAppMessage) {
159187
val mockInAppMessageManager = mockk<InAppMessagesManager>()
@@ -178,17 +206,18 @@ class InAppMessagingHelpers {
178206
// End IAM Lifecycle
179207

180208
class OSTestInAppMessageInternal(
181-
private val jsonObject: JSONObject
209+
private val jsonObject: JSONObject,
182210
) {
183211
private val inAppMessage: InAppMessage by lazy {
184212
initializeInAppMessage()
185213
}
186214

187215
private fun initializeInAppMessage(): InAppMessage {
188-
val time = object : ITime {
189-
override val currentTimeMillis: Long
190-
get() = System.currentTimeMillis()
191-
}
216+
val time =
217+
object : ITime {
218+
override val currentTimeMillis: Long
219+
get() = System.currentTimeMillis()
220+
}
192221

193222
return InAppMessage(jsonObject, time)
194223
}

0 commit comments

Comments
 (0)