2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-09-06 01:05:28 +00:00

remove unused BatchChangeInfoSerializer (#776)

* remove unused BatchChangeInfoSerializer

* with extra validation
This commit is contained in:
Rebecca Star
2019-07-30 14:11:12 -04:00
committed by GitHub
parent a72c7faf0a
commit eefa2a3392
4 changed files with 8 additions and 77 deletions

View File

@@ -23,6 +23,10 @@ def test_get_batch_change_success(shared_zone_test_context):
result = client.get_batch_change(batch_change['id'], status=200) result = client.get_batch_change(batch_change['id'], status=200)
assert_that(result, is_(completed_batch)) assert_that(result, is_(completed_batch))
assert_that(result['userId'], is_('ok'))
assert_that(result['userName'], is_('ok'))
assert_that(result, has_key('createdTimestamp'))
assert_that(result['status'], is_('Complete'))
assert_that(result['approvalStatus'], is_('AutoApproved')) assert_that(result['approvalStatus'], is_('AutoApproved'))
assert_that(result, is_not(has_key('reviewerId'))) assert_that(result, is_not(has_key('reviewerId')))
assert_that(result, is_not(has_key('reviewerUserName'))) assert_that(result, is_not(has_key('reviewerUserName')))

View File

@@ -19,7 +19,7 @@ package vinyldns.api.notifier.sns
import vinyldns.core.notifier.{Notification, Notifier} import vinyldns.core.notifier.{Notification, Notifier}
import cats.effect.IO import cats.effect.IO
import cats.syntax.functor._ import cats.syntax.functor._
import vinyldns.core.domain.batch.{BatchChange, BatchChangeInfo} import vinyldns.core.domain.batch.BatchChange
import vinyldns.api.route.VinylDNSJsonProtocol import vinyldns.api.route.VinylDNSJsonProtocol
import org.json4s.jackson.JsonMethods._ import org.json4s.jackson.JsonMethods._
import com.amazonaws.services.sns.AmazonSNS import com.amazonaws.services.sns.AmazonSNS
@@ -33,15 +33,14 @@ class SnsNotifier(config: SnsNotifierConfig, sns: AmazonSNS)
def notify(notification: Notification[_]): IO[Unit] = def notify(notification: Notification[_]): IO[Unit] =
notification.change match { notification.change match {
case bc: BatchChange => sendBatchChangeNotification(BatchChangeInfo(bc)) case bc: BatchChange => sendBatchChangeNotification(bc)
case _ => IO.unit case _ => IO.unit
} }
def sendBatchChangeNotification(bc: BatchChangeInfo): IO[Unit] = def sendBatchChangeNotification(bc: BatchChange): IO[Unit] =
IO { IO {
val message = val message =
compact( compact(render(BatchChangeSerializer.toJson(bc).replace(List("changes"), JNull)).noNulls)
render(BatchChangeInfoSerializer.toJson(bc).replace(List("changes"), JNull)).noNulls)
val request = new PublishRequest(config.topicArn, message) val request = new PublishRequest(config.topicArn, message)
request.addMessageAttributesEntry( request.addMessageAttributesEntry(
"userName", "userName",

View File

@@ -160,19 +160,6 @@ trait BatchChangeJsonProtocol extends JsonValidation {
("scheduledTime" -> Extraction.decompose(bc.scheduledTime)) ("scheduledTime" -> Extraction.decompose(bc.scheduledTime))
} }
case object BatchChangeInfoSerializer extends ValidationSerializer[BatchChangeInfo] {
override def toJson(bc: BatchChangeInfo): JValue =
("userId" -> bc.userId) ~
("userName" -> bc.userName) ~
("comments" -> bc.comments) ~
("createdTimestamp" -> Extraction.decompose(bc.createdTimestamp)) ~
("changes" -> Extraction.decompose(bc.changes)) ~
("status" -> bc.status.toString) ~
("id" -> bc.id) ~
("ownerGroupId" -> bc.ownerGroupId) ~
("ownerGroupName" -> bc.ownerGroupName)
}
case object BatchChangeErrorListSerializer case object BatchChangeErrorListSerializer
extends ValidationSerializer[InvalidBatchChangeResponses] { extends ValidationSerializer[InvalidBatchChangeResponses] {
override def toJson(crl: InvalidBatchChangeResponses): JValue = override def toJson(crl: InvalidBatchChangeResponses): JValue =

View File

@@ -399,65 +399,6 @@ class BatchChangeJsonProtocolSpec
("scheduledTime" -> JNothing) ("scheduledTime" -> JNothing)
} }
} }
"Serializing BatchChangeInfo to JSON" should {
"successfully serialize" in {
val delete = SingleDeleteChange(
Some("zoneId"),
Some("zoneName"),
Some("recordName"),
"fqdn",
A,
Pending,
Some("systemMessage"),
None,
None,
id = "id")
val add = SingleAddChange(
Some("zoneId"),
Some("zoneName"),
Some("recordName"),
"fqdn",
A,
30,
AData("1.1.1.1"),
Pending,
Some("systemMessage"),
None,
None,
id = "id")
val time = DateTime.now
val batchChange = BatchChange(
"someUserId",
"someUserName",
Some("these be comments!"),
time,
List(add, delete),
Some("groupId"),
BatchChangeApprovalStatus.AutoApproved,
None,
None,
None,
"someId"
)
val batchChangeInfo = BatchChangeInfo(batchChange, Some("groupName"))
val result = BatchChangeInfoSerializer.toJson(batchChangeInfo)
result shouldBe ("userId" -> "someUserId") ~
("userName" -> "someUserName") ~
("comments" -> "these be comments!") ~
("createdTimestamp" -> decompose(time)) ~
("changes" -> decompose(List(add, delete))) ~
("status" -> decompose(BatchChangeStatus.PendingProcessing)) ~
("id" -> "someId") ~
("ownerGroupId" -> decompose(Some("groupId"))) ~
("ownerGroupName" -> decompose(Some("groupName")))
}
}
"Serializing BatchChangeErrorList" should { "Serializing BatchChangeErrorList" should {
"serialize changes for valid inputs" in { "serialize changes for valid inputs" in {
val onlyValid = List( val onlyValid = List(