Skip to content

Commit f9e998b

Browse files
committed
[tests] add test for new OperationModelStore check
* Add new test file `OperationModelStoreTests` * Add test called "does not load invalid cached operations" that uncaches valid and invalid operations based on the new checks in the OperationModelStore uncaching logic.
1 parent 9306f90 commit f9e998b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.onesignal.core.internal.operations
2+
3+
import com.onesignal.core.internal.operations.impl.OperationModelStore
4+
import com.onesignal.core.internal.preferences.PreferenceOneSignalKeys
5+
import com.onesignal.core.internal.preferences.PreferenceStores
6+
import com.onesignal.debug.LogLevel
7+
import com.onesignal.debug.internal.logging.Logging
8+
import com.onesignal.mocks.MockPreferencesService
9+
import com.onesignal.user.internal.operations.LoginUserOperation
10+
import com.onesignal.user.internal.operations.SetPropertyOperation
11+
import io.kotest.core.spec.style.FunSpec
12+
import io.kotest.matchers.shouldBe
13+
import io.kotest.matchers.shouldNotBe
14+
import org.json.JSONArray
15+
import java.util.UUID
16+
17+
class OperationModelStoreTests : FunSpec({
18+
19+
beforeAny {
20+
Logging.logLevel = LogLevel.NONE
21+
}
22+
23+
test("does not load invalid cached operations") {
24+
// Given
25+
val prefs = MockPreferencesService()
26+
val operationModelStore = OperationModelStore(prefs)
27+
val jsonArray = JSONArray()
28+
29+
// Create a valid Operation with onesignalId
30+
val validOperation = SetPropertyOperation(UUID.randomUUID().toString(), UUID.randomUUID().toString(), "property", "value")
31+
validOperation.id = UUID.randomUUID().toString()
32+
33+
// Create a valid operation missing onesignalId
34+
val validOperationMissing = LoginUserOperation()
35+
validOperationMissing.id = UUID.randomUUID().toString()
36+
37+
// Create an invalid Operation missing onesignalId
38+
val invalidOperation = SetPropertyOperation()
39+
invalidOperation.id = UUID.randomUUID().toString()
40+
41+
// Add the Operations to the cache
42+
jsonArray.put(validOperation.toJSON())
43+
jsonArray.put(validOperationMissing.toJSON())
44+
jsonArray.put(invalidOperation.toJSON())
45+
prefs.saveString(PreferenceStores.ONESIGNAL, PreferenceOneSignalKeys.MODEL_STORE_PREFIX + "operations", jsonArray.toString())
46+
47+
// When
48+
operationModelStore.loadOperations()
49+
50+
// Then
51+
operationModelStore.list().count() shouldBe 2
52+
operationModelStore.get(validOperation.id) shouldNotBe null
53+
operationModelStore.get(validOperationMissing.id) shouldNotBe null
54+
operationModelStore.get(invalidOperation.id) shouldBe null
55+
}
56+
})

0 commit comments

Comments
 (0)