Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drmarjanovic committed Apr 27, 2023
1 parent 232bcbc commit 8319008
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ trait IntegrationSpec extends ZIOSpecDefault {
subDocumentList <- Gen.listOfBounded(1, 3)(genTestSubDocument)
intField <- Gen.int(1, 2000)
doubleField <- Gen.double(100, 2000)
booleanField <- Gen.boolean
} yield TestDocument(
stringField = stringField,
dateField = dateField,
subDocumentList = subDocumentList,
intField = intField,
doubleField = doubleField
doubleField = doubleField,
booleanField = booleanField
)

def genTestSubDocument: Gen[Any, TestSubDocument] = for {
Expand Down
241 changes: 160 additions & 81 deletions modules/library/src/test/scala/zio/elasticsearch/QueryDSLSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ object QueryDSLSpec extends ZIOSpecDefault {
must = List(Terms(field = "stringField", values = List("a", "b", "c"), boost = None)),
mustNot = List(
Match(field = "doubleField", value = 3.14, boost = None),
Match(field = "testField", value = "test", boost = None),
Match(field = "testField", value = true, boost = None),
Exists("anotherTestField")
),
should = Nil,
Expand All @@ -261,7 +261,7 @@ object QueryDSLSpec extends ZIOSpecDefault {
mustNot = List(Match(field = "intField", value = 50, boost = None)),
should = List(
Range(field = "intField", lower = GreaterThan(1), upper = LessThanOrEqualTo(100), boost = None),
Match(field = "testField", value = "test", boost = None)
Match(field = "stringField", value = "test", boost = None)
),
boost = None,
minimumShouldMatch = None
Expand All @@ -287,7 +287,7 @@ object QueryDSLSpec extends ZIOSpecDefault {
must = List(Terms(field = "stringField", values = List("a", "b", "c"), boost = None)),
mustNot = List(
Match(field = "doubleField", value = 3.14, boost = None),
Match(field = "testField", value = "test", boost = None),
Match(field = "testField", value = true, boost = None),
Exists("anotherTestField")
),
should = Nil,
Expand All @@ -304,7 +304,7 @@ object QueryDSLSpec extends ZIOSpecDefault {
mustNot = List(Match(field = "intField", value = 50, boost = None)),
should = List(
Range(field = "intField", lower = GreaterThan(1), upper = LessThanOrEqualTo(100), boost = None),
Match(field = "testField", value = "test", boost = None)
Match(field = "stringField", value = "test", boost = None)
),
boost = Some(3.14),
minimumShouldMatch = Some(3)
Expand All @@ -313,6 +313,58 @@ object QueryDSLSpec extends ZIOSpecDefault {
)
}
),
test("contains") {
val query = contains("testField", "test")
val queryTs = contains(TestDocument.stringField, "test")
val queryWithSuffix = contains(TestDocument.stringField.raw, "test")
val queryWithBoost = contains(TestDocument.stringField, "test").boost(10.21)
val queryWithCaseInsensitive = contains(TestDocument.stringField, "test").caseInsensitiveTrue
val queryAllParams = contains(TestDocument.stringField, "test").boost(3.14).caseInsensitiveFalse

assert(query)(
equalTo(Wildcard[Any](field = "testField", value = "*test*", boost = None, caseInsensitive = None))
) &&
assert(queryTs)(
equalTo(
Wildcard[TestDocument](field = "stringField", value = "*test*", boost = None, caseInsensitive = None)
)
) &&
assert(queryWithSuffix)(
equalTo(
Wildcard[TestDocument](field = "stringField.raw", value = "*test*", boost = None, caseInsensitive = None)
)
) &&
assert(queryWithBoost)(
equalTo(
Wildcard[TestDocument](
field = "stringField",
value = "*test*",
boost = Some(10.21),
caseInsensitive = None
)
)
) &&
assert(queryWithCaseInsensitive)(
equalTo(
Wildcard[TestDocument](
field = "stringField",
value = "*test*",
boost = None,
caseInsensitive = Some(true)
)
)
) &&
assert(queryAllParams)(
equalTo(
Wildcard[TestDocument](
field = "stringField",
value = "*test*",
boost = Some(3.14),
caseInsensitive = Some(false)
)
)
)
},
test("exists") {
val query = exists("testField")
val queryTs = exists(TestDocument.intField)
Expand Down Expand Up @@ -462,63 +514,6 @@ object QueryDSLSpec extends ZIOSpecDefault {
)
)
},
test("term") {
val query = term("stringField", "test")
val queryTs = term(TestDocument.stringField, "test")
val queryWithSuffix = term(TestDocument.stringField.keyword, "test")
val queryWithBoost = term(TestDocument.stringField, "test").boost(10.21)
val queryWithCaseInsensitive = term(TestDocument.stringField, "test").caseInsensitiveTrue
val queryAllParams = term(TestDocument.stringField, "test").boost(3.14).caseInsensitiveFalse

assert(query)(
equalTo(Term[Any](field = "stringField", value = "test", boost = None, caseInsensitive = None))
) &&
assert(queryTs)(
equalTo(Term[TestDocument](field = "stringField", value = "test", boost = None, caseInsensitive = None))
) &&
assert(queryWithSuffix)(
equalTo(
Term[TestDocument](field = "stringField.keyword", value = "test", boost = None, caseInsensitive = None)
)
) &&
assert(queryWithBoost)(
equalTo(
Term[TestDocument](field = "stringField", value = "test", boost = Some(10.21), caseInsensitive = None)
)
) &&
assert(queryWithCaseInsensitive)(
equalTo(
Term[TestDocument](field = "stringField", value = "test", boost = None, caseInsensitive = Some(true))
)
) &&
assert(queryAllParams)(
equalTo(
Term[TestDocument](
field = "stringField",
value = "test",
boost = Some(3.14),
caseInsensitive = Some(false)
)
)
)
},
test("terms") {
val query = terms("stringField", "a", "b", "c")
val queryTs = terms(TestDocument.stringField, "a", "b", "c")
val queryWithSuffix = terms(TestDocument.stringField.keyword, "a", "b", "c")
val queryWithBoost = terms(TestDocument.stringField, "a", "b", "c").boost(10.21)

assert(query)(equalTo(Terms[Any](field = "stringField", values = List("a", "b", "c"), boost = None))) &&
assert(queryTs)(
equalTo(Terms[TestDocument](field = "stringField", values = List("a", "b", "c"), boost = None))
) &&
assert(queryWithSuffix)(
equalTo(Terms[TestDocument](field = "stringField.keyword", values = List("a", "b", "c"), boost = None))
) &&
assert(queryWithBoost)(
equalTo(Terms[TestDocument](field = "stringField", values = List("a", "b", "c"), boost = Some(10.21)))
)
},
test("range") {
val query = range("testField")
val queryString = range(TestDocument.stringField)
Expand Down Expand Up @@ -632,13 +627,113 @@ object QueryDSLSpec extends ZIOSpecDefault {
)
)
},
test("startsWith") {
val query = startsWith("testField", "test")
val queryTs = startsWith(TestDocument.stringField, "test")
val queryWithSuffix = startsWith(TestDocument.stringField.raw, "test")
val queryWithBoost = startsWith(TestDocument.stringField, "test").boost(10.21)
val queryWithCaseInsensitive = startsWith(TestDocument.stringField, "test").caseInsensitiveTrue
val queryAllParams = startsWith(TestDocument.stringField, "test").boost(3.14).caseInsensitiveFalse

assert(query)(
equalTo(Wildcard[Any](field = "testField", value = "test*", boost = None, caseInsensitive = None))
) &&
assert(queryTs)(
equalTo(
Wildcard[TestDocument](field = "stringField", value = "test*", boost = None, caseInsensitive = None)
)
) &&
assert(queryWithSuffix)(
equalTo(
Wildcard[TestDocument](field = "stringField.raw", value = "test*", boost = None, caseInsensitive = None)
)
) &&
assert(queryWithBoost)(
equalTo(
Wildcard[TestDocument](
field = "stringField",
value = "test*",
boost = Some(10.21),
caseInsensitive = None
)
)
) &&
assert(queryWithCaseInsensitive)(
equalTo(
Wildcard[TestDocument](field = "stringField", value = "test*", boost = None, caseInsensitive = Some(true))
)
) &&
assert(queryAllParams)(
equalTo(
Wildcard[TestDocument](
field = "stringField",
value = "test*",
boost = Some(3.14),
caseInsensitive = Some(false)
)
)
)
},
test("term") {
val query = term("stringField", "test")
val queryTs = term(TestDocument.stringField, "test")
val queryWithSuffix = term(TestDocument.stringField.keyword, "test")
val queryWithBoost = term(TestDocument.stringField, "test").boost(10.21)
val queryWithCaseInsensitive = term(TestDocument.stringField, "test").caseInsensitiveTrue
val queryAllParams = term(TestDocument.stringField, "test").boost(3.14).caseInsensitiveFalse

assert(query)(
equalTo(Term[Any](field = "stringField", value = "test", boost = None, caseInsensitive = None))
) &&
assert(queryTs)(
equalTo(Term[TestDocument](field = "stringField", value = "test", boost = None, caseInsensitive = None))
) &&
assert(queryWithSuffix)(
equalTo(
Term[TestDocument](field = "stringField.keyword", value = "test", boost = None, caseInsensitive = None)
)
) &&
assert(queryWithBoost)(
equalTo(
Term[TestDocument](field = "stringField", value = "test", boost = Some(10.21), caseInsensitive = None)
)
) &&
assert(queryWithCaseInsensitive)(
equalTo(
Term[TestDocument](field = "stringField", value = "test", boost = None, caseInsensitive = Some(true))
)
) &&
assert(queryAllParams)(
equalTo(
Term[TestDocument](
field = "stringField",
value = "test",
boost = Some(3.14),
caseInsensitive = Some(false)
)
)
)
},
test("terms") {
val query = terms("stringField", "a", "b", "c")
val queryTs = terms(TestDocument.stringField, "a", "b", "c")
val queryWithSuffix = terms(TestDocument.stringField.keyword, "a", "b", "c")
val queryWithBoost = terms(TestDocument.stringField, "a", "b", "c").boost(10.21)

assert(query)(equalTo(Terms[Any](field = "stringField", values = List("a", "b", "c"), boost = None))) &&
assert(queryTs)(
equalTo(Terms[TestDocument](field = "stringField", values = List("a", "b", "c"), boost = None))
) &&
assert(queryWithSuffix)(
equalTo(Terms[TestDocument](field = "stringField.keyword", values = List("a", "b", "c"), boost = None))
) &&
assert(queryWithBoost)(
equalTo(Terms[TestDocument](field = "stringField", values = List("a", "b", "c"), boost = Some(10.21)))
)
},
test("wildcard") {
val query = wildcard("testField", "test")
val queryContains = contains("testField", "test")
val queryStartsWith = startsWith("testField", "test")
val queryTs = wildcard(TestDocument.stringField, "test")
val queryContainsTs = contains(TestDocument.stringField, "test")
val queryStartsWithTs = startsWith(TestDocument.stringField, "test")
val queryWithSuffix = wildcard(TestDocument.stringField.raw, "test")
val queryWithBoost = wildcard(TestDocument.stringField, "test").boost(10.21)
val queryWithCaseInsensitive = wildcard(TestDocument.stringField, "test").caseInsensitiveTrue
Expand All @@ -647,25 +742,9 @@ object QueryDSLSpec extends ZIOSpecDefault {
assert(query)(
equalTo(Wildcard[Any](field = "testField", value = "test", boost = None, caseInsensitive = None))
) &&
assert(queryContains)(
equalTo(Wildcard[Any](field = "testField", value = "*test*", boost = None, caseInsensitive = None))
) &&
assert(queryStartsWith)(
equalTo(Wildcard[Any](field = "testField", value = "test*", boost = None, caseInsensitive = None))
) &&
assert(queryTs)(
equalTo(Wildcard[TestDocument](field = "stringField", value = "test", boost = None, caseInsensitive = None))
) &&
assert(queryContainsTs)(
equalTo(
Wildcard[TestDocument](field = "stringField", value = "*test*", boost = None, caseInsensitive = None)
)
) &&
assert(queryStartsWithTs)(
equalTo(
Wildcard[TestDocument](field = "stringField", value = "test*", boost = None, caseInsensitive = None)
)
) &&
assert(queryWithSuffix)(
equalTo(
Wildcard[TestDocument](field = "stringField.raw", value = "test", boost = None, caseInsensitive = None)
Expand Down

0 comments on commit 8319008

Please sign in to comment.