Skip to content

Commit e05abd9

Browse files
committed
Merge branch 'master' of github.com:moia-oss/scynamo
2 parents c0bd701 + c9263c5 commit e05abd9

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/main/scala/scynamo/Scynamo.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scynamo
22

33
import cats.data.EitherNec
4-
import software.amazon.awssdk.services.dynamodb.model.{GetItemResponse, QueryResponse}
4+
import software.amazon.awssdk.services.dynamodb.model.{GetItemResponse, QueryResponse, ScanResponse}
55
import cats.syntax.all._
66

77
import scala.jdk.CollectionConverters._
@@ -16,4 +16,8 @@ trait ScynamoFunctions {
1616

1717
def decodeQueryResponse[A: ObjectScynamoDecoder](response: QueryResponse): EitherNec[ScynamoDecodeError, List[A]] =
1818
response.items().asScala.toList.traverse(ObjectScynamoDecoder[A].decodeMap(_))
19+
20+
def decodeScanResponse[A: ObjectScynamoDecoder](response: ScanResponse): EitherNec[ScynamoDecodeError, List[A]] =
21+
response.items().asScala.toList.traverse(ObjectScynamoDecoder[A].decodeMap(_))
22+
1923
}

src/test/scala/scynamo/ScynamoTest.scala

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scynamo
22

3-
import software.amazon.awssdk.services.dynamodb.model.{AttributeValue, GetItemResponse, QueryResponse}
3+
import software.amazon.awssdk.services.dynamodb.model.{AttributeValue, GetItemResponse, QueryResponse, ScanResponse}
44

55
class ScynamoTest extends UnitTest {
66
"Scynamo" should {
@@ -23,6 +23,16 @@ class ScynamoTest extends UnitTest {
2323
result should ===(Right(List.empty))
2424
}
2525

26+
"return an empty List if the scan response has no items" in {
27+
val response = ScanResponse.builder().build()
28+
29+
val result = for {
30+
result <- Scynamo.decodeScanResponse[Map[String, AttributeValue]](response)
31+
} yield result
32+
33+
result should ===(Right(List.empty))
34+
}
35+
2636
"return the decoded result if it has an item that is well formed" in {
2737
import scynamo.syntax.encoder._
2838
val input = Map("foo" -> "bar")
@@ -36,7 +46,7 @@ class ScynamoTest extends UnitTest {
3646
result should ===(Right(Some(input)))
3747
}
3848

39-
"return the decoded result if it has multiple items that are well formed" in {
49+
"return the decoded query result if it has multiple items that are well formed" in {
4050
import scynamo.syntax.encoder._
4151
val input1 = Map("foo" -> "bar")
4252
val input2 = Map("Miami" -> "Ibiza")
@@ -49,5 +59,19 @@ class ScynamoTest extends UnitTest {
4959
} yield result
5060
result should ===(Right(List(input1, input2)))
5161
}
62+
63+
"return the decoded scan result if it has multiple items that are well formed" in {
64+
import scynamo.syntax.encoder._
65+
val input1 = Map("foo" -> "bar")
66+
val input2 = Map("Miami" -> "Ibiza")
67+
68+
val result = for {
69+
encodedInput1 <- input1.encodedMap
70+
encodedInput2 <- input2.encodedMap
71+
response = ScanResponse.builder().items(encodedInput1, encodedInput2).build()
72+
result <- Scynamo.decodeScanResponse[Map[String, String]](response)
73+
} yield result
74+
result should ===(Right(List(input1, input2)))
75+
}
5276
}
5377
}

0 commit comments

Comments
 (0)