Skip to content

Commit

Permalink
Add tests for .everyItem in OuterTransformers without nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Oct 8, 2024
1 parent ebe27d2 commit 979fb5d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,77 @@ class PartialTransformerIntegrationsSpec extends ChimneySpec {
test("transform using TotalOuterTransformer") {
import OuterTransformers.totalNonEmptyToSorted

val result = NonEmptyWrapper("b", "a").transformIntoPartial[SortedWrapper[String]]
result.asOption ==> Some(SortedWrapper("a", "b"))
result.asEither ==> Right(SortedWrapper("a", "b"))
result.asErrorPathMessageStrings ==> Iterable.empty

implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value)

val result = NonEmptyWrapper(Foo("b"), Foo("a")).transformIntoPartial[SortedWrapper[Bar]]
result.asOption ==> Some(SortedWrapper(Bar("a"), Bar("b")))
result.asEither ==> Right(SortedWrapper(Bar("a"), Bar("b")))
result.asErrorPathMessageStrings ==> Iterable.empty
val result2 = NonEmptyWrapper(Foo("b"), Foo("a")).transformIntoPartial[SortedWrapper[Bar]]
result2.asOption ==> Some(SortedWrapper(Bar("a"), Bar("b")))
result2.asEither ==> Right(SortedWrapper(Bar("a"), Bar("b")))
result2.asErrorPathMessageStrings ==> Iterable.empty
}

test("transform using TotalOuterTransformer with an override") {
import OuterTransformers.totalNonEmptyToSorted

val result = NonEmptyWrapper("b", "a")
.intoPartial[SortedWrapper[String]]
.withFieldConst(_.everyItem, "c")
.transform
result.asOption ==> Some(SortedWrapper("c"))
result.asEither ==> Right(SortedWrapper("c"))
result.asErrorPathMessageStrings ==> Iterable.empty

implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value)

val result = NonEmptyWrapper(Foo("b"), Foo("a"))
val result2 = NonEmptyWrapper(Foo("b"), Foo("a"))
.intoPartial[SortedWrapper[Bar]]
.withFieldConst(_.everyItem.value, "c")
.transform
result.asOption ==> Some(SortedWrapper(Bar("c")))
result.asEither ==> Right(SortedWrapper(Bar("c")))
result.asErrorPathMessageStrings ==> Iterable.empty
result2.asOption ==> Some(SortedWrapper(Bar("c")))
result2.asEither ==> Right(SortedWrapper(Bar("c")))
result2.asErrorPathMessageStrings ==> Iterable.empty
}

test("transform using PartialOuterTransformer") {
import OuterTransformers.partialNonEmptyToSorted

val result = NonEmptyWrapper("b", "a").transformIntoPartial[SortedWrapper[String]]
result.asOption ==> Some(SortedWrapper("a", "b"))
result.asEither ==> Right(SortedWrapper("a", "b"))
result.asErrorPathMessageStrings ==> Iterable.empty

implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value)

val result = NonEmptyWrapper(Foo("b"), Foo("a")).transformIntoPartial[SortedWrapper[Bar]]
result.asOption ==> Some(SortedWrapper(Bar("a"), Bar("b")))
result.asEither ==> Right(SortedWrapper(Bar("a"), Bar("b")))
result.asErrorPathMessageStrings ==> Iterable.empty
val result2 = NonEmptyWrapper(Foo("b"), Foo("a")).transformIntoPartial[SortedWrapper[Bar]]
result2.asOption ==> Some(SortedWrapper(Bar("a"), Bar("b")))
result2.asEither ==> Right(SortedWrapper(Bar("a"), Bar("b")))
result2.asErrorPathMessageStrings ==> Iterable.empty
}

test("transform using PartialOuterTransformer with an override") {
import OuterTransformers.partialNonEmptyToSorted

val result = NonEmptyWrapper("b", "a")
.intoPartial[SortedWrapper[String]]
.withFieldConst(_.everyItem, "c")
.transform
result.asOption ==> Some(SortedWrapper("c"))
result.asEither ==> Right(SortedWrapper("c"))
result.asErrorPathMessageStrings ==> Iterable.empty

implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value)

val result = NonEmptyWrapper(Foo("b"), Foo("a"))
val result2 = NonEmptyWrapper(Foo("b"), Foo("a"))
.intoPartial[SortedWrapper[Bar]]
.withFieldConst(_.everyItem.value, "c")
.transform
result.asOption ==> Some(SortedWrapper(Bar("c")))
result.asEither ==> Right(SortedWrapper(Bar("c")))
result.asErrorPathMessageStrings ==> Iterable.empty
result2.asOption ==> Some(SortedWrapper(Bar("c")))
result2.asEither ==> Right(SortedWrapper(Bar("c")))
result2.asErrorPathMessageStrings ==> Iterable.empty
}

test("transform using PartialOuterTransformer resolving total-partial-conflict") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TotalTransformerIntegrationsSpec extends ChimneySpec {

implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value)

NonEmptyWrapper("b", "a").transformInto[SortedWrapper[String]] ==> SortedWrapper("a", "b")
NonEmptyWrapper(Foo("b"), Foo("a")).transformInto[SortedWrapper[Bar]] ==> SortedWrapper(Bar("a"), Bar("b"))
}

Expand All @@ -25,6 +26,10 @@ class TotalTransformerIntegrationsSpec extends ChimneySpec {

implicit val barOrdering: Ordering[Bar] = Ordering[String].on[Bar](_.value)

NonEmptyWrapper("b", "a")
.into[SortedWrapper[String]]
.withFieldConst(_.everyItem, "c")
.transform ==> SortedWrapper("c")
NonEmptyWrapper(Foo("b"), Foo("a"))
.into[SortedWrapper[Bar]]
.withFieldConst(_.everyItem.value, "c")
Expand Down

0 comments on commit 979fb5d

Please sign in to comment.