Skip to content

Commit a1f5e49

Browse files
committed
WIP update dynamo tests
1 parent ffb4993 commit a1f5e49

3 files changed

Lines changed: 43 additions & 25 deletions

File tree

liveactivities/src/test/scala/com/gu/liveactivities/DynamodbSpecification.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait DynamodbSpecification extends Specification with BeforeAfterAll {
2424

2525
def createTableRequest: CreateTableRequest
2626

27-
val TestEndpoint = "http://localhost:8002"
27+
val TestEndpoint = "http://localhost:8000"
2828

2929
override def beforeAll(): Unit = {
3030
awsClient.createTable(createTableRequest)
@@ -39,9 +39,8 @@ trait DynamodbSpecification extends Specification with BeforeAfterAll {
3939
override def refresh(): Unit = {}
4040

4141
override def getCredentials: AWSCredentials = new AWSCredentials {
42-
override def getAWSAccessKeyId: String = ""
43-
44-
override def getAWSSecretKey: String = ""
42+
override def getAWSAccessKeyId: String = "testid"
43+
override def getAWSSecretKey: String = "testkey"
4544
}
4645
})
4746

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.gu.liveactivities
22

3-
43
import com.amazonaws.services.dynamodbv2.model._
54
import org.specs2.concurrent.ExecutionEnv
65
import org.specs2.mock.Mockito
76
import tracking.Repository.RepositoryResult
8-
7+
import tracking.RepositoryError
98
import scala.concurrent.Future
109
import 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+
}

project/LocalDynamoDBLiveActivities.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ object LocalDynamoDBLiveActivities {
77
val settings: Seq[Setting[_]] = DynamoDBLocalKeys.baseDynamoDBSettings ++ Seq(
88
dynamoDBLocalDownloadDir := file("dynamodb-local-live-activities"),
99
dynamoDBLocalInMemory := true,
10-
dynamoDBLocalVersion := "latest",
11-
// dynamoDBLocalSharedDB := true, // Add this line
10+
dynamoDBLocalVersion := "2018-04-11",
1211
dynamoDBLocalPort := 8002
1312
)
1413
}

0 commit comments

Comments
 (0)