-
Notifications
You must be signed in to change notification settings - Fork 19
feat(core): add client sync rules paramters #60
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e159172
feat(core): add client sync rules paramters
1bf362c
chore: name change
7f1e58b
Merge branch 'main' into feat/add-client-sync-rule-parameters
DominicGBauer f1d65e3
chore: rename variable to align with other sdks
DominicGBauer a2f953b
chore: add arrays, lists and maps to function
DominicGBauer d111bec
feat: add JsonParam sealed class to provide type safety
24c5f98
chore: pr reverts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
core/src/commonTest/kotlin/com/powersync/utils/JsonTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.powersync.utils | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.json.JsonArray | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.json.JsonPrimitive | ||
import kotlin.test.* | ||
|
||
class JsonTest { | ||
@Test | ||
fun testEmptyMap() { | ||
val emptyMap = emptyMap<String, Any>() | ||
val result = convertMapToJson(emptyMap) | ||
assertEquals(0, result.size) | ||
} | ||
|
||
@Test | ||
fun testNull() { | ||
val result = convertMapToJson(null) | ||
assertEquals(JsonObject(mapOf()), result) | ||
} | ||
|
||
@Test | ||
fun testIntegerMap() { | ||
val testMap = mapOf("int" to 1) | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf("int" to JsonPrimitive(1))), result) | ||
} | ||
|
||
@Test | ||
fun testStringMap() { | ||
val testMap = mapOf("string" to "string") | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf("string" to JsonPrimitive("string"))), result) | ||
} | ||
|
||
@Test | ||
fun testLongMap() { | ||
val testMap = mapOf("double" to 123L) | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf("double" to JsonPrimitive(123L))), result) | ||
} | ||
|
||
@Test | ||
fun testBooleanMap() { | ||
val testMap = mapOf("boolean" to false) | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf("boolean" to JsonPrimitive(false))), result) | ||
} | ||
|
||
@Test | ||
fun testDoubleMap() { | ||
val testMap = mapOf("double" to 0.02) | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf("double" to JsonPrimitive(0.02))), result) | ||
} | ||
|
||
@Test | ||
fun testArrayMap() { | ||
val testMap = mapOf("array" to arrayOf(1, 2, 3)) | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf("array" to JsonArray(listOf(JsonPrimitive(1), JsonPrimitive(2), JsonPrimitive(3))))), result) | ||
} | ||
|
||
@Test | ||
fun testListMap() { | ||
val testMap = mapOf("list" to listOf("a", "b", "c")) | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf("list" to JsonArray(listOf(JsonPrimitive("a"), JsonPrimitive("b"), JsonPrimitive("c"))))), result) | ||
} | ||
|
||
@Test | ||
fun testNestedMap() { | ||
val testMap = mapOf( | ||
"nested" to mapOf( | ||
"int" to 1, | ||
"string" to "value" | ||
) | ||
) | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf( | ||
"nested" to JsonObject(mapOf( | ||
"int" to JsonPrimitive(1), | ||
"string" to JsonPrimitive("value") | ||
)) | ||
)), result) | ||
} | ||
|
||
@Test | ||
fun testComplexNestedStructure() { | ||
val testMap = mapOf( | ||
"string" to "value", | ||
"int" to 42, | ||
"list" to listOf(1, "two", 3.0), | ||
"nestedMap" to mapOf( | ||
"array" to arrayOf(true, false), | ||
"nestedList" to listOf( | ||
mapOf("key" to "value"), | ||
listOf(1, 2, 3) | ||
) | ||
) | ||
) | ||
val result = convertMapToJson(testMap) | ||
|
||
val expected = JsonObject(mapOf( | ||
"string" to JsonPrimitive("value"), | ||
"int" to JsonPrimitive(42), | ||
"list" to JsonArray(listOf(JsonPrimitive(1), JsonPrimitive("two"), JsonPrimitive(3.0))), | ||
"nestedMap" to JsonObject(mapOf( | ||
"array" to JsonArray(listOf(JsonPrimitive(true), JsonPrimitive(false))), | ||
"nestedList" to JsonArray(listOf( | ||
JsonObject(mapOf("key" to JsonPrimitive("value"))), | ||
JsonArray(listOf(JsonPrimitive(1), JsonPrimitive(2), JsonPrimitive(3))) | ||
)) | ||
)) | ||
)) | ||
|
||
assertEquals(expected, result) | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Test | ||
fun testMapWithUnsupportedType() { | ||
val testMap = mapOf("unsupported" to object {}) | ||
val result = convertMapToJson(testMap) | ||
assertEquals(JsonObject(mapOf("unsupported" to JsonPrimitive(null))), result) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.