11package com .gu .liveactivities
22
3-
43import com .amazonaws .services .dynamodbv2 .model ._
54import org .specs2 .concurrent .ExecutionEnv
65import org .specs2 .mock .Mockito
76import tracking .Repository .RepositoryResult
8-
7+ import tracking . RepositoryError
98import scala .concurrent .Future
109import scala .jdk .CollectionConverters ._
1110
12-
13- class LiveActivityChannelRepositoryTest (implicit ev : ExecutionEnv ) extends DynamodbSpecification with Mockito {
11+ class LiveActivityChannelRepositoryTest (implicit ev : ExecutionEnv )
12+ extends DynamodbSpecification
13+ with Mockito {
1414
1515 override val TableName = " test-table"
1616
@@ -20,23 +20,38 @@ class LiveActivityChannelRepositoryTest (implicit ev: ExecutionEnv) extends Dyna
2020 1 must beEqualTo(1 )
2121 }
2222
23- " save a new channel mapping for an id if it does not exist" in new RepositoryScope with ExampleData {
23+ " save a new channel mapping for an id if it does not exist" in new RepositoryScope
24+ with ExampleData {
2425 repository.saveMapping(footballMapping).flatMap { _ =>
2526 repository.getMappingByActivityId(footballMapping.liveActivityId)
26- } must beEqualTo(Right (Some ( footballMapping) )).await
27+ } must beEqualTo(Right (footballMapping)).await
2728 }
2829
29- " Error if trying to save a new channel mapping for an id that already exists" in new RepositoryScope with ExampleData {
30+ " Error if trying to save a new channel mapping for an id that already exists" in new RepositoryScope
31+ with ExampleData {
3032 repository.saveMapping(footballMapping).flatMap { _ =>
31- repository.getMappingByActivityId(footballMapping.liveActivityId)
32- } must beEqualTo(Right (Some (footballMapping))).await
33+ repository.saveMapping(footballMapping)
34+ } must beLike[RepositoryResult [Unit ]] {
35+ case Left (RepositoryError (msg))
36+ if msg.contains(" ConditionalCheckFailed" ) =>
37+ ok
38+ }.await
39+ }
40+
41+ " delete a channel mapping for an activity id if it exists" in new RepositoryScope
42+ with ExampleData {
43+
44+ repository.saveMapping(footballMapping).flatMap { _ =>
45+ repository.deleteMappingByActivityId(footballMapping.liveActivityId)
46+ } must beEqualTo(Right (())).await
3347 }
3448
35- // "delete a channel mapping for an activity id if it exists" in new RepositoryScope with ExampleData {
36- // }
37- //
38- // "get a channel mapping for an activity id if it exists" in new RepositoryScope with ExampleData {
39- // }
49+ " get a channel mapping for an activity id if it exists" in new RepositoryScope
50+ with ExampleData {
51+ repository.saveMapping(footballMapping).flatMap { _ =>
52+ repository.getMappingByActivityId(footballMapping.liveActivityId)
53+ } must beEqualTo(Right (footballMapping)).await
54+ }
4055 }
4156
4257 trait RepositoryScope extends AsyncDynamoScope {
@@ -60,11 +75,16 @@ class LiveActivityChannelRepositoryTest (implicit ev: ExecutionEnv) extends Dyna
6075 override def createTableRequest : CreateTableRequest = {
6176 val IdField = " liveActivityId"
6277
63- new CreateTableRequest (TableName , List (new KeySchemaElement (IdField , KeyType .HASH )).asJava)
64- .withAttributeDefinitions(List (
65- new AttributeDefinition (IdField , ScalarAttributeType .S )
66- ).asJava)
78+ new CreateTableRequest (
79+ TableName ,
80+ List (new KeySchemaElement (IdField , KeyType .HASH )).asJava
81+ )
82+ .withAttributeDefinitions(
83+ List (
84+ new AttributeDefinition (IdField , ScalarAttributeType .S )
85+ ).asJava
86+ )
6787 .withProvisionedThroughput(new ProvisionedThroughput (5L , 5L ))
6888 }
6989
70- }
90+ }
0 commit comments