-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace @enumOfCaseObject with @simpleEnum #323
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,35 +284,20 @@ object ItemDecoderSpec extends ZIOSpecDefault with CodecTestFixtures { | |
|
||
assert(actual)(isRight(equalTo(PreBilled(id = 1, s = "foobar")))) | ||
}, | ||
test("decodes case object only enum with @enumOfCaseObjects annotation and without @caseName annotation") { | ||
test("decodes case object only enum with @simpleEnum annotation and without @caseName annotation") { | ||
val item: Item = Item(Map("enum" -> AttributeValue.String("ONE"))) | ||
|
||
val actual = DynamoDBQuery.fromItem[WithCaseObjectOnlyEnum](item) | ||
|
||
assert(actual)(isRight(equalTo(WithCaseObjectOnlyEnum(WithCaseObjectOnlyEnum.ONE)))) | ||
}, | ||
test("decodes case object only enum with @enumOfCaseObjects annotation and @caseName annotation of '2'") { | ||
test("decodes case object only enum with @simpleEnum annotation and @caseName annotation of '2'") { | ||
val item: Item = Item(Map("enum" -> AttributeValue.String("2"))) | ||
|
||
val actual = DynamoDBQuery.fromItem[WithCaseObjectOnlyEnum](item) | ||
|
||
assert(actual)(isRight(equalTo(WithCaseObjectOnlyEnum(WithCaseObjectOnlyEnum.TWO)))) | ||
}, | ||
test("fails decoding of enum with @enumOfCaseObjects annotation that does not have all case objects") { | ||
val item: Item = Item(Map("enum" -> AttributeValue.String("ONE"))) | ||
|
||
val actual = DynamoDBQuery.fromItem[WithCaseObjectOnlyEnum2](item) | ||
|
||
assert(actual)( | ||
isLeft( | ||
hasMessage( | ||
equalTo( | ||
"Can not decode enum String(ONE) - @enumOfCaseObjects annotation present when all instances are not case objects." | ||
) | ||
) | ||
) | ||
) | ||
}, | ||
Comment on lines
-301
to
-315
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
test( | ||
"decodes enum and honours @caseName annotation at case class level when there is no @discriminatorName annotation" | ||
) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import zio.test._ | |
import java.time.Instant | ||
import scala.collection.immutable.ListMap | ||
import zio.test.ZIOSpecDefault | ||
import scala.util.Try | ||
|
||
object ItemEncoderSpec extends ZIOSpecDefault with CodecTestFixtures { | ||
override def spec = suite("ItemEncoder Suite")(mainSuite) | ||
|
@@ -219,35 +218,21 @@ object ItemEncoderSpec extends ZIOSpecDefault with CodecTestFixtures { | |
|
||
assert(item)(equalTo(expectedItem)) | ||
}, | ||
test("encodes case object only enum with @enumOfCaseObjects annotation") { | ||
test("encodes case object only enum with @simpleEnum annotation") { | ||
val expectedItem: Item = Item(Map("enum" -> AttributeValue.String("ONE"))) | ||
|
||
val item = DynamoDBQuery.toItem(WithCaseObjectOnlyEnum(WithCaseObjectOnlyEnum.ONE)) | ||
|
||
assert(item)(equalTo(expectedItem)) | ||
}, | ||
test("encodes case object only enum with @enumOfCaseObjects annotation and @caseName annotation of '2'") { | ||
test("encodes case object only enum with @simpleEnum annotation and @caseName annotation of '2'") { | ||
val expectedItem: Item = Item(Map("enum" -> AttributeValue.String("2"))) | ||
|
||
val item = DynamoDBQuery.toItem(WithCaseObjectOnlyEnum(WithCaseObjectOnlyEnum.TWO)) | ||
|
||
assert(item)(equalTo(expectedItem)) | ||
}, | ||
test("fails encoding of enum with @enumOfCaseObjects annotation that does not have all case objects") { | ||
|
||
val item = Try(DynamoDBQuery.toItem(WithCaseObjectOnlyEnum2(WithCaseObjectOnlyEnum2.ONE))) | ||
|
||
assert(item)( | ||
isFailure( | ||
hasMessage( | ||
equalTo( | ||
"Can not encode enum ONE - @enumOfCaseObjects annotation present when all instances are not case objects." | ||
) | ||
) | ||
) | ||
) | ||
}, | ||
test("encodes enum and honours @caseName annotation when there is no @enumOfCaseObjects annotation") { | ||
Comment on lines
-236
to
-250
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
test("encodes enum and honours @caseName annotation when there is no @simpleEnum annotation") { | ||
val expectedItem: Item = Item("enum" -> Item(Map("1" -> AttributeValue.Null))) | ||
|
||
val item = DynamoDBQuery.toItem(WithEnumWithoutDiscriminator(WithEnumWithoutDiscriminator.ONE)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
examples/src/main/scala/zio/dynamodb/examples/model/Student.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not pretty sure if we need to keep these test cases as it seems they test what was tested by zio-schema.