Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbulaja98 committed Jan 30, 2023
1 parent a4809f8 commit 297eff7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,72 @@ object HttpExecutorSpec extends IntegrationSpec {
}
} @@ before(ElasticRequest.createIndex(secondSearchIndex, None).execute) @@ after(
ElasticRequest.deleteIndex(secondSearchIndex).execute.orDie
),
test("search for document using wildcard query - contains") {
checkOnce(genDocumentId, genCustomer, genDocumentId, genCustomer) {
(firstDocumentId, firstCustomer, secondDocumentId, secondCustomer) =>
val result =
for {
_ <- ElasticRequest.deleteByQuery(firstSearchIndex, matchAll()).execute
_ <-
ElasticRequest.upsert[CustomerDocument](firstSearchIndex, firstDocumentId, firstCustomer).execute
_ <-
ElasticRequest
.upsert[CustomerDocument](firstSearchIndex, secondDocumentId, secondCustomer)
.refreshTrue
.execute
query = ElasticQuery.contains("name.keyword", firstCustomer.name.take(3))
res <- ElasticRequest.search[CustomerDocument](firstSearchIndex, query).execute
} yield res

assertZIO(result)(Assertion.contains(firstCustomer))
}
} @@ before(ElasticRequest.createIndex(firstSearchIndex, None).execute) @@ after(
ElasticRequest.deleteIndex(firstSearchIndex).execute.orDie
),
test("search for document using wildcard query - starts with") {
checkOnce(genDocumentId, genCustomer, genDocumentId, genCustomer) {
(firstDocumentId, firstCustomer, secondDocumentId, secondCustomer) =>
val result =
for {
_ <- ElasticRequest.deleteByQuery(firstSearchIndex, matchAll()).execute
_ <-
ElasticRequest.upsert[CustomerDocument](firstSearchIndex, firstDocumentId, firstCustomer).execute
_ <-
ElasticRequest
.upsert[CustomerDocument](firstSearchIndex, secondDocumentId, secondCustomer)
.refreshTrue
.execute
query = ElasticQuery.startsWith("name.keyword", firstCustomer.name.take(3))
res <- ElasticRequest.search[CustomerDocument](firstSearchIndex, query).execute
} yield res

assertZIO(result)(Assertion.contains(firstCustomer))
}
} @@ before(ElasticRequest.createIndex(firstSearchIndex, None).execute) @@ after(
ElasticRequest.deleteIndex(firstSearchIndex).execute.orDie
),
test("search for document using wildcard query") {
checkOnce(genDocumentId, genCustomer, genDocumentId, genCustomer) {
(firstDocumentId, firstCustomer, secondDocumentId, secondCustomer) =>
val result =
for {
_ <- ElasticRequest.deleteByQuery(firstSearchIndex, matchAll()).execute
_ <-
ElasticRequest.upsert[CustomerDocument](firstSearchIndex, firstDocumentId, firstCustomer).execute
_ <-
ElasticRequest
.upsert[CustomerDocument](firstSearchIndex, secondDocumentId, secondCustomer)
.refreshTrue
.execute
query = wildcard("name.keyword", s"*${firstCustomer.name.take(3)}*")
res <- ElasticRequest.search[CustomerDocument](firstSearchIndex, query).execute
} yield res

assertZIO(result)(Assertion.contains(firstCustomer))
}
} @@ before(ElasticRequest.createIndex(firstSearchIndex, None).execute) @@ after(
ElasticRequest.deleteIndex(firstSearchIndex).execute.orDie
)
) @@ shrinks(0),
suite("deleting by query")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ object ElasticQuery {
caseInsensitive: Option[Boolean] = None
) extends ElasticQuery[Wildcard] { self =>
override def toJson: Json = {
val wildcardFields = Some("value" -> value.toJson) ++ boost.map("boost" -> Num(_)) ++ caseInsensitive.map(
val wildcardFields = Some("wildcard" -> value.toJson) ++ boost.map("boost" -> Num(_)) ++ caseInsensitive.map(
"case_insensitive" -> Json.Bool(_)
)
Obj("wildcard" -> Obj(field -> Obj(wildcardFields.toList: _*)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ object QueryDSLSpec extends ZIOSpecDefault {
|}
|""".stripMargin

assert(query1.toJsonBody)(equalTo(expected1.toJson))
assert(query2.toJsonBody)(equalTo(expected23.toJson))
assert(query1.toJsonBody)(equalTo(expected1.toJson)) &&
assert(query2.toJsonBody)(equalTo(expected23.toJson)) &&
assert(query3.toJsonBody)(equalTo(expected23.toJson))
},
test("properly encode case insensitive Wildcard query") {
Expand Down Expand Up @@ -642,8 +642,8 @@ object QueryDSLSpec extends ZIOSpecDefault {
|}
|""".stripMargin

assert(query1.toJsonBody)(equalTo(expected1.toJson))
assert(query2.toJsonBody)(equalTo(expected23.toJson))
assert(query1.toJsonBody)(equalTo(expected1.toJson)) &&
assert(query2.toJsonBody)(equalTo(expected23.toJson)) &&
assert(query3.toJsonBody)(equalTo(expected23.toJson))
},
test("properly encode case insensitive Wildcard query with boost") {
Expand Down Expand Up @@ -679,8 +679,8 @@ object QueryDSLSpec extends ZIOSpecDefault {
|}
|""".stripMargin

assert(query1.toJsonBody)(equalTo(expected1.toJson))
assert(query2.toJsonBody)(equalTo(expected23.toJson))
assert(query1.toJsonBody)(equalTo(expected1.toJson)) &&
assert(query2.toJsonBody)(equalTo(expected23.toJson)) &&
assert(query3.toJsonBody)(equalTo(expected23.toJson))
},
test("properly encode Bulk request body") {
Expand Down

0 comments on commit 297eff7

Please sign in to comment.