Skip to content

Commit

Permalink
(tests): Restructure ScriptSpec (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
saksofon997 authored Jun 24, 2023
1 parent 0ac0d9a commit 5ced9c9
Showing 1 changed file with 38 additions and 45 deletions.
83 changes: 38 additions & 45 deletions modules/library/src/test/scala/zio/elasticsearch/ScriptSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,32 @@ object ScriptSpec extends ZIOSpecDefault {
def spec: Spec[Environment with TestEnvironment with Scope, Any] =
suite("Script")(
suite("constructing")(
test("create script with source") {
val source = "doc['day_of_week'].value"
test("script") {
val source = "doc['day_of_week'].value"
val sourceWithParams = "doc['day_of_week'].value * params['factor']"
val params = "factor" -> 2
val lang = Painless

assert(Script(source))(equalTo(Script(source, Map.empty, None)))
},
test("create script with source and params") {
val source = "doc['day_of_week'].value * params['factor']"
val params = "factor" -> 2
val script = Script(source)
val scriptWithParams = Script(sourceWithParams).params(params)
val scriptWithLang = Script(sourceWithParams).lang(lang)
val scriptWithLangAndParams =
Script(sourceWithParams).params(params).lang(lang)

assert(Script(source).params(params))(
assert(script)(equalTo(Script(source, Map.empty, None))) && assert(
scriptWithParams
)(
equalTo(
Script(source = source, params = Map(params), lang = None)
Script(source = sourceWithParams, params = Map(params), lang = None)
)
)
},
test("create script with source and lang") {
val source = "doc['day_of_week'].value * params['factor']"
val lang = Painless

assert(Script(source).lang(lang))(
) && assert(scriptWithLang)(
equalTo(
Script(source = source, params = Map.empty, lang = Some(lang))
Script(source = sourceWithParams, params = Map.empty, lang = Some(lang))
)
)
},
test("create script with source, params and lang") {
val source = "doc['day_of_week'].value * params['factor']"
val params = "factor" -> 2
val lang = Painless

assert(Script(source).params(params).lang(lang))(
) && assert(scriptWithLangAndParams)(
equalTo(
Script(
source = source,
source = sourceWithParams,
params = Map(params),
lang = Some(lang)
)
Expand All @@ -52,20 +44,26 @@ object ScriptSpec extends ZIOSpecDefault {
}
),
suite("encoding as JSON")(
test("create script with source") {
val script = Script("doc['day_of_week'].value")
test("script") {
val source = "doc['day_of_week'].value"
val sourceWithParams = "doc['day_of_week'].value * params['factor']"
val params = "factor" -> 2
val lang = Painless

val script = Script(source)
val scriptWithParams = Script(sourceWithParams).params(params)
val scriptWithLang = Script(source).lang(lang)
val scriptWithLangAndParams =
Script(sourceWithParams).params(params).lang(lang)

val expected =
"""
|{
| "source": "doc['day_of_week'].value"
|}
|""".stripMargin

assert(script.toJson)(equalTo(expected.toJson))
},
test("create script with source and params") {
val script = Script("doc['day_of_week'].value * params['factor']").params("factor" -> 2)
val expected =
val expectedWithParams =
"""
|{
| "source": "doc['day_of_week'].value * params['factor']",
Expand All @@ -75,24 +73,15 @@ object ScriptSpec extends ZIOSpecDefault {
|}
|""".stripMargin

assert(script.toJson)(equalTo(expected.toJson))
},
test("create script with source and lang") {
val script = Script("doc['day_of_week'].value").lang(Painless)
val expected =
val expectedWithLang =
"""
|{
| "lang": "painless",
| "source": "doc['day_of_week'].value"
|}
|""".stripMargin

assert(script.toJson)(equalTo(expected.toJson))
},
test("create script with source, params and lang") {
val script =
Script("doc['day_of_week'].value * params['factor']").params("factor" -> 2).lang(Painless)
val expected =
val expectedWithLangAndParams =
"""
|{
| "lang": "painless",
Expand All @@ -103,7 +92,11 @@ object ScriptSpec extends ZIOSpecDefault {
|}
|""".stripMargin

assert(script.toJson)(equalTo(expected.toJson))
assert(script.toJson)(equalTo(expected.toJson)) && assert(scriptWithParams.toJson)(
equalTo(expectedWithParams.toJson)
) && assert(scriptWithLang.toJson)(equalTo(expectedWithLang.toJson)) && assert(
scriptWithLangAndParams.toJson
)(equalTo(expectedWithLangAndParams.toJson))
}
)
)
Expand Down

0 comments on commit 5ced9c9

Please sign in to comment.