Skip to content

Commit 69d61e5

Browse files
committed
feat: expose 'increment from' and 'increment set' as new partial update operations
Close #592
1 parent f998616 commit 69d61e5

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

src/main/scala/algolia/definitions/PartialUpdateObjectOperationDefinition.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ case object Remove extends Operation {
5656
override def name: String = "Remove"
5757
}
5858

59+
case object IncrementFrom extends Operation {
60+
override def name: String = "IncrementFrom"
61+
}
62+
63+
case object IncrementSet extends Operation {
64+
override def name: String = "IncrementSet"
65+
}
66+
5967
case class PartialUpdateObjectOperationDefinition(
6068
operation: Operation,
6169
index: Option[String] = None,

src/main/scala/algolia/dsl/PartialUpdateObjectDsl.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ trait PartialUpdateObjectDsl {
4444
attribute = Some(attribute)
4545
)
4646

47+
def from(attribute: String): PartialUpdateObjectOperationDefinition =
48+
PartialUpdateObjectOperationDefinition(
49+
IncrementFrom,
50+
attribute = Some(attribute)
51+
)
52+
53+
def set(attribute: String): PartialUpdateObjectOperationDefinition =
54+
PartialUpdateObjectOperationDefinition(
55+
IncrementSet,
56+
attribute = Some(attribute)
57+
)
58+
4759
}
4860

4961
case object decrement {

src/test/scala/algolia/dsl/PartialUpdateObjectTest.scala

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ package algolia.dsl
2727

2828
import algolia.AlgoliaDsl._
2929
import algolia.AlgoliaTest
30-
import algolia.definitions.BatchDefinition
3130
import algolia.http.{HttpPayload, POST}
3231

3332
class PartialUpdateObjectTest extends AlgoliaTest {
@@ -38,7 +37,7 @@ class PartialUpdateObjectTest extends AlgoliaTest {
3837
increment attribute "toto" ofObjectId "myId" by 1 from "index"
3938
}
4039

41-
it("should call API") {
40+
it("should build increment attribute payload") {
4241
(increment attribute "toto" ofObjectId "myId" by 1 from "index")
4342
.build() should be(
4443
HttpPayload(
@@ -51,6 +50,40 @@ class PartialUpdateObjectTest extends AlgoliaTest {
5150
)
5251
}
5352

53+
it("should increment from") {
54+
increment from "toto" ofObjectId "myId" by 1 from "index"
55+
}
56+
57+
it("should build increment from payload") {
58+
(increment from "toto" ofObjectId "myId" by 1 from "index")
59+
.build() should be(
60+
HttpPayload(
61+
POST,
62+
Seq("1", "indexes", "index", "myId", "partial"),
63+
body = Some("""{"toto":{"_operation":"IncrementFrom","value":1}}"""),
64+
isSearch = false,
65+
requestOptions = None
66+
)
67+
)
68+
}
69+
70+
it("should increment set") {
71+
increment set "toto" ofObjectId "myId" by 1 from "index"
72+
}
73+
74+
it("should build increment set payload") {
75+
(increment set "toto" ofObjectId "myId" by 1 from "index")
76+
.build() should be(
77+
HttpPayload(
78+
POST,
79+
Seq("1", "indexes", "index", "myId", "partial"),
80+
body = Some("""{"toto":{"_operation":"IncrementSet","value":1}}"""),
81+
isSearch = false,
82+
requestOptions = None
83+
)
84+
)
85+
}
86+
5487
}
5588

5689
describe("decrement value") {

0 commit comments

Comments
 (0)