Skip to content

Commit

Permalink
Tests for JsonCodec for Schema.EnumN (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
987Nabil committed Jun 30, 2024
1 parent ad289bc commit 2f538ed
Showing 1 changed file with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ object JsonCodecSpec extends ZIOSpecDefault {
)
}
),
suite("Generic Record") {
suite("Generic Record")(
test("Do not encode transient field") {
assertEncodes(
RecordExample.schema.annotate(rejectExtraFields()),
Expand All @@ -427,8 +427,16 @@ object JsonCodecSpec extends ZIOSpecDefault {
)
)
}

}
),
suite("EnumN")(
test("Respects the case name annotation") {
assertEncodesJson(
Enum23Cases.schema,
Enum23Cases.Case1("foo"),
"""{"NumberOne":{"value":"foo"}}"""
)
}
)
)

private val decoderSuite = suite("decoding")(
Expand All @@ -447,7 +455,7 @@ object JsonCodecSpec extends ZIOSpecDefault {
)
} @@ TestAspect.jvmOnly
),
suite("generic record")(
suite("Generic record")(
test("with extra fields") {
assertDecodes(
recordSchema,
Expand Down Expand Up @@ -484,6 +492,22 @@ object JsonCodecSpec extends ZIOSpecDefault {
)
}
),
suite("EnumN")(
test("Respects the case name annotation") {
assertDecodes(
Enum23Cases.schema,
Enum23Cases.Case1("foo"),
charSequenceToByteChunk("""{"NumberOne":{"value":"foo"}}""")
)
},
test("Respects case aliases") {
assertDecodes(
Enum23Cases.schema,
Enum23Cases.Case1("foo"),
charSequenceToByteChunk("""{"One":{"value":"foo"}}""")
)
}
),
suite("transform")(
test("string") {
val stringSchema = Schema.Primitive(StandardType.StringType)
Expand Down Expand Up @@ -1975,4 +1999,55 @@ object JsonCodecSpec extends ZIOSpecDefault {
DeriveSchema.gen[RecordExampleWithOptField]
}

sealed trait Enum23Cases

object Enum23Cases {
implicit lazy val schema: Schema[Enum23Cases] = DeriveSchema.gen[Enum23Cases]

@caseName("NumberOne") @caseNameAliases("One") case class Case1(value: String) extends Enum23Cases

case class Case2(value: Int) extends Enum23Cases

case class Case3(value: String) extends Enum23Cases

case class Case4(value: String) extends Enum23Cases

case class Case5(value: String) extends Enum23Cases

case class Case6(value: String) extends Enum23Cases

case class Case7(value: String) extends Enum23Cases

case class Case8(value: String) extends Enum23Cases

case class Case9(value: String) extends Enum23Cases

case class Case10(value: String) extends Enum23Cases

case class Case11(value: String) extends Enum23Cases

case class Case12(value: String) extends Enum23Cases

case class Case13(value: String) extends Enum23Cases

case class Case14(value: String) extends Enum23Cases

case class Case15(value: String) extends Enum23Cases

case class Case16(value: String) extends Enum23Cases

case class Case17(value: String) extends Enum23Cases

case class Case18(value: String) extends Enum23Cases

case class Case19(value: String) extends Enum23Cases

case class Case20(value: String) extends Enum23Cases

case class Case21(value: String) extends Enum23Cases

case class Case22(value: String) extends Enum23Cases

case class Case23(value: String) extends Enum23Cases
}
}

0 comments on commit 2f538ed

Please sign in to comment.