From 3798c122fdb80892505c6e04875188e1be4b326e Mon Sep 17 00:00:00 2001 From: Dimitrije Bulaja Date: Fri, 12 May 2023 15:06:54 +0200 Subject: [PATCH] Resolve conflicts --- .../aggregation/Aggregations.scala | 2 +- .../ElasticAggregationSpec.scala | 53 ++++++++++++------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/modules/library/src/main/scala/zio/elasticsearch/aggregation/Aggregations.scala b/modules/library/src/main/scala/zio/elasticsearch/aggregation/Aggregations.scala index 23aa182d6..e9cb54338 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/aggregation/Aggregations.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/aggregation/Aggregations.scala @@ -39,7 +39,7 @@ private[elasticsearch] final case class BucketSelector(name: String, script: Scr def withAgg(agg: SingleElasticAggregation): MultipleAggregations = multipleAggregations.aggregations(self, agg) - private[elasticsearch] def paramsToJson: Json = { + private[elasticsearch] def togJson: Json = { val bucketsPathJson: Json = Obj("buckets_path" -> bucketsPath.collect { case (scriptVal, path) => Obj(scriptVal -> path.toJson) }.reduce(_ merge _)) diff --git a/modules/library/src/test/scala/zio/elasticsearch/ElasticAggregationSpec.scala b/modules/library/src/test/scala/zio/elasticsearch/ElasticAggregationSpec.scala index e2d596759..2a1c38194 100644 --- a/modules/library/src/test/scala/zio/elasticsearch/ElasticAggregationSpec.scala +++ b/modules/library/src/test/scala/zio/elasticsearch/ElasticAggregationSpec.scala @@ -335,24 +335,41 @@ object ElasticAggregationSpec extends ZIOSpecDefault { bucketsPath = Map("agg1" -> "aggregation1", "agg2" -> "aggregation2") ) - assert(aggregation1)( - equalTo( - BucketSelector( - name = "aggregation", - script = Script("params.agg1 > 10"), - bucketsPath = Map("agg1" -> "aggregation1") - ) - ) - ) && - assert(aggregation2)( - equalTo( - BucketSelector( - name = "aggregation", - script = Script("params.agg1 + params.agg2 > 10"), - bucketsPath = Map("agg1" -> "aggregation1", "agg2" -> "aggregation2") - ) - ) - ) + val expected1 = + """ + |{ + | "aggregation": { + | "bucket_selector": { + | "buckets_path": { + | "agg1": "aggregation1" + | }, + | "script": { + | "source": "params.agg1 > 10" + | } + | } + | } + |} + |""".stripMargin + + val expected2 = + """ + |{ + | "aggregation": { + | "bucket_selector": { + | "buckets_path": { + | "agg1": "aggregation1", + | "agg2": "aggregation2" + | }, + | "script": { + | "source": "params.agg1 + params.agg2 > 10" + | } + | } + | } + |} + |""".stripMargin + + assert(aggregation1.toJson)(equalTo(expected1.toJson)) && + assert(aggregation2.toJson)(equalTo(expected2.toJson)) }, test("bucketSort") { val aggregationWithFrom = bucketSortAggregation("aggregation").from(5)