Skip to content

Commit

Permalink
test: add more tests regarding partialUpdate payloads (with and witho…
Browse files Browse the repository at this point in the history
…ut createIfNotExists, within batch or not)
  • Loading branch information
aseure committed Aug 7, 2019
1 parent 8d6b41a commit 7935b99
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions src/test/scala/algolia/dsl/PartialUpdateObjectTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package algolia.dsl

import algolia.AlgoliaDsl._
import algolia.AlgoliaTest
import algolia.definitions.BatchDefinition
import algolia.http.{HttpPayload, POST}

class PartialUpdateObjectTest extends AlgoliaTest {
Expand Down Expand Up @@ -181,10 +182,54 @@ class PartialUpdateObjectTest extends AlgoliaTest {

describe("partial update") {

it("should partial update") {
partialUpdate from "index" `object` BasicObjectWithObjectID("name1", 1, "myId")
}

it("should call API") {
(partialUpdate from "index" `object` BasicObjectWithObjectID("name1", 1, "myId"))
.build() should be(
HttpPayload(
POST,
Seq("1", "indexes", "index", "myId", "partial"),
queryParameters = None,
body = Some("""{"name":"name1","age":1,"objectID":"myId"}"""),
isSearch = false,
requestOptions = None
)
)
}

}

describe("partial update create") {

it("should partial update") {
partialUpdate from "index" `object` BasicObjectWithObjectID("name1", 1, "myId") createIfNotExists true
}

it("should call API") {
(partialUpdate from "index" `object` BasicObjectWithObjectID("name1", 1, "myId") createIfNotExists true)
.build() should be(
HttpPayload(
POST,
Seq("1", "indexes", "index", "myId", "partial"),
queryParameters = None,
body = Some("""{"name":"name1","age":1,"objectID":"myId"}"""),
isSearch = false,
requestOptions = None
)
)
}

}

describe("partial update no create") {

it("should partial update") {
partialUpdate from "index" `object` BasicObjectWithObjectID("name1", 1, "myId") createIfNotExists false
}

it("should call API") {
(partialUpdate from "index" `object` BasicObjectWithObjectID("name1", 1, "myId") createIfNotExists false)
.build() should be(
Expand Down Expand Up @@ -224,4 +269,54 @@ class PartialUpdateObjectTest extends AlgoliaTest {

}

describe("partial update objects create") {

it("should partial update") {
partialUpdate from "index" createIfNotExists true objects Seq(
BasicObjectWithObjectID("name1", 1, "myId"))
}

it("should call API") {
(partialUpdate from "index" createIfNotExists true objects Seq(
BasicObjectWithObjectID("name1", 1, "myId")))
.build() should be(
HttpPayload(
POST,
Seq("1", "indexes", "*", "batch"),
queryParameters = None,
body = Some(
"""{"requests":[{"body":{"name":"name1","age":1,"objectID":"myId"},"indexName":"index","action":"partialUpdateObject"}]}"""),
isSearch = false,
requestOptions = None
)
)
}

}

describe("partial update objects no create") {

it("should partial update") {
partialUpdate from "index" createIfNotExists false objects Seq(
BasicObjectWithObjectID("name1", 1, "myId"))
}

it("should call API") {
(partialUpdate from "index" createIfNotExists false objects Seq(
BasicObjectWithObjectID("name1", 1, "myId")))
.build() should be(
HttpPayload(
POST,
Seq("1", "indexes", "*", "batch"),
queryParameters = None,
body = Some(
"""{"requests":[{"body":{"name":"name1","age":1,"objectID":"myId"},"indexName":"index","action":"partialUpdateObjectNoCreate"}]}"""),
isSearch = false,
requestOptions = None
)
)
}

}

}

0 comments on commit 7935b99

Please sign in to comment.