From 32c9f836e53772b90b96d6536da2e37fe8ed369b Mon Sep 17 00:00:00 2001 From: Aravindh-Raju Date: Fri, 15 Nov 2024 11:15:09 +0530 Subject: [PATCH 1/2] fix batch status display --- .../api/domain/batch/BatchChangeService.scala | 2 -- .../domain/batch/BatchChangeServiceSpec.scala | 7 +------ .../api/notifier/email/EmailNotifierSpec.scala | 1 - .../api/notifier/sns/SnsNotifierSpec.scala | 3 +-- .../InMemoryBatchChangeRepository.scala | 5 ----- .../api/route/BatchChangeJsonProtocolSpec.scala | 2 -- .../api/route/BatchChangeRoutingSpec.scala | 1 - .../vinyldns/core/domain/batch/BatchChange.scala | 1 - .../domain/batch/BatchChangeSummarySpec.scala | 1 - ...SqlBatchChangeRepositoryIntegrationSpec.scala | 16 +++++++--------- .../repository/MySqlBatchChangeRepository.scala | 11 ++++++++--- 11 files changed, 17 insertions(+), 33 deletions(-) diff --git a/modules/api/src/main/scala/vinyldns/api/domain/batch/BatchChangeService.scala b/modules/api/src/main/scala/vinyldns/api/domain/batch/BatchChangeService.scala index 0fb74382d..d0a364b5e 100644 --- a/modules/api/src/main/scala/vinyldns/api/domain/batch/BatchChangeService.scala +++ b/modules/api/src/main/scala/vinyldns/api/domain/batch/BatchChangeService.scala @@ -443,7 +443,6 @@ class BatchChangeService( changes, batchChangeInput.ownerGroupId, BatchChangeApprovalStatus.PendingReview, - BatchChangeStatus.PendingReview, scheduledTime = batchChangeInput.scheduledTime ).asRight } @@ -459,7 +458,6 @@ class BatchChangeService( changes, batchChangeInput.ownerGroupId, BatchChangeApprovalStatus.AutoApproved, - BatchChangeStatus.PendingProcessing, scheduledTime = batchChangeInput.scheduledTime ).asRight } diff --git a/modules/api/src/test/scala/vinyldns/api/domain/batch/BatchChangeServiceSpec.scala b/modules/api/src/test/scala/vinyldns/api/domain/batch/BatchChangeServiceSpec.scala index 4615ab718..bf79fd38e 100644 --- a/modules/api/src/test/scala/vinyldns/api/domain/batch/BatchChangeServiceSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/domain/batch/BatchChangeServiceSpec.scala @@ -1041,7 +1041,6 @@ class BatchChangeServiceSpec List(), ownerGroupId = Some(okGroup.id), BatchChangeApprovalStatus.ManuallyApproved, - BatchChangeStatus.PendingProcessing, Some(superUser.id), None, Some(Instant.now.truncatedTo(ChronoUnit.MILLIS)) @@ -2549,7 +2548,6 @@ class BatchChangeServiceSpec Instant.now.truncatedTo(ChronoUnit.MILLIS), List(), approvalStatus = BatchChangeApprovalStatus.PendingReview, - batchStatus = BatchChangeStatus.PendingReview ) batchChangeRepo.save(batchChangeOne) @@ -2560,7 +2558,6 @@ class BatchChangeServiceSpec Instant.ofEpochMilli(Instant.now.truncatedTo(ChronoUnit.MILLIS).toEpochMilli + 1000), List(), approvalStatus = BatchChangeApprovalStatus.AutoApproved, - batchStatus = BatchChangeStatus.PendingProcessing ) batchChangeRepo.save(batchChangeTwo) @@ -2578,8 +2575,7 @@ class BatchChangeServiceSpec result.ignoreAccess shouldBe false result.batchStatus shouldBe Some(BatchChangeStatus.PendingReview) - result.batchChanges.length shouldBe 1 - result.batchChanges(0).status shouldBe batchChangeOne.batchStatus + result.batchChanges.length shouldBe 2 } } @@ -2719,7 +2715,6 @@ class BatchChangeServiceSpec List(singleChangeGood, singleChangeNR), Some(authGrp.id), BatchChangeApprovalStatus.ManuallyApproved, - BatchChangeStatus.PendingProcessing, Some("reviewer_id"), Some("approved"), Some(Instant.now.truncatedTo(ChronoUnit.MILLIS)) diff --git a/modules/api/src/test/scala/vinyldns/api/notifier/email/EmailNotifierSpec.scala b/modules/api/src/test/scala/vinyldns/api/notifier/email/EmailNotifierSpec.scala index 4e992537e..243ac3546 100644 --- a/modules/api/src/test/scala/vinyldns/api/notifier/email/EmailNotifierSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/notifier/email/EmailNotifierSpec.scala @@ -100,7 +100,6 @@ class EmailNotifierSpec changes, None, BatchChangeApprovalStatus.AutoApproved, - BatchChangeStatus.PendingProcessing, None, None, None, diff --git a/modules/api/src/test/scala/vinyldns/api/notifier/sns/SnsNotifierSpec.scala b/modules/api/src/test/scala/vinyldns/api/notifier/sns/SnsNotifierSpec.scala index 9a697b08e..fe04879fa 100644 --- a/modules/api/src/test/scala/vinyldns/api/notifier/sns/SnsNotifierSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/notifier/sns/SnsNotifierSpec.scala @@ -27,7 +27,7 @@ import org.mockito.Matchers._ import org.mockito.Mockito._ import org.mockito.ArgumentCaptor import cats.effect.IO -import _root_.vinyldns.core.domain.batch.{BatchChange, BatchChangeApprovalStatus, BatchChangeStatus, SingleAddChange, SingleChange, SingleChangeStatus, SingleDeleteRRSetChange} +import _root_.vinyldns.core.domain.batch.{BatchChange, BatchChangeApprovalStatus, SingleAddChange, SingleChange, SingleChangeStatus, SingleDeleteRRSetChange} import java.time.Instant import vinyldns.core.domain.record.RecordType import vinyldns.core.domain.record.AData @@ -65,7 +65,6 @@ class SnsNotifierSpec changes, None, BatchChangeApprovalStatus.AutoApproved, - BatchChangeStatus.PendingProcessing, None, None, None, diff --git a/modules/api/src/test/scala/vinyldns/api/repository/InMemoryBatchChangeRepository.scala b/modules/api/src/test/scala/vinyldns/api/repository/InMemoryBatchChangeRepository.scala index 9c1b9041a..3a6ba1be4 100644 --- a/modules/api/src/test/scala/vinyldns/api/repository/InMemoryBatchChangeRepository.scala +++ b/modules/api/src/test/scala/vinyldns/api/repository/InMemoryBatchChangeRepository.scala @@ -39,7 +39,6 @@ class InMemoryBatchChangeRepository extends BatchChangeRepository { ownerGroupId: Option[String], id: String, approvalStatus: BatchChangeApprovalStatus, - batchStatus: BatchChangeStatus, reviewerId: Option[String], reviewComment: Option[String], reviewTimestamp: Option[Instant] @@ -55,7 +54,6 @@ class InMemoryBatchChangeRepository extends BatchChangeRepository { batchChange.ownerGroupId, batchChange.id, batchChange.approvalStatus, - batchChange.batchStatus, batchChange.reviewerId, batchChange.reviewComment, batchChange.reviewTimestamp @@ -90,7 +88,6 @@ class InMemoryBatchChangeRepository extends BatchChangeRepository { singleChangesFromRepo, sc.ownerGroupId, sc.approvalStatus, - sc.batchStatus, sc.reviewerId, sc.reviewComment, sc.reviewTimestamp, @@ -135,7 +132,6 @@ class InMemoryBatchChangeRepository extends BatchChangeRepository { val userBatchChanges = batches.values.toList .filter(b => userId.forall(_ == b.userId)) - .filter(bs => batchStatus.forall(_ == bs.batchStatus)) .filter(bu => userName.forall(_ == bu.userName)) .filter(bdtsi => startInstant.forall(_.isBefore(bdtsi.createdTimestamp))) .filter(bdtei => endInstant.forall(_.isAfter(bdtei.createdTimestamp))) @@ -152,7 +148,6 @@ class InMemoryBatchChangeRepository extends BatchChangeRepository { changes, sc.ownerGroupId, sc.approvalStatus, - sc.batchStatus, sc.reviewerId, sc.reviewComment, sc.reviewTimestamp, diff --git a/modules/api/src/test/scala/vinyldns/api/route/BatchChangeJsonProtocolSpec.scala b/modules/api/src/test/scala/vinyldns/api/route/BatchChangeJsonProtocolSpec.scala index 33ff17c78..53ad40cb0 100644 --- a/modules/api/src/test/scala/vinyldns/api/route/BatchChangeJsonProtocolSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/route/BatchChangeJsonProtocolSpec.scala @@ -482,7 +482,6 @@ class BatchChangeJsonProtocolSpec List(add, delete), None, BatchChangeApprovalStatus.PendingReview, - BatchChangeStatus.PendingReview, None, None, None, @@ -617,7 +616,6 @@ class BatchChangeJsonProtocolSpec List(add, delete), None, BatchChangeApprovalStatus.PendingReview, - BatchChangeStatus.PendingReview, None, None, None, diff --git a/modules/api/src/test/scala/vinyldns/api/route/BatchChangeRoutingSpec.scala b/modules/api/src/test/scala/vinyldns/api/route/BatchChangeRoutingSpec.scala index 762f56274..5c97ce77d 100644 --- a/modules/api/src/test/scala/vinyldns/api/route/BatchChangeRoutingSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/route/BatchChangeRoutingSpec.scala @@ -133,7 +133,6 @@ class BatchChangeRoutingSpec() ), ownerGroupId, approvalStatus, - BatchChangeStatus.PendingProcessing, None, None, None, diff --git a/modules/core/src/main/scala/vinyldns/core/domain/batch/BatchChange.scala b/modules/core/src/main/scala/vinyldns/core/domain/batch/BatchChange.scala index ad68d5f99..43d29c0e2 100644 --- a/modules/core/src/main/scala/vinyldns/core/domain/batch/BatchChange.scala +++ b/modules/core/src/main/scala/vinyldns/core/domain/batch/BatchChange.scala @@ -31,7 +31,6 @@ case class BatchChange( changes: List[SingleChange], ownerGroupId: Option[String] = None, approvalStatus: BatchChangeApprovalStatus, - batchStatus: BatchChangeStatus = BatchChangeStatus.PendingProcessing, reviewerId: Option[String] = None, reviewComment: Option[String] = None, reviewTimestamp: Option[Instant] = None, diff --git a/modules/core/src/test/scala/vinyldns/core/domain/batch/BatchChangeSummarySpec.scala b/modules/core/src/test/scala/vinyldns/core/domain/batch/BatchChangeSummarySpec.scala index b654d338e..cf3d66e10 100644 --- a/modules/core/src/test/scala/vinyldns/core/domain/batch/BatchChangeSummarySpec.scala +++ b/modules/core/src/test/scala/vinyldns/core/domain/batch/BatchChangeSummarySpec.scala @@ -47,7 +47,6 @@ class BatchChangeSummarySpec extends AnyWordSpec with Matchers { List(pendingChange, failedChange, completeChange), Some("groupId"), BatchChangeApprovalStatus.AutoApproved, - BatchChangeStatus.PendingProcessing, None, None, None, diff --git a/modules/mysql/src/it/scala/vinyldns/mysql/repository/MySqlBatchChangeRepositoryIntegrationSpec.scala b/modules/mysql/src/it/scala/vinyldns/mysql/repository/MySqlBatchChangeRepositoryIntegrationSpec.scala index d44dd5436..2e19905ed 100644 --- a/modules/mysql/src/it/scala/vinyldns/mysql/repository/MySqlBatchChangeRepositoryIntegrationSpec.scala +++ b/modules/mysql/src/it/scala/vinyldns/mysql/repository/MySqlBatchChangeRepositoryIntegrationSpec.scala @@ -33,7 +33,7 @@ import vinyldns.core.domain.{SingleChangeError, ZoneDiscoveryError} import vinyldns.mysql.TestMySqlInstance class MySqlBatchChangeRepositoryIntegrationSpec - extends AnyWordSpec + extends AnyWordSpec with BeforeAndAfterAll with BeforeAndAfterEach with Matchers @@ -47,11 +47,11 @@ class MySqlBatchChangeRepositoryIntegrationSpec object TestData { def generateSingleAddChange( - recordType: RecordType, - recordData: RecordData, - status: SingleChangeStatus = Pending, - errors: List[SingleChangeError] = List.empty - ): SingleAddChange = + recordType: RecordType, + recordData: RecordData, + status: SingleChangeStatus = Pending, + errors: List[SingleChangeError] = List.empty + ): SingleAddChange = SingleAddChange( Some(okZone.id), Some(okZone.name), @@ -103,7 +103,6 @@ class MySqlBatchChangeRepositoryIntegrationSpec changes, Some(UUID.randomUUID().toString), BatchChangeApprovalStatus.AutoApproved, - BatchChangeStatus.PendingProcessing, Some(UUID.randomUUID().toString), Some("review comment"), Some(Instant.now.truncatedTo(ChronoUnit.MILLIS).plusSeconds(2)) @@ -456,8 +455,7 @@ class MySqlBatchChangeRepositoryIntegrationSpec } yield (updated, saved) val (retrieved, saved) = f.unsafeRunSync - // Batch Change Status will be updated once saved - retrieved.map(x => x.copy(batchStatus = BatchChangeStatus.Complete)) shouldBe saved + retrieved shouldBe saved } "return no batch when single changes list is empty" in { diff --git a/modules/mysql/src/main/scala/vinyldns/mysql/repository/MySqlBatchChangeRepository.scala b/modules/mysql/src/main/scala/vinyldns/mysql/repository/MySqlBatchChangeRepository.scala index d9cc98f1c..ef5d9fa7b 100644 --- a/modules/mysql/src/main/scala/vinyldns/mysql/repository/MySqlBatchChangeRepository.scala +++ b/modules/mysql/src/main/scala/vinyldns/mysql/repository/MySqlBatchChangeRepository.scala @@ -297,7 +297,6 @@ class MySqlBatchChangeRepository val complete = res.int("complete_count") val cancelled = res.int("cancelled_count") val approvalStatus = toApprovalStatus(res.intOpt("approval_status")) - val batchChangeStatus = toBatchChangeStatus(res.stringOpt("batch_status")) val schedTime = res.timestampOpt("scheduled_time").map(st => st.toInstant) val cancelledTimestamp = @@ -308,7 +307,14 @@ class MySqlBatchChangeRepository Option(res.string("comments")), res.timestamp("created_time").toInstant, pending + failed + complete + cancelled, - batchChangeStatus, + BatchChangeStatus + .calculateBatchStatus( + approvalStatus, + pending > 0, + failed > 0, + complete > 0, + schedTime.isDefined + ), Option(res.string("owner_group_id")), res.string("id"), None, @@ -363,7 +369,6 @@ class MySqlBatchChangeRepository Nil, result.stringOpt("owner_group_id"), toApprovalStatus(result.intOpt("approval_status")), - toBatchChangeStatus(result.stringOpt("batch_status")), result.stringOpt("reviewer_id"), result.stringOpt("review_comment"), result.timestampOpt("review_timestamp").map(toDateTime), From 1993b240af439548c14e8a91817af61e815b099d Mon Sep 17 00:00:00 2001 From: Aravindh-Raju Date: Fri, 15 Nov 2024 11:26:39 +0530 Subject: [PATCH 2/2] fix format --- .../MySqlBatchChangeRepositoryIntegrationSpec.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/mysql/src/it/scala/vinyldns/mysql/repository/MySqlBatchChangeRepositoryIntegrationSpec.scala b/modules/mysql/src/it/scala/vinyldns/mysql/repository/MySqlBatchChangeRepositoryIntegrationSpec.scala index 2e19905ed..0426ab2a5 100644 --- a/modules/mysql/src/it/scala/vinyldns/mysql/repository/MySqlBatchChangeRepositoryIntegrationSpec.scala +++ b/modules/mysql/src/it/scala/vinyldns/mysql/repository/MySqlBatchChangeRepositoryIntegrationSpec.scala @@ -33,7 +33,7 @@ import vinyldns.core.domain.{SingleChangeError, ZoneDiscoveryError} import vinyldns.mysql.TestMySqlInstance class MySqlBatchChangeRepositoryIntegrationSpec - extends AnyWordSpec + extends AnyWordSpec with BeforeAndAfterAll with BeforeAndAfterEach with Matchers @@ -47,11 +47,11 @@ class MySqlBatchChangeRepositoryIntegrationSpec object TestData { def generateSingleAddChange( - recordType: RecordType, - recordData: RecordData, - status: SingleChangeStatus = Pending, - errors: List[SingleChangeError] = List.empty - ): SingleAddChange = + recordType: RecordType, + recordData: RecordData, + status: SingleChangeStatus = Pending, + errors: List[SingleChangeError] = List.empty + ): SingleAddChange = SingleAddChange( Some(okZone.id), Some(okZone.name),