Skip to content

Commit 0fc12dd

Browse files
authored
Merge pull request #121 from algolia/hotfix/partial-update-object
Fix PartialUpdateObject “from” method
2 parents 0b97274 + 005378b commit 0fc12dd

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/commonMain/kotlin/com/algolia/search/model/indexing/BatchOperation.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ public sealed class BatchOperation(override val raw: String) : Raw<String> {
7676
): PartialUpdateObject {
7777
return PartialUpdateObject(
7878
objectID,
79-
Json.toJson(Partial, partial).jsonObject,
79+
json {
80+
partial.attribute.raw to partial.value
81+
KeyObjectID to objectID.raw
82+
},
8083
createIfNotExists
8184
)
8285
}

src/commonTest/kotlin/serialize/indexing/TestBatchOperation.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package serialize.indexing
22

3+
import com.algolia.search.model.Attribute
34
import com.algolia.search.model.ObjectID
45
import com.algolia.search.model.indexing.BatchOperation
56
import com.algolia.search.model.indexing.BatchOperation.*
7+
import com.algolia.search.model.indexing.Partial
68
import com.algolia.search.serialize.*
79
import kotlinx.serialization.json.json
810
import serialize.TestSerializer
11+
import shouldEqual
912
import unknown
13+
import kotlin.test.Test
1014

1115

1216
internal class TestBatchOperation : TestSerializer<BatchOperation>(BatchOperation) {
@@ -33,6 +37,18 @@ internal class TestBatchOperation : TestSerializer<BatchOperation>(BatchOperatio
3337
KeyAction to KeyPartialUpdateObjectNoCreate
3438
KeyBody to json
3539
},
40+
PartialUpdateObject.from(
41+
ObjectID(unknown),
42+
Partial.Update(
43+
Attribute("key"), "value"
44+
)
45+
) to json {
46+
KeyAction to KeyPartialUpdateObject
47+
KeyBody to json {
48+
KeyObjectID to unknown
49+
"key" to "value"
50+
}
51+
},
3652
DeleteObject(objectID) to json {
3753
KeyAction to KeyDeleteObject
3854
KeyBody to json
@@ -44,4 +60,12 @@ internal class TestBatchOperation : TestSerializer<BatchOperation>(BatchOperatio
4460
KeyBody to json
4561
}
4662
)
63+
64+
@Test
65+
fun fromPartialUpdate() {
66+
val fromPartialUpdate = PartialUpdateObject.from(ObjectID(unknown), Partial.Update(Attribute("key"), "value"))
67+
val partialUpdateObject = PartialUpdateObject(ObjectID(unknown), json { "key" to "value" })
68+
69+
Json.toJson(BatchOperation, fromPartialUpdate) shouldEqual Json.toJson(BatchOperation, partialUpdateObject)
70+
}
4771
}

0 commit comments

Comments
 (0)