2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-09-04 08:15:18 +00:00

Merge pull request #1167 from Aravindh-Raju/aravindhr/replace-await-with-io

Replace await with IO
This commit is contained in:
Nicholas Spadaccino
2022-11-09 14:04:04 -05:00
committed by GitHub
13 changed files with 412 additions and 590 deletions

View File

@@ -668,25 +668,23 @@ class RecordSetServiceIntegrationSpec
} }
"fail deleting for user not in record owner group in shared zone" in { "fail deleting for user not in record owner group in shared zone" in {
val result = leftResultOf( val result =
testRecordSetService testRecordSetService
.deleteRecordSet(sharedTestRecord.id, sharedTestRecord.zoneId, dummyAuth) .deleteRecordSet(sharedTestRecord.id, sharedTestRecord.zoneId, dummyAuth)
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
"fail deleting for user in record owner group in non-shared zone" in { "fail deleting for user in record owner group in non-shared zone" in {
val result = leftResultOf( val result =
testRecordSetService testRecordSetService
.deleteRecordSet( .deleteRecordSet(
testOwnerGroupRecordInNormalZone.id, testOwnerGroupRecordInNormalZone.id,
testOwnerGroupRecordInNormalZone.zoneId, testOwnerGroupRecordInNormalZone.zoneId,
auth2 auth2
) )
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }

View File

@@ -16,46 +16,14 @@
package vinyldns.api package vinyldns.api
import cats.effect._
import cats.implicits._ import cats.implicits._
import vinyldns.api.domain.batch.BatchChangeInterfaces.ValidatedBatch import vinyldns.api.domain.batch.BatchChangeInterfaces.ValidatedBatch
import vinyldns.api.domain.batch.BatchTransformations.ChangeForValidation import vinyldns.api.domain.batch.BatchTransformations.ChangeForValidation
import scala.concurrent.duration._
import org.scalatest.Assertions._ import org.scalatest.Assertions._
import org.scalatest.matchers.{MatchResult, Matcher} import org.scalatest.matchers.{MatchResult, Matcher}
import scala.concurrent.ExecutionContext
trait CatsHelpers { trait CatsHelpers {
private implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)
private implicit val cs: ContextShift[IO] =
IO.contextShift(scala.concurrent.ExecutionContext.global)
def await[E, T](f: => IO[T], duration: FiniteDuration = 60.seconds): T = {
val i: IO[Either[E, T]] = f.attempt.map {
case Right(ok) => Right(ok.asInstanceOf[T])
case Left(e) => Left(e.asInstanceOf[E])
}
awaitResultOf[E, T](i, duration).toOption.get
}
// Waits for the future to complete, then returns the value as an Either[Throwable, T]
def awaitResultOf[E, T](
f: => IO[Either[E, T]],
duration: FiniteDuration = 60.seconds
): Either[E, T] = {
val timeOut = IO.sleep(duration) *> IO(new RuntimeException("Timed out waiting for result"))
IO.race(timeOut, f).unsafeRunSync().toOption.get
}
// Assumes that the result of the future operation will be successful, this will fail on a left disjunction
def rightResultOf[E, T](f: => IO[Either[E, T]], duration: FiniteDuration = 60.seconds): T =
rightValue(awaitResultOf[E, T](f, duration))
// Assumes that the result of the future operation will fail, this will error on a right disjunction
def leftResultOf[E, T](f: => IO[Either[E, T]], duration: FiniteDuration = 60.seconds): E =
leftValue(awaitResultOf(f, duration))
def leftValue[E, T](t: Either[E, T]): E = t match { def leftValue[E, T](t: Either[E, T]): E = t match {
case Right(x) => fail(s"expected left value, got right: $x") case Right(x) => fail(s"expected left value, got right: $x")

View File

@@ -18,54 +18,15 @@ package vinyldns.api
import cats.data.Validated.{Invalid, Valid} import cats.data.Validated.{Invalid, Valid}
import cats.data.ValidatedNel import cats.data.ValidatedNel
import cats.effect._
import cats.implicits._
import cats.scalatest.ValidatedMatchers import cats.scalatest.ValidatedMatchers
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import org.scalatest.propspec.AnyPropSpec import org.scalatest.propspec.AnyPropSpec
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import scala.reflect.ClassTag import scala.reflect.ClassTag
final case class TimeoutException(message: String) extends Throwable(message) final case class TimeoutException(message: String) extends Throwable(message)
trait ResultHelpers { trait ResultHelpers {
private implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)
private implicit val cs: ContextShift[IO] =
IO.contextShift(scala.concurrent.ExecutionContext.global)
def await[T](f: => IO[_], duration: FiniteDuration = 60.seconds): T =
awaitResultOf[T](f.map(_.asInstanceOf[T]).attempt, duration).toOption.get
// Waits for the future to complete, then returns the value as an Either[Throwable, T]
def awaitResultOf[T](
f: => IO[Either[Throwable, T]],
duration: FiniteDuration = 60.seconds
): Either[Throwable, T] = {
val timeOut = IO.sleep(duration) *> IO(
TimeoutException("Timed out waiting for result").asInstanceOf[Throwable]
)
IO.race(timeOut, f.handleError(e => Left(e))).unsafeRunSync() match {
case Left(e) => Left(e)
case Right(ok) => ok
}
}
// Assumes that the result of the future operation will be successful, this will fail on a left disjunction
def rightResultOf[T](f: => IO[Either[Throwable, T]], duration: FiniteDuration = 60.seconds): T =
awaitResultOf[T](f, duration) match {
case Right(result) => result
case Left(error) => throw error
}
// Assumes that the result of the future operation will fail, this will error on a right disjunction
def leftResultOf[T](
f: => IO[Either[Throwable, T]],
duration: FiniteDuration = 60.seconds
): Throwable = awaitResultOf(f, duration).swap.toOption.get
def leftValue[T](t: Either[Throwable, T]): Throwable = t.swap.toOption.get def leftValue[T](t: Either[Throwable, T]): Throwable = t.swap.toOption.get

View File

@@ -21,17 +21,14 @@ import org.mockito.Mockito._
import org.scalatestplus.mockito.MockitoSugar import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec import org.scalatest.wordspec.AnyWordSpec
import vinyldns.api.ResultHelpers
import vinyldns.core.TestMembershipData._ import vinyldns.core.TestMembershipData._
import vinyldns.core.domain.membership.{MembershipRepository, UserRepository} import vinyldns.core.domain.membership.{MembershipRepository, UserRepository}
import cats.effect._ import cats.effect._
import vinyldns.core.domain.auth.AuthPrincipal
class MembershipAuthPrincipalProviderSpec class MembershipAuthPrincipalProviderSpec
extends AnyWordSpec extends AnyWordSpec
with Matchers with Matchers
with MockitoSugar with MockitoSugar {
with ResultHelpers {
"MembershipAuthPrincipalProvider" should { "MembershipAuthPrincipalProvider" should {
"return the AuthPrincipal" in { "return the AuthPrincipal" in {
@@ -65,7 +62,7 @@ class MembershipAuthPrincipalProviderSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUserByAccessKey(any[String]) .getUserByAccessKey(any[String])
val result = await[Option[AuthPrincipal]](underTest.getAuthPrincipal("None")) val result = underTest.getAuthPrincipal("None").unsafeRunSync()
result shouldBe None result shouldBe None
} }
"return an empty list of groups if there are no matching groups" in { "return an empty list of groups if there are no matching groups" in {
@@ -83,7 +80,7 @@ class MembershipAuthPrincipalProviderSpec
.when(mockMembershipRepo) .when(mockMembershipRepo)
.getGroupsForUser(any[String]) .getGroupsForUser(any[String])
val result = await[Option[AuthPrincipal]](underTest.getAuthPrincipal(accessKey)) val result = underTest.getAuthPrincipal(accessKey).unsafeRunSync()
result.map { authPrincipal => result.map { authPrincipal =>
authPrincipal.signedInUser shouldBe okUser authPrincipal.signedInUser shouldBe okUser
authPrincipal.memberGroupIds shouldBe Seq() authPrincipal.memberGroupIds shouldBe Seq()

View File

@@ -22,7 +22,6 @@ import java.time.Instant
import java.time.temporal.ChronoUnit import java.time.temporal.ChronoUnit
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec import org.scalatest.wordspec.AnyWordSpec
import vinyldns.api.CatsHelpers
import vinyldns.api.domain.batch.BatchTransformations._ import vinyldns.api.domain.batch.BatchTransformations._
import vinyldns.api.domain.batch.BatchTransformations.LogicalChangeType._ import vinyldns.api.domain.batch.BatchTransformations.LogicalChangeType._
import vinyldns.api.engine.TestMessageQueue import vinyldns.api.engine.TestMessageQueue
@@ -37,7 +36,7 @@ import vinyldns.core.domain.record.RecordType.{RecordType, _}
import vinyldns.core.domain.record._ import vinyldns.core.domain.record._
import vinyldns.core.domain.zone.Zone import vinyldns.core.domain.zone.Zone
class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelpers { class BatchChangeConverterSpec extends AnyWordSpec with Matchers {
private val notExistCompletedMessage: String = "This record does not exist." + private val notExistCompletedMessage: String = "This record does not exist." +
"No further action is required." "No further action is required."
@@ -305,7 +304,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
addSingleChangesGood, addSingleChangesGood,
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = rightResultOf( val result =
underTest underTest
.sendBatchForProcessing( .sendBatchForProcessing(
batchChange, batchChange,
@@ -313,8 +312,8 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
ChangeForValidationMap(addChangeForValidationGood.map(_.validNel), existingRecordSets), ChangeForValidationMap(addChangeForValidationGood.map(_.validNel), existingRecordSets),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
val rsChanges = result.recordSetChanges val rsChanges = result.recordSetChanges
// validate recordset changes generated from batch // validate recordset changes generated from batch
@@ -339,7 +338,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
deleteSingleChangesGood, deleteSingleChangesGood,
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = rightResultOf( val result =
underTest underTest
.sendBatchForProcessing( .sendBatchForProcessing(
batchChange, batchChange,
@@ -350,8 +349,8 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
), ),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
val rsChanges = result.recordSetChanges val rsChanges = result.recordSetChanges
// validate recordset change basics generated from batch // validate recordset change basics generated from batch
@@ -388,7 +387,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
updateSingleChangesGood, updateSingleChangesGood,
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = rightResultOf( val result =
underTest underTest
.sendBatchForProcessing( .sendBatchForProcessing(
batchChange, batchChange,
@@ -399,8 +398,8 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
), ),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
val rsChanges = result.recordSetChanges val rsChanges = result.recordSetChanges
// validate recordset changes generated from batch // validate recordset changes generated from batch
@@ -435,7 +434,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
changes, changes,
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = rightResultOf( val result =
underTest underTest
.sendBatchForProcessing( .sendBatchForProcessing(
batchChange, batchChange,
@@ -443,8 +442,8 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
ChangeForValidationMap(changeForValidation.map(_.validNel), existingRecordSets), ChangeForValidationMap(changeForValidation.map(_.validNel), existingRecordSets),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
val rsChanges = result.recordSetChanges val rsChanges = result.recordSetChanges
// validate recordset changes generated from batch // validate recordset changes generated from batch
@@ -471,7 +470,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
// check the batch has been stored in the DB // check the batch has been stored in the DB
val savedBatch: Option[BatchChange] = val savedBatch: Option[BatchChange] =
await(batchChangeRepo.getBatchChange(batchChange.id)) batchChangeRepo.getBatchChange(batchChange.id).unsafeRunSync()
savedBatch shouldBe Some(batchChange) savedBatch shouldBe Some(batchChange)
} }
@@ -486,7 +485,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
List(), List(),
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = rightResultOf( val result =
underTest underTest
.sendBatchForProcessing( .sendBatchForProcessing(
batchChange, batchChange,
@@ -494,8 +493,8 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
ChangeForValidationMap(List(), existingRecordSets), ChangeForValidationMap(List(), existingRecordSets),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
result.batchChange shouldBe batchChange result.batchChange shouldBe batchChange
} }
@@ -510,7 +509,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
singleChangesOneBad, singleChangesOneBad,
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = rightResultOf( val result =
underTest underTest
.sendBatchForProcessing( .sendBatchForProcessing(
batchWithBadChange, batchWithBadChange,
@@ -518,8 +517,8 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
ChangeForValidationMap(changeForValidationOneBad.map(_.validNel), existingRecordSets), ChangeForValidationMap(changeForValidationOneBad.map(_.validNel), existingRecordSets),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
val rsChanges = result.recordSetChanges val rsChanges = result.recordSetChanges
rsChanges.length shouldBe 3 rsChanges.length shouldBe 3
@@ -542,7 +541,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
// check the update has been made in the DB // check the update has been made in the DB
val savedBatch: Option[BatchChange] = val savedBatch: Option[BatchChange] =
await(batchChangeRepo.getBatchChange(batchWithBadChange.id)) batchChangeRepo.getBatchChange(batchWithBadChange.id).unsafeRunSync()
savedBatch shouldBe Some(returnedBatch) savedBatch shouldBe Some(returnedBatch)
} }
@@ -556,7 +555,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
singleChangesOneDelete, singleChangesOneDelete,
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = rightResultOf( val result =
underTest underTest
.sendBatchForProcessing( .sendBatchForProcessing(
batchWithBadChange, batchWithBadChange,
@@ -564,8 +563,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
ChangeForValidationMap(changeForValidationOneDelete.map(_.validNel), existingRecordSets), ChangeForValidationMap(changeForValidationOneDelete.map(_.validNel), existingRecordSets),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
val returnedBatch = result.batchChange val returnedBatch = result.batchChange
@@ -578,7 +576,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
// check the update has been made in the DB // check the update has been made in the DB
val savedBatch: Option[BatchChange] = val savedBatch: Option[BatchChange] =
await(batchChangeRepo.getBatchChange(batchWithBadChange.id)) batchChangeRepo.getBatchChange(batchWithBadChange.id).unsafeRunSync()
savedBatch shouldBe Some(returnedBatch) savedBatch shouldBe Some(returnedBatch)
} }
@@ -592,7 +590,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
singleChangesOneUnsupported, singleChangesOneUnsupported,
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = leftResultOf( val result =
underTest underTest
.sendBatchForProcessing( .sendBatchForProcessing(
batchChangeUnsupported, batchChangeUnsupported,
@@ -603,12 +601,12 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
), ),
None None
) )
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe an[BatchConversionError] result shouldBe an[BatchConversionError]
val notSaved: Option[BatchChange] = val notSaved: Option[BatchChange] =
await(batchChangeRepo.getBatchChange(batchChangeUnsupported.id)) batchChangeRepo.getBatchChange(batchChangeUnsupported.id).unsafeRunSync()
notSaved shouldBe None notSaved shouldBe None
} }
} }

View File

@@ -18,26 +18,25 @@ package vinyldns.api.domain.batch
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec import org.scalatest.wordspec.AnyWordSpec
import vinyldns.api.CatsHelpers
import vinyldns.api.domain.batch.BatchChangeInterfaces._ import vinyldns.api.domain.batch.BatchChangeInterfaces._
import cats.effect._ import cats.effect._
import cats.implicits._ import cats.implicits._
import vinyldns.core.domain.{BatchChangeIsEmpty, ChangeLimitExceeded} import vinyldns.core.domain.{BatchChangeIsEmpty, ChangeLimitExceeded}
class BatchChangeInterfacesSpec extends AnyWordSpec with Matchers with CatsHelpers { class BatchChangeInterfacesSpec extends AnyWordSpec with Matchers {
"toBatchResult" should { "toBatchResult" should {
"work with either success input" in { "work with either success input" in {
val input = "good" val input = "good"
val out = input.asRight[BatchChangeErrorResponse].toBatchResult val out = input.asRight[BatchChangeErrorResponse].toBatchResult
rightResultOf(out.value) shouldBe input out.value.unsafeRunSync().toOption.get shouldBe input
} }
"work with either failure input" in { "work with either failure input" in {
val error = InvalidBatchChangeInput(List(BatchChangeIsEmpty(10))) val error = InvalidBatchChangeInput(List(BatchChangeIsEmpty(10)))
val out = error.asLeft.toBatchResult val out = error.asLeft.toBatchResult
leftResultOf(out.value) shouldBe error out.value.unsafeRunSync().swap.toOption.get shouldBe error
} }
"work with Future success inputs" in { "work with Future success inputs" in {
val input = "good" val input = "good"
@@ -49,42 +48,42 @@ class BatchChangeInterfacesSpec extends AnyWordSpec with Matchers with CatsHelpe
val out2 = futureEitherA.toBatchResult val out2 = futureEitherA.toBatchResult
val out3 = futureEitherANoType.toBatchResult val out3 = futureEitherANoType.toBatchResult
rightResultOf(out1.value) shouldBe input out1.value.unsafeRunSync().toOption.get shouldBe input
rightResultOf(out2.value) shouldBe input out2.value.unsafeRunSync().toOption.get shouldBe input
rightResultOf(out3.value) shouldBe input out3.value.unsafeRunSync().toOption.get shouldBe input
} }
"return a BatchChangeIsEmpty error if no changes are found" in { "return a BatchChangeIsEmpty error if no changes are found" in {
val futureError = val futureError =
IO.pure(InvalidBatchChangeInput(List(BatchChangeIsEmpty(10))).asLeft) IO.pure(InvalidBatchChangeInput(List(BatchChangeIsEmpty(10))).asLeft)
val output = futureError.toBatchResult val output = futureError.toBatchResult
leftResultOf(output.value) shouldBe InvalidBatchChangeInput(List(BatchChangeIsEmpty(10))) output.value.unsafeRunSync().swap.toOption.get shouldBe InvalidBatchChangeInput(List(BatchChangeIsEmpty(10)))
} }
"return a ChangeLimitExceeded error if change limit is exceeded" in { "return a ChangeLimitExceeded error if change limit is exceeded" in {
val futureError = val futureError =
IO.pure(InvalidBatchChangeInput(List(ChangeLimitExceeded(10))).asLeft) IO.pure(InvalidBatchChangeInput(List(ChangeLimitExceeded(10))).asLeft)
val output = futureError.toBatchResult val output = futureError.toBatchResult
leftResultOf(output.value) shouldBe InvalidBatchChangeInput(List(ChangeLimitExceeded(10))) output.value.unsafeRunSync().swap.toOption.get shouldBe InvalidBatchChangeInput(List(ChangeLimitExceeded(10)))
} }
"return a UnknownConversionError if run-time error is encountered during processing" in { "return a UnknownConversionError if run-time error is encountered during processing" in {
val futureError = IO.pure(new RuntimeException("bad!").asLeft) val futureError = IO.pure(new RuntimeException("bad!").asLeft)
val output = futureError.toBatchResult val output = futureError.toBatchResult
leftResultOf(output.value) shouldBe an[UnknownConversionError] output.value.unsafeRunSync().swap.toOption.get shouldBe an[UnknownConversionError]
} }
"return a RuntimeException error if Future fails" in { "return a RuntimeException error if Future fails" in {
val futureError = IO.raiseError(new RuntimeException("bad!")) val futureError = IO.raiseError(new RuntimeException("bad!"))
val output = futureError.toBatchResult val output = futureError.toBatchResult
a[RuntimeException] shouldBe thrownBy(await(output.value)) a[RuntimeException] shouldBe thrownBy(output.value.unsafeRunSync())
} }
} }
"collectSuccesses" should { "collectSuccesses" should {
"return a IO[List] of all if all are successful" in { "return a IO[List] of all if all are successful" in {
val futures = List(1, 2, 3, 4).map(IO.pure) val futures = List(1, 2, 3, 4).map(IO.pure)
val result = await(futures.collectSuccesses) val result = futures.collectSuccesses.unsafeRunSync()
result shouldBe List(1, 2, 3, 4) result shouldBe List(1, 2, 3, 4)
} }
"filter out unsuccessful futures" in { "filter out unsuccessful futures" in {
@@ -96,7 +95,7 @@ class BatchChangeInterfacesSpec extends AnyWordSpec with Matchers with CatsHelpe
IO.pure(3) IO.pure(3)
) )
val result = await(futures.collectSuccesses) val result = futures.collectSuccesses.unsafeRunSync()
result shouldBe List(1, 2, 3) result shouldBe List(1, 2, 3)
} }
"return an empty list of all fail" in { "return an empty list of all fail" in {
@@ -105,7 +104,7 @@ class BatchChangeInterfacesSpec extends AnyWordSpec with Matchers with CatsHelpe
IO.raiseError(new RuntimeException("bad again")) IO.raiseError(new RuntimeException("bad again"))
) )
val result = await(futures.collectSuccesses) val result = futures.collectSuccesses.unsafeRunSync()
result shouldBe List() result shouldBe List()
} }
} }

View File

@@ -27,7 +27,6 @@ import org.scalatest.{BeforeAndAfterEach, EitherValues}
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec import org.scalatest.wordspec.AnyWordSpec
import vinyldns.api.ValidatedBatchMatcherImprovements.containChangeForValidation import vinyldns.api.ValidatedBatchMatcherImprovements.containChangeForValidation
import vinyldns.api._
import vinyldns.api.domain.auth.AuthPrincipalProvider import vinyldns.api.domain.auth.AuthPrincipalProvider
import vinyldns.api.domain.batch.BatchChangeInterfaces.{BatchResult, _} import vinyldns.api.domain.batch.BatchChangeInterfaces.{BatchResult, _}
import vinyldns.api.domain.batch.BatchTransformations._ import vinyldns.api.domain.batch.BatchTransformations._
@@ -59,7 +58,6 @@ class BatchChangeServiceSpec
extends AnyWordSpec extends AnyWordSpec
with Matchers with Matchers
with MockitoSugar with MockitoSugar
with CatsHelpers
with BeforeAndAfterEach with BeforeAndAfterEach
with EitherMatchers with EitherMatchers
with EitherValues with EitherValues
@@ -458,7 +456,7 @@ class BatchChangeServiceSpec
"succeed if all inputs are good" in { "succeed if all inputs are good" in {
val input = BatchChangeInput(None, List(apexAddA, nonApexAddA)) val input = BatchChangeInput(None, List(apexAddA, nonApexAddA))
val result = rightResultOf(underTest.applyBatchChange(input, auth, true).value) val result = underTest.applyBatchChange(input, auth, true).value.unsafeRunSync().toOption.get
result.changes.length shouldBe 2 result.changes.length shouldBe 2
} }
@@ -488,7 +486,7 @@ class BatchChangeServiceSpec
val input = BatchChangeInput(None, List(ptr), Some(authGrp.id)) val input = BatchChangeInput(None, List(ptr), Some(authGrp.id))
val result = rightResultOf(underTest.applyBatchChange(input, auth, false).value) val result = underTest.applyBatchChange(input, auth, false).value.unsafeRunSync().toOption.get
result.changes.length shouldBe 1 result.changes.length shouldBe 1
result.changes.head.zoneId shouldBe Some(ipv6PTR17Zone.id) result.changes.head.zoneId shouldBe Some(ipv6PTR17Zone.id)
@@ -519,7 +517,7 @@ class BatchChangeServiceSpec
val input = BatchChangeInput(None, List(ptr), Some(authGrp.id)) val input = BatchChangeInput(None, List(ptr), Some(authGrp.id))
val result = rightResultOf(underTest.applyBatchChange(input, auth, false).value) val result = underTest.applyBatchChange(input, auth, false).value.unsafeRunSync().toOption.get
result.changes.length shouldBe 1 result.changes.length shouldBe 1
result.changes.head.zoneId shouldBe Some(ipv6PTR16Zone.id) result.changes.head.zoneId shouldBe Some(ipv6PTR16Zone.id)
@@ -527,7 +525,7 @@ class BatchChangeServiceSpec
"fail if conversion cannot process" in { "fail if conversion cannot process" in {
val input = BatchChangeInput(Some("conversionError"), List(apexAddA, nonApexAddA)) val input = BatchChangeInput(Some("conversionError"), List(apexAddA, nonApexAddA))
val result = leftResultOf(underTest.applyBatchChange(input, auth, true).value) val result = underTest.applyBatchChange(input, auth, true).value.unsafeRunSync().swap.toOption.get
result shouldBe an[BatchConversionError] result shouldBe an[BatchConversionError]
} }
@@ -535,7 +533,7 @@ class BatchChangeServiceSpec
"fail with GroupDoesNotExist if owner group ID is provided for a non-existent group" in { "fail with GroupDoesNotExist if owner group ID is provided for a non-existent group" in {
val ownerGroupId = "non-existent-group-id" val ownerGroupId = "non-existent-group-id"
val input = BatchChangeInput(None, List(apexAddA), Some(ownerGroupId)) val input = BatchChangeInput(None, List(apexAddA), Some(ownerGroupId))
val result = leftResultOf(underTest.applyBatchChange(input, auth, true).value) val result = underTest.applyBatchChange(input, auth, true).value.unsafeRunSync().swap.toOption.get
result shouldBe InvalidBatchChangeInput(List(GroupDoesNotExist(ownerGroupId))) result shouldBe InvalidBatchChangeInput(List(GroupDoesNotExist(ownerGroupId)))
} }
@@ -543,7 +541,7 @@ class BatchChangeServiceSpec
"fail with UserDoesNotBelongToOwnerGroup if normal user does not belong to group specified by owner group ID" in { "fail with UserDoesNotBelongToOwnerGroup if normal user does not belong to group specified by owner group ID" in {
val ownerGroupId = "user-is-not-member" val ownerGroupId = "user-is-not-member"
val input = BatchChangeInput(None, List(apexAddA), Some(ownerGroupId)) val input = BatchChangeInput(None, List(apexAddA), Some(ownerGroupId))
val result = leftResultOf(underTest.applyBatchChange(input, notAuth, true).value) val result = underTest.applyBatchChange(input, notAuth, true).value.unsafeRunSync().swap.toOption.get
result shouldBe result shouldBe
InvalidBatchChangeInput( InvalidBatchChangeInput(
@@ -553,7 +551,7 @@ class BatchChangeServiceSpec
"succeed if owner group ID is provided and user is a member of the group" in { "succeed if owner group ID is provided and user is a member of the group" in {
val input = BatchChangeInput(None, List(apexAddA), Some(okGroup.id)) val input = BatchChangeInput(None, List(apexAddA), Some(okGroup.id))
val result = rightResultOf(underTest.applyBatchChange(input, okAuth, true).value) val result = underTest.applyBatchChange(input, okAuth, true).value.unsafeRunSync().toOption.get
result.changes.length shouldBe 1 result.changes.length shouldBe 1
} }
@@ -562,11 +560,9 @@ class BatchChangeServiceSpec
val ownerGroupId = Some("user-is-not-member") val ownerGroupId = Some("user-is-not-member")
val input = BatchChangeInput(None, List(apexAddA), ownerGroupId) val input = BatchChangeInput(None, List(apexAddA), ownerGroupId)
val result = val result =
rightResultOf(
underTest underTest
.applyBatchChange(input, AuthPrincipal(superUser, Seq(baseZone.adminGroupId)), true) .applyBatchChange(input, AuthPrincipal(superUser, Seq(baseZone.adminGroupId)), true)
.value .value.unsafeRunSync().toOption.get
)
result.changes.length shouldBe 1 result.changes.length shouldBe 1
} }
@@ -580,7 +576,7 @@ class BatchChangeServiceSpec
AddChangeInput("non-apex.test.com.", RecordType.TXT, None, TXTData("hello")) AddChangeInput("non-apex.test.com.", RecordType.TXT, None, TXTData("hello"))
val input = BatchChangeInput(None, List(noTtl, withTtl, noTtlDel, noTtlUpdate)) val input = BatchChangeInput(None, List(noTtl, withTtl, noTtlDel, noTtlUpdate))
val result = rightResultOf(underTest.applyBatchChange(input, auth, true).value) val result = underTest.applyBatchChange(input, auth, true).value.unsafeRunSync().toOption.get
result.changes.length shouldBe 4 result.changes.length shouldBe 4
result result
@@ -608,15 +604,13 @@ class BatchChangeServiceSpec
doReturn(IO.unit).when(mockNotifier).notify(any[Notification[_]]) doReturn(IO.unit).when(mockNotifier).notify(any[Notification[_]])
val result = val result =
rightResultOf(
underTest underTest
.rejectBatchChange( .rejectBatchChange(
batchChange.id, batchChange.id,
supportUserAuth, supportUserAuth,
RejectBatchChangeInput(Some("review comment")) RejectBatchChangeInput(Some("review comment"))
) )
.value .value.unsafeRunSync().toOption.get
)
result.status shouldBe BatchChangeStatus.Rejected result.status shouldBe BatchChangeStatus.Rejected
result.approvalStatus shouldBe BatchChangeApprovalStatus.ManuallyRejected result.approvalStatus shouldBe BatchChangeApprovalStatus.ManuallyRejected
@@ -642,11 +636,9 @@ class BatchChangeServiceSpec
val rejectAuth = AuthPrincipal(supportUser.copy(isTest = true), List()) val rejectAuth = AuthPrincipal(supportUser.copy(isTest = true), List())
val result = val result =
rightResultOf(
underTestManualEnabled underTestManualEnabled
.rejectBatchChange(batchChange.id, rejectAuth, RejectBatchChangeInput(Some("bad"))) .rejectBatchChange(batchChange.id, rejectAuth, RejectBatchChangeInput(Some("bad")))
.value .value.unsafeRunSync().toOption.get
)
result.status shouldBe BatchChangeStatus.Rejected result.status shouldBe BatchChangeStatus.Rejected
} }
@@ -664,11 +656,9 @@ class BatchChangeServiceSpec
val rejectAuth = AuthPrincipal(supportUser.copy(isTest = true), List()) val rejectAuth = AuthPrincipal(supportUser.copy(isTest = true), List())
val result = val result =
leftResultOf(
underTestManualEnabled underTestManualEnabled
.rejectBatchChange(batchChange.id, rejectAuth, RejectBatchChangeInput(Some("bad"))) .rejectBatchChange(batchChange.id, rejectAuth, RejectBatchChangeInput(Some("bad")))
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe UserNotAuthorizedError(batchChange.id) result shouldBe UserNotAuthorizedError(batchChange.id)
} }
@@ -685,11 +675,9 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf(
underTest underTest
.rejectBatchChange(batchChange.id, supportUserAuth, RejectBatchChangeInput()) .rejectBatchChange(batchChange.id, supportUserAuth, RejectBatchChangeInput())
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe BatchChangeNotPendingReview(batchChange.id) result shouldBe BatchChangeNotPendingReview(batchChange.id)
} }
@@ -707,9 +695,7 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf( underTest.rejectBatchChange(batchChange.id, auth, RejectBatchChangeInput()).value.unsafeRunSync().swap.toOption.get
underTest.rejectBatchChange(batchChange.id, auth, RejectBatchChangeInput()).value
)
result shouldBe UserNotAuthorizedError(batchChange.id) result shouldBe UserNotAuthorizedError(batchChange.id)
} }
@@ -727,9 +713,7 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf( underTest.rejectBatchChange(batchChange.id, auth, RejectBatchChangeInput()).value.unsafeRunSync().swap.toOption.get
underTest.rejectBatchChange(batchChange.id, auth, RejectBatchChangeInput()).value
)
result shouldBe UserNotAuthorizedError(batchChange.id) result shouldBe UserNotAuthorizedError(batchChange.id)
} }
@@ -748,17 +732,14 @@ class BatchChangeServiceSpec
"succeed if the batchChange is PendingReview and reviewer is authorized" in { "succeed if the batchChange is PendingReview and reviewer is authorized" in {
batchChangeRepo.save(batchChangeNeedsApproval) batchChangeRepo.save(batchChangeNeedsApproval)
val result = { val result =
rightResultOf(
underTestManualEnabled underTestManualEnabled
.approveBatchChange( .approveBatchChange(
batchChangeNeedsApproval.id, batchChangeNeedsApproval.id,
supportUserAuth, supportUserAuth,
ApproveBatchChangeInput(Some("reviewed!")) ApproveBatchChangeInput(Some("reviewed!"))
) )
.value .value.unsafeRunSync().toOption.get
)
}
result.userId shouldBe batchChangeNeedsApproval.userId result.userId shouldBe batchChangeNeedsApproval.userId
result.userName shouldBe batchChangeNeedsApproval.userName result.userName shouldBe batchChangeNeedsApproval.userName
@@ -778,15 +759,13 @@ class BatchChangeServiceSpec
val auth = AuthPrincipal(supportUser.copy(isTest = true), List()) val auth = AuthPrincipal(supportUser.copy(isTest = true), List())
val result = val result =
leftResultOf(
underTestManualEnabled underTestManualEnabled
.approveBatchChange( .approveBatchChange(
batchChangeNeedsApproval.id, batchChangeNeedsApproval.id,
auth, auth,
ApproveBatchChangeInput(Some("reviewed!")) ApproveBatchChangeInput(Some("reviewed!"))
) )
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe UserNotAuthorizedError(batchChangeNeedsApproval.id) result shouldBe UserNotAuthorizedError(batchChangeNeedsApproval.id)
} }
@@ -796,11 +775,9 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf(
underTest underTest
.approveBatchChange(batchChange.id, supportUserAuth, ApproveBatchChangeInput()) .approveBatchChange(batchChange.id, supportUserAuth, ApproveBatchChangeInput())
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe BatchChangeNotPendingReview(batchChange.id) result shouldBe BatchChangeNotPendingReview(batchChange.id)
} }
@@ -809,11 +786,9 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChangeNeedsApproval) batchChangeRepo.save(batchChangeNeedsApproval)
val result = val result =
leftResultOf(
underTest underTest
.approveBatchChange(batchChangeNeedsApproval.id, auth, ApproveBatchChangeInput()) .approveBatchChange(batchChangeNeedsApproval.id, auth, ApproveBatchChangeInput())
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe UserNotAuthorizedError(batchChangeNeedsApproval.id) result shouldBe UserNotAuthorizedError(batchChangeNeedsApproval.id)
} }
@@ -824,9 +799,7 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf( underTest.approveBatchChange(batchChange.id, auth, ApproveBatchChangeInput()).value.unsafeRunSync().swap.toOption.get
underTest.approveBatchChange(batchChange.id, auth, ApproveBatchChangeInput()).value
)
result shouldBe UserNotAuthorizedError(batchChange.id) result shouldBe UserNotAuthorizedError(batchChange.id)
} }
@@ -844,11 +817,9 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf(
underTest underTest
.approveBatchChange(batchChange.id, superUserAuth, ApproveBatchChangeInput()) .approveBatchChange(batchChange.id, superUserAuth, ApproveBatchChangeInput())
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe BatchRequesterNotFound("someOtherUserId", "someUn") result shouldBe BatchRequesterNotFound("someOtherUserId", "someUn")
} }
@@ -868,11 +839,9 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
rightResultOf(
underTest underTest
.cancelBatchChange(batchChange.id, auth) .cancelBatchChange(batchChange.id, auth)
.value .value.unsafeRunSync().toOption.get
)
result.status shouldBe BatchChangeStatus.Cancelled result.status shouldBe BatchChangeStatus.Cancelled
result.approvalStatus shouldBe BatchChangeApprovalStatus.Cancelled result.approvalStatus shouldBe BatchChangeApprovalStatus.Cancelled
@@ -893,7 +862,7 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf(underTest.cancelBatchChange(batchChange.id, supportUserAuth).value) underTest.cancelBatchChange(batchChange.id, supportUserAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe UserNotAuthorizedError(batchChange.id) result shouldBe UserNotAuthorizedError(batchChange.id)
} }
@@ -911,11 +880,9 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf(
underTest underTest
.cancelBatchChange(batchChange.id, auth) .cancelBatchChange(batchChange.id, auth)
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe BatchChangeNotPendingReview(batchChange.id) result shouldBe BatchChangeNotPendingReview(batchChange.id)
} }
@@ -933,11 +900,9 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = val result =
leftResultOf(
underTest underTest
.cancelBatchChange(batchChange.id, supportUserAuth) .cancelBatchChange(batchChange.id, supportUserAuth)
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe BatchChangeNotPendingReview(batchChange.id) result shouldBe BatchChangeNotPendingReview(batchChange.id)
} }
@@ -956,13 +921,13 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = rightResultOf(underTest.getBatchChange(batchChange.id, auth).value) val result = underTest.getBatchChange(batchChange.id, auth).value.unsafeRunSync().toOption.get
result shouldBe BatchChangeInfo(batchChange) result shouldBe BatchChangeInfo(batchChange)
} }
"Fail if batchChange id does not exist" in { "Fail if batchChange id does not exist" in {
val result = leftResultOf(underTest.getBatchChange("badId", auth).value) val result = underTest.getBatchChange("badId", auth).value.unsafeRunSync().swap.toOption.get
result shouldBe BatchChangeNotFound("badId") result shouldBe BatchChangeNotFound("badId")
} }
@@ -978,7 +943,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = leftResultOf(underTest.getBatchChange(batchChange.id, notAuth).value) val result = underTest.getBatchChange(batchChange.id, notAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe UserNotAuthorizedError(batchChange.id) result shouldBe UserNotAuthorizedError(batchChange.id)
} }
@@ -996,7 +961,7 @@ class BatchChangeServiceSpec
val authSuper = notAuth.copy(signedInUser = notAuth.signedInUser.copy(isSuper = true)) val authSuper = notAuth.copy(signedInUser = notAuth.signedInUser.copy(isSuper = true))
val result = rightResultOf(underTest.getBatchChange(batchChange.id, authSuper).value) val result = underTest.getBatchChange(batchChange.id, authSuper).value.unsafeRunSync().toOption.get
result shouldBe BatchChangeInfo(batchChange) result shouldBe BatchChangeInfo(batchChange)
} }
@@ -1014,7 +979,7 @@ class BatchChangeServiceSpec
val authSuper = notAuth.copy(signedInUser = notAuth.signedInUser.copy(isSupport = true)) val authSuper = notAuth.copy(signedInUser = notAuth.signedInUser.copy(isSupport = true))
val result = rightResultOf(underTest.getBatchChange(batchChange.id, authSuper).value) val result = underTest.getBatchChange(batchChange.id, authSuper).value.unsafeRunSync().toOption.get
result shouldBe BatchChangeInfo(batchChange) result shouldBe BatchChangeInfo(batchChange)
} }
@@ -1032,7 +997,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = rightResultOf(underTest.getBatchChange(batchChange.id, auth).value) val result = underTest.getBatchChange(batchChange.id, auth).value.unsafeRunSync().toOption.get
result shouldBe BatchChangeInfo(batchChange, Some(okGroup.name)) result shouldBe BatchChangeInfo(batchChange, Some(okGroup.name))
} }
@@ -1049,7 +1014,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = rightResultOf(underTest.getBatchChange(batchChange.id, auth).value) val result = underTest.getBatchChange(batchChange.id, auth).value.unsafeRunSync().toOption.get
result shouldBe BatchChangeInfo(batchChange) result shouldBe BatchChangeInfo(batchChange)
} }
@@ -1069,7 +1034,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = rightResultOf(underTest.getBatchChange(batchChange.id, auth).value) val result = underTest.getBatchChange(batchChange.id, auth).value.unsafeRunSync().toOption.get
result shouldBe BatchChangeInfo(batchChange, Some(okGroup.name), Some(superUser.userName)) result shouldBe BatchChangeInfo(batchChange, Some(okGroup.name), Some(superUser.userName))
} }
} }
@@ -1088,7 +1053,7 @@ class BatchChangeServiceSpec
error error
) )
val zoneMap = ExistingZones(Set(apexZone, baseZone, ptrZone, delegatedPTRZone, ipv6PTRZone)) val zoneMap = ExistingZones(Set(apexZone, baseZone, ptrZone, delegatedPTRZone, ipv6PTRZone))
val result = await(underTest.getExistingRecordSets(in, zoneMap)) val result = underTest.getExistingRecordSets(in, zoneMap).unsafeRunSync()
val expected = val expected =
List(existingApex, existingNonApex, existingPtr, existingPtrDelegated, existingPtrV6) List(existingApex, existingNonApex, existingPtr, existingPtrDelegated, existingPtrV6)
@@ -1105,7 +1070,7 @@ class BatchChangeServiceSpec
error error
) )
val zoneMap = ExistingZones(Set(apexZone, baseZone, ptrZone, ipv6PTRZone)) val zoneMap = ExistingZones(Set(apexZone, baseZone, ptrZone, ipv6PTRZone))
val result = await(underTest.getExistingRecordSets(in, zoneMap)) val result = underTest.getExistingRecordSets(in, zoneMap).unsafeRunSync()
val expected = val expected =
List(existingApex, existingNonApex, existingPtr, existingPtrV6) List(existingApex, existingNonApex, existingPtr, existingPtrV6)
@@ -1115,7 +1080,7 @@ class BatchChangeServiceSpec
"not fail if gets all lefts" in { "not fail if gets all lefts" in {
val errors = List(error) val errors = List(error)
val zoneMap = ExistingZones(Set(apexZone, baseZone, ptrZone, delegatedPTRZone, ipv6PTRZone)) val zoneMap = ExistingZones(Set(apexZone, baseZone, ptrZone, delegatedPTRZone, ipv6PTRZone))
val result = await(underTest.getExistingRecordSets(errors, zoneMap)) val result = underTest.getExistingRecordSets(errors, zoneMap).unsafeRunSync()
result.recordSets.length shouldBe 0 result.recordSets.length shouldBe 0
} }
@@ -1124,42 +1089,42 @@ class BatchChangeServiceSpec
"getZonesForRequest" should { "getZonesForRequest" should {
"return names for the apex and base zones if they both exist" in { "return names for the apex and base zones if they both exist" in {
val underTestBaseApexZoneList: ExistingZones = val underTestBaseApexZoneList: ExistingZones =
await(underTest.getZonesForRequest(List(apexAddA.validNel))) underTest.getZonesForRequest(List(apexAddA.validNel)).unsafeRunSync()
(underTestBaseApexZoneList.zones should contain).allOf(apexZone, baseZone) (underTestBaseApexZoneList.zones should contain).allOf(apexZone, baseZone)
} }
"return only the apex zone if only the apex zone exists or A or AAAA records" in { "return only the apex zone if only the apex zone exists or A or AAAA records" in {
val underTestOnlyApexZoneList: ExistingZones = val underTestOnlyApexZoneList: ExistingZones =
await(underTest.getZonesForRequest(List(onlyApexAddA.validNel))) underTest.getZonesForRequest(List(onlyApexAddA.validNel)).unsafeRunSync()
(underTestOnlyApexZoneList.zones should contain).only(onlyApexZone) (underTestOnlyApexZoneList.zones should contain).only(onlyApexZone)
} }
"return only the base zone if only the base zone exists" in { "return only the base zone if only the base zone exists" in {
val underTestOnlyBaseZoneList: ExistingZones = val underTestOnlyBaseZoneList: ExistingZones =
await(underTest.getZonesForRequest(List(onlyBaseAddAAAA.validNel))) underTest.getZonesForRequest(List(onlyBaseAddAAAA.validNel)).unsafeRunSync()
(underTestOnlyBaseZoneList.zones should contain).only(onlyBaseZone) (underTestOnlyBaseZoneList.zones should contain).only(onlyBaseZone)
} }
"return no zones if neither the apex nor base zone exist" in { "return no zones if neither the apex nor base zone exist" in {
val underTestOnlyNoZonesList: ExistingZones = val underTestOnlyNoZonesList: ExistingZones =
await(underTest.getZonesForRequest(List(noZoneAddA.validNel))) underTest.getZonesForRequest(List(noZoneAddA.validNel)).unsafeRunSync()
underTestOnlyNoZonesList.zones shouldBe Set() underTestOnlyNoZonesList.zones shouldBe Set()
} }
"return all possible zones for a dotted host" in { "return all possible zones for a dotted host" in {
val underTestZonesList: ExistingZones = val underTestZonesList: ExistingZones =
await(underTest.getZonesForRequest(List(dottedAddA.validNel))) underTest.getZonesForRequest(List(dottedAddA.validNel)).unsafeRunSync()
(underTestZonesList.zones should contain).allOf(apexZone, baseZone) (underTestZonesList.zones should contain).allOf(apexZone, baseZone)
} }
"return all possible zones given an IPv4 PTR" in { "return all possible zones given an IPv4 PTR" in {
val underTestPTRZonesList: ExistingZones = val underTestPTRZonesList: ExistingZones =
await(underTest.getZonesForRequest(List(ptrAdd.validNel))) underTest.getZonesForRequest(List(ptrAdd.validNel)).unsafeRunSync()
(underTestPTRZonesList.zones should contain).allOf(ptrZone, delegatedPTRZone) (underTestPTRZonesList.zones should contain).allOf(ptrZone, delegatedPTRZone)
} }
@@ -1199,7 +1164,7 @@ class BatchChangeServiceSpec
) )
val ptr = AddChangeInput(ip, RecordType.PTR, ttl, PTRData(Fqdn("ptr."))).validNel val ptr = AddChangeInput(ip, RecordType.PTR, ttl, PTRData(Fqdn("ptr."))).validNel
val underTestPTRZonesList: ExistingZones = await(underTest.getZonesForRequest(List(ptr))) val underTestPTRZonesList: ExistingZones = underTest.getZonesForRequest(List(ptr)).unsafeRunSync()
val zoneNames = underTestPTRZonesList.zones.map(_.name) val zoneNames = underTestPTRZonesList.zones.map(_.name)
zoneNames should contain theSameElementsAs possibleZones zoneNames should contain theSameElementsAs possibleZones
@@ -1225,7 +1190,7 @@ class BatchChangeServiceSpec
val ip = "2001:0db8:0000:0000:0000:ff00:0042:8329" val ip = "2001:0db8:0000:0000:0000:ff00:0042:8329"
val ptr = AddChangeInput(ip, RecordType.PTR, ttl, PTRData(Fqdn("ptr."))).validNel val ptr = AddChangeInput(ip, RecordType.PTR, ttl, PTRData(Fqdn("ptr."))).validNel
val underTestPTRZonesList: ExistingZones = await(underTest.getZonesForRequest(List(ptr))) val underTestPTRZonesList: ExistingZones = underTest.getZonesForRequest(List(ptr)).unsafeRunSync()
val zoneNames = underTestPTRZonesList.zones.map(_.name) val zoneNames = underTestPTRZonesList.zones.map(_.name)
zoneNames shouldBe Set("0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.") zoneNames shouldBe Set("0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.")
@@ -1274,7 +1239,7 @@ class BatchChangeServiceSpec
AddChangeInput(v6Name, RecordType.PTR, ttl, PTRData(Fqdn("ptr."))).validNel AddChangeInput(v6Name, RecordType.PTR, ttl, PTRData(Fqdn("ptr."))).validNel
} }
val underTestPTRZonesList: ExistingZones = await(underTest.getZonesForRequest(ptrs)) val underTestPTRZonesList: ExistingZones = underTest.getZonesForRequest(ptrs).unsafeRunSync()
val zoneNames = underTestPTRZonesList.zones.map(_.name) val zoneNames = underTestPTRZonesList.zones.map(_.name)
zoneNames should contain theSameElementsAs (possibleZones1 ++ possibleZones2) zoneNames should contain theSameElementsAs (possibleZones1 ++ possibleZones2)
@@ -1282,7 +1247,7 @@ class BatchChangeServiceSpec
"return a set of distinct zones, given duplicates" in { "return a set of distinct zones, given duplicates" in {
val underTestDistinctZonesList: ExistingZones = val underTestDistinctZonesList: ExistingZones =
await(underTest.getZonesForRequest(List(cnameReverseAdd.validNel, ptrAdd.validNel))) underTest.getZonesForRequest(List(cnameReverseAdd.validNel, ptrAdd.validNel)).unsafeRunSync()
underTestDistinctZonesList.zones.count(_.id == "nonDelegatedPTR") shouldBe 1 underTestDistinctZonesList.zones.count(_.id == "nonDelegatedPTR") shouldBe 1
} }
@@ -2033,7 +1998,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = rightResultOf(underTest.listBatchChangeSummaries(auth, maxItems = 100).value) val result = underTest.listBatchChangeSummaries(auth, maxItems = 100).value.unsafeRunSync().toOption.get
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe None result.nextId shouldBe None
@@ -2072,7 +2037,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChangeTwo) batchChangeRepo.save(batchChangeTwo)
val result = rightResultOf(underTest.listBatchChangeSummaries(auth, maxItems = 100).value) val result = underTest.listBatchChangeSummaries(auth, maxItems = 100).value.unsafeRunSync().toOption.get
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe None result.nextId shouldBe None
@@ -2106,7 +2071,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChangeTwo) batchChangeRepo.save(batchChangeTwo)
val result = rightResultOf(underTest.listBatchChangeSummaries(auth, maxItems = 1).value) val result = underTest.listBatchChangeSummaries(auth, maxItems = 1).value.unsafeRunSync().toOption.get
result.maxItems shouldBe 1 result.maxItems shouldBe 1
result.nextId shouldBe Some(1) result.nextId shouldBe Some(1)
@@ -2139,14 +2104,13 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChangeTwo) batchChangeRepo.save(batchChangeTwo)
val result = rightResultOf( val result =
underTest underTest
.listBatchChangeSummaries( .listBatchChangeSummaries(
auth, auth,
approvalStatus = Some(BatchChangeApprovalStatus.PendingReview) approvalStatus = Some(BatchChangeApprovalStatus.PendingReview)
) )
.value .value.unsafeRunSync().toOption.get
)
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe None result.nextId shouldBe None
@@ -2181,7 +2145,7 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChangeTwo) batchChangeRepo.save(batchChangeTwo)
val result = val result =
rightResultOf(underTest.listBatchChangeSummaries(auth, startFrom = Some(1)).value) underTest.listBatchChangeSummaries(auth, startFrom = Some(1)).value.unsafeRunSync().toOption.get
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe None result.nextId shouldBe None
@@ -2215,7 +2179,7 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChangeUserTwo) batchChangeRepo.save(batchChangeUserTwo)
val result = val result =
rightResultOf(underTest.listBatchChangeSummaries(auth, maxItems = 100).value).batchChanges underTest.listBatchChangeSummaries(auth, maxItems = 100).value.unsafeRunSync().toOption.get.batchChanges
result.length shouldBe 1 result.length shouldBe 1
result(0).createdTimestamp shouldBe batchChangeUserOne.createdTimestamp result(0).createdTimestamp shouldBe batchChangeUserOne.createdTimestamp
@@ -2244,7 +2208,7 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChangeUserTwo) batchChangeRepo.save(batchChangeUserTwo)
val result = val result =
rightResultOf(underTest.listBatchChangeSummaries(auth, ignoreAccess = true).value).batchChanges underTest.listBatchChangeSummaries(auth, ignoreAccess = true).value.unsafeRunSync().toOption.get.batchChanges
result.length shouldBe 1 result.length shouldBe 1
result(0).createdTimestamp shouldBe batchChangeUserOne.createdTimestamp result(0).createdTimestamp shouldBe batchChangeUserOne.createdTimestamp
@@ -2273,7 +2237,7 @@ class BatchChangeServiceSpec
batchChangeRepo.save(batchChangeUserTwo) batchChangeRepo.save(batchChangeUserTwo)
val result = val result =
rightResultOf(underTest.listBatchChangeSummaries(superUserAuth, ignoreAccess = true).value) underTest.listBatchChangeSummaries(superUserAuth, ignoreAccess = true).value.unsafeRunSync().toOption.get
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe None result.nextId shouldBe None
@@ -2287,7 +2251,7 @@ class BatchChangeServiceSpec
"return an empty list of batchChangeSummaries if none exist" in { "return an empty list of batchChangeSummaries if none exist" in {
val result = val result =
rightResultOf(underTest.listBatchChangeSummaries(auth, maxItems = 100).value).batchChanges underTest.listBatchChangeSummaries(auth, maxItems = 100).value.unsafeRunSync().toOption.get.batchChanges
result.length shouldBe 0 result.length shouldBe 0
} }
@@ -2305,7 +2269,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = rightResultOf(underTest.listBatchChangeSummaries(auth, maxItems = 100).value) val result = underTest.listBatchChangeSummaries(auth, maxItems = 100).value.unsafeRunSync().toOption.get
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe None result.nextId shouldBe None
@@ -2330,7 +2294,7 @@ class BatchChangeServiceSpec
) )
batchChangeRepo.save(batchChange) batchChangeRepo.save(batchChange)
val result = rightResultOf(underTest.listBatchChangeSummaries(auth, maxItems = 100).value) val result = underTest.listBatchChangeSummaries(auth, maxItems = 100).value.unsafeRunSync().toOption.get
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe None result.nextId shouldBe None
@@ -2345,29 +2309,29 @@ class BatchChangeServiceSpec
"getOwnerGroup" should { "getOwnerGroup" should {
"return None if owner group ID is None" in { "return None if owner group ID is None" in {
rightResultOf(underTest.getOwnerGroup(None).value) shouldBe None underTest.getOwnerGroup(None).value.unsafeRunSync().toOption.get shouldBe None
} }
"return None if group does not exist for owner group ID" in { "return None if group does not exist for owner group ID" in {
rightResultOf(underTest.getOwnerGroup(Some("non-existent-group-id")).value) shouldBe None underTest.getOwnerGroup(Some("non-existent-group-id")).value.unsafeRunSync().toOption.get shouldBe None
} }
"return the group if the group exists for the owner group ID" in { "return the group if the group exists for the owner group ID" in {
rightResultOf(underTest.getOwnerGroup(Some(okGroup.id)).value) shouldBe Some(okGroup) underTest.getOwnerGroup(Some(okGroup.id)).value.unsafeRunSync().toOption.get shouldBe Some(okGroup)
} }
} }
"getReviewer" should { "getReviewer" should {
"return None if reviewer ID is None" in { "return None if reviewer ID is None" in {
rightResultOf(underTest.getReviewer(None).value) shouldBe None underTest.getReviewer(None).value.unsafeRunSync().toOption.get shouldBe None
} }
"return None if reviewer does not exist for the given reviewer ID" in { "return None if reviewer does not exist for the given reviewer ID" in {
rightResultOf(underTest.getReviewer(Some("non-existent-user-id")).value) shouldBe None underTest.getReviewer(Some("non-existent-user-id")).value.unsafeRunSync().toOption.get shouldBe None
} }
"return the reviewer if the reviewer exists for the given reviewer ID" in { "return the reviewer if the reviewer exists for the given reviewer ID" in {
rightResultOf(underTest.getReviewer(Some(superUser.id)).value) shouldBe Some(superUser) underTest.getReviewer(Some(superUser.id)).value.unsafeRunSync().toOption.get shouldBe Some(superUser)
} }
} }
@@ -2383,7 +2347,7 @@ class BatchChangeServiceSpec
approvalStatus = BatchChangeApprovalStatus.AutoApproved approvalStatus = BatchChangeApprovalStatus.AutoApproved
) )
val result = rightResultOf( val result =
underTestManualEnabled underTestManualEnabled
.convertOrSave( .convertOrSave(
batchChange, batchChange,
@@ -2391,8 +2355,8 @@ class BatchChangeServiceSpec
ChangeForValidationMap(List(), ExistingRecordSets(List())), ChangeForValidationMap(List(), ExistingRecordSets(List())),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
result.reviewComment shouldBe Some("batchSentToConverter") result.reviewComment shouldBe Some("batchSentToConverter")
} }
"not send to the converter, save the change if PendingReview and MA enabled" in { "not send to the converter, save the change if PendingReview and MA enabled" in {
@@ -2406,7 +2370,7 @@ class BatchChangeServiceSpec
approvalStatus = BatchChangeApprovalStatus.PendingReview approvalStatus = BatchChangeApprovalStatus.PendingReview
) )
val result = rightResultOf( val result =
underTestManualEnabled underTestManualEnabled
.convertOrSave( .convertOrSave(
batchChange, batchChange,
@@ -2414,8 +2378,7 @@ class BatchChangeServiceSpec
ChangeForValidationMap(List(), ExistingRecordSets(List())), ChangeForValidationMap(List(), ExistingRecordSets(List())),
None None
) )
.value .value.unsafeRunSync().toOption.get
)
// not sent to converter // not sent to converter
result.reviewComment shouldBe None result.reviewComment shouldBe None
@@ -2433,7 +2396,7 @@ class BatchChangeServiceSpec
approvalStatus = BatchChangeApprovalStatus.PendingReview approvalStatus = BatchChangeApprovalStatus.PendingReview
) )
val result = leftResultOf( val result =
underTest underTest
.convertOrSave( .convertOrSave(
batchChange, batchChange,
@@ -2441,8 +2404,7 @@ class BatchChangeServiceSpec
ChangeForValidationMap(List(), ExistingRecordSets(List())), ChangeForValidationMap(List(), ExistingRecordSets(List())),
None None
) )
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe an[UnknownConversionError] result shouldBe an[UnknownConversionError]
} }
@@ -2457,7 +2419,7 @@ class BatchChangeServiceSpec
approvalStatus = BatchChangeApprovalStatus.ManuallyApproved approvalStatus = BatchChangeApprovalStatus.ManuallyApproved
) )
val result = leftResultOf( val result =
underTest underTest
.convertOrSave( .convertOrSave(
batchChange, batchChange,
@@ -2465,8 +2427,8 @@ class BatchChangeServiceSpec
ChangeForValidationMap(List(), ExistingRecordSets(List())), ChangeForValidationMap(List(), ExistingRecordSets(List())),
None None
) )
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe an[UnknownConversionError] result shouldBe an[UnknownConversionError]
} }
} }
@@ -2530,7 +2492,7 @@ class BatchChangeServiceSpec
"combine gets for each valid record" in { "combine gets for each valid record" in {
val in = List(apexAddForVal.validNel, error) val in = List(apexAddForVal.validNel, error)
val result = rightResultOf(underTest.getGroupIdsFromUnauthorizedErrors(in).value) val result = underTest.getGroupIdsFromUnauthorizedErrors(in).value.unsafeRunSync().toOption.get
result shouldBe Set(okGroup) result shouldBe Set(okGroup)
} }

View File

@@ -25,7 +25,6 @@ import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.BeforeAndAfterEach import org.scalatest.BeforeAndAfterEach
import vinyldns.api.Interfaces._ import vinyldns.api.Interfaces._
import vinyldns.api.ResultHelpers
import vinyldns.core.domain.auth.AuthPrincipal import vinyldns.core.domain.auth.AuthPrincipal
import vinyldns.core.domain.zone.ZoneRepository import vinyldns.core.domain.zone.ZoneRepository
import cats.effect._ import cats.effect._
@@ -41,7 +40,6 @@ class MembershipServiceSpec
with Matchers with Matchers
with MockitoSugar with MockitoSugar
with BeforeAndAfterEach with BeforeAndAfterEach
with ResultHelpers
with EitherMatchers { with EitherMatchers {
private val mockGroupRepo = mock[GroupRepository] private val mockGroupRepo = mock[GroupRepository]
@@ -123,7 +121,7 @@ class MembershipServiceSpec
.saveMembers(any[DB], anyString, any[Set[String]], isAdmin = anyBoolean) .saveMembers(any[DB], anyString, any[Set[String]], isAdmin = anyBoolean)
doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange]) doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange])
val result: Group = rightResultOf(underTest.createGroup(groupInfo, okAuth).value) val result: Group = underTest.createGroup(groupInfo, okAuth).value.unsafeRunSync().toOption.get
result shouldBe groupInfo result shouldBe groupInfo
val groupCaptor = ArgumentCaptor.forClass(classOf[Group]) val groupCaptor = ArgumentCaptor.forClass(classOf[Group])
@@ -151,7 +149,7 @@ class MembershipServiceSpec
.saveMembers(any[DB], anyString, any[Set[String]], isAdmin = anyBoolean) .saveMembers(any[DB], anyString, any[Set[String]], isAdmin = anyBoolean)
doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange]) doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange])
val result: Group = rightResultOf(underTest.createGroup(groupInfo, okAuth).value) val result: Group = underTest.createGroup(groupInfo, okAuth).value.unsafeRunSync().toOption.get
result shouldBe groupInfo result shouldBe groupInfo
val groupChangeCaptor = ArgumentCaptor.forClass(classOf[GroupChange]) val groupChangeCaptor = ArgumentCaptor.forClass(classOf[GroupChange])
@@ -180,7 +178,7 @@ class MembershipServiceSpec
).thenReturn(IO.pure(expectedMembersAdded)) ).thenReturn(IO.pure(expectedMembersAdded))
doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange]) doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange])
val result: Group = rightResultOf(underTest.createGroup(info, okAuth).value) val result: Group = underTest.createGroup(info, okAuth).value.unsafeRunSync().toOption.get
result shouldBe info result shouldBe info
val memberIdCaptor = ArgumentCaptor.forClass(classOf[Set[String]]) val memberIdCaptor = ArgumentCaptor.forClass(classOf[Set[String]])
@@ -207,7 +205,7 @@ class MembershipServiceSpec
.saveMembers(any[DB], anyString, any[Set[String]], isAdmin = anyBoolean) .saveMembers(any[DB], anyString, any[Set[String]], isAdmin = anyBoolean)
doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange]) doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange])
val result: Group = rightResultOf(underTest.createGroup(info, okAuth).value) val result: Group = underTest.createGroup(info, okAuth).value.unsafeRunSync().toOption.get
result.memberIds should contain(okAuth.userId) result.memberIds should contain(okAuth.userId)
} }
@@ -217,7 +215,7 @@ class MembershipServiceSpec
.when(underTest) .when(underTest)
.groupWithSameNameDoesNotExist(groupInfo.name) .groupWithSameNameDoesNotExist(groupInfo.name)
val error = leftResultOf(underTest.createGroup(groupInfo, okAuth).value) val error = underTest.createGroup(groupInfo, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[GroupAlreadyExistsError] error shouldBe a[GroupAlreadyExistsError]
verify(mockGroupRepo, never()).save(any[DB], any[Group]) verify(mockGroupRepo, never()).save(any[DB], any[Group])
@@ -233,7 +231,7 @@ class MembershipServiceSpec
.when(underTest) .when(underTest)
.usersExist(groupInfo.memberIds) .usersExist(groupInfo.memberIds)
val error = leftResultOf(underTest.createGroup(groupInfo, okAuth).value) val error = underTest.createGroup(groupInfo, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[UserNotFoundError] error shouldBe a[UserNotFoundError]
verify(mockGroupRepo, never()).save(any[DB], any[Group]) verify(mockGroupRepo, never()).save(any[DB], any[Group])
@@ -249,7 +247,7 @@ class MembershipServiceSpec
doReturn(IO.raiseError(new RuntimeException("fail"))).when(mockGroupRepo).save(any[DB], any[Group]) doReturn(IO.raiseError(new RuntimeException("fail"))).when(mockGroupRepo).save(any[DB], any[Group])
doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange]) doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange])
val error = leftResultOf(underTest.createGroup(groupInfo, okAuth).value) val error = underTest.createGroup(groupInfo, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[RuntimeException] error shouldBe a[RuntimeException]
verify(mockMembershipRepo, never()) verify(mockMembershipRepo, never())
@@ -267,7 +265,7 @@ class MembershipServiceSpec
.saveMembers(any[DB], anyString, any[Set[String]], isAdmin = anyBoolean) .saveMembers(any[DB], anyString, any[Set[String]], isAdmin = anyBoolean)
doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange]) doReturn(IO.pure(okGroupChange)).when(mockGroupChangeRepo).save(any[DB], any[GroupChange])
val error = leftResultOf(underTest.createGroup(groupInfo, okAuth).value) val error = underTest.createGroup(groupInfo, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[RuntimeException] error shouldBe a[RuntimeException]
} }
@@ -277,7 +275,7 @@ class MembershipServiceSpec
.when(underTest) .when(underTest)
.groupValidation(groupInfo.copy(name = "", email = "")) .groupValidation(groupInfo.copy(name = "", email = ""))
val error = leftResultOf(underTest.createGroup(groupInfo.copy(name = "", email = ""), okAuth).value) val error = underTest.createGroup(groupInfo.copy(name = "", email = ""), okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[GroupValidationError] error shouldBe a[GroupValidationError]
verify(mockGroupRepo, never()).save(any[DB], any[Group]) verify(mockGroupRepo, never()).save(any[DB], any[Group])
@@ -304,7 +302,6 @@ class MembershipServiceSpec
.when(mockGroupChangeRepo) .when(mockGroupChangeRepo)
.save(any[DB], any[GroupChange]) .save(any[DB], any[GroupChange])
awaitResultOf(
underTest underTest
.updateGroup( .updateGroup(
updatedInfo.id, updatedInfo.id,
@@ -315,8 +312,7 @@ class MembershipServiceSpec
updatedInfo.adminUserIds, updatedInfo.adminUserIds,
okAuth okAuth
) )
.value .value.unsafeRunSync()
)
val groupCaptor = ArgumentCaptor.forClass(classOf[Group]) val groupCaptor = ArgumentCaptor.forClass(classOf[Group])
val addedMemberCaptor = ArgumentCaptor.forClass(classOf[Set[String]]) val addedMemberCaptor = ArgumentCaptor.forClass(classOf[Set[String]])
@@ -366,7 +362,7 @@ class MembershipServiceSpec
"return an error if the user is not an admin" in { "return an error if the user is not an admin" in {
doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(anyString) doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(anyString)
val error = leftResultOf( val error =
underTest underTest
.updateGroup( .updateGroup(
updatedInfo.id, updatedInfo.id,
@@ -377,8 +373,7 @@ class MembershipServiceSpec
updatedInfo.adminUserIds, updatedInfo.adminUserIds,
dummyAuth dummyAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -392,7 +387,7 @@ class MembershipServiceSpec
.when(underTest) .when(underTest)
.differentGroupWithSameNameDoesNotExist(updatedInfo.name, existingGroup.id) .differentGroupWithSameNameDoesNotExist(updatedInfo.name, existingGroup.id)
val error = leftResultOf( val error =
underTest underTest
.updateGroup( .updateGroup(
updatedInfo.id, updatedInfo.id,
@@ -403,8 +398,8 @@ class MembershipServiceSpec
updatedInfo.adminUserIds, updatedInfo.adminUserIds,
okAuth okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[GroupAlreadyExistsError] error shouldBe a[GroupAlreadyExistsError]
} }
@@ -417,7 +412,7 @@ class MembershipServiceSpec
.when(underTest) .when(underTest)
.groupValidation(existingGroup.copy(name = "", email = "")) .groupValidation(existingGroup.copy(name = "", email = ""))
val error = leftResultOf( val error =
underTest underTest
.updateGroup( .updateGroup(
updatedInfo.id, updatedInfo.id,
@@ -428,15 +423,15 @@ class MembershipServiceSpec
updatedInfo.adminUserIds, updatedInfo.adminUserIds,
okAuth okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[GroupValidationError] error shouldBe a[GroupValidationError]
} }
"return an error if the group is not found" in { "return an error if the group is not found" in {
doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(existingGroup.id) doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(existingGroup.id)
val error = leftResultOf( val error =
underTest underTest
.updateGroup( .updateGroup(
updatedInfo.id, updatedInfo.id,
@@ -447,8 +442,8 @@ class MembershipServiceSpec
updatedInfo.adminUserIds, updatedInfo.adminUserIds,
okAuth okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[GroupNotFoundError] error shouldBe a[GroupNotFoundError]
} }
@@ -463,7 +458,7 @@ class MembershipServiceSpec
.when(underTest) .when(underTest)
.usersExist(any[Set[String]]) .usersExist(any[Set[String]])
val error = leftResultOf( val error =
underTest underTest
.updateGroup( .updateGroup(
updatedInfo.id, updatedInfo.id,
@@ -474,8 +469,8 @@ class MembershipServiceSpec
updatedInfo.adminUserIds, updatedInfo.adminUserIds,
okAuth okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[UserNotFoundError] error shouldBe a[UserNotFoundError]
} }
@@ -484,7 +479,7 @@ class MembershipServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroup(existingGroup.id) .getGroup(existingGroup.id)
val error = leftResultOf( val error =
underTest underTest
.updateGroup( .updateGroup(
updatedInfo.id, updatedInfo.id,
@@ -495,8 +490,8 @@ class MembershipServiceSpec
Set(), Set(),
okAuth okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe an[InvalidGroupError] error shouldBe an[InvalidGroupError]
} }
} }
@@ -519,7 +514,7 @@ class MembershipServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getFirstOwnedZoneAclGroupId(anyString()) .getFirstOwnedZoneAclGroupId(anyString())
val result: Group = rightResultOf(underTest.deleteGroup("ok", okAuth).value) val result: Group = underTest.deleteGroup("ok", okAuth).value.unsafeRunSync().toOption.get
result shouldBe okGroup.copy(status = GroupStatus.Deleted) result shouldBe okGroup.copy(status = GroupStatus.Deleted)
val groupCaptor = ArgumentCaptor.forClass(classOf[Group]) val groupCaptor = ArgumentCaptor.forClass(classOf[Group])
@@ -540,7 +535,7 @@ class MembershipServiceSpec
"return an error if the user is not an admin" in { "return an error if the user is not an admin" in {
doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(anyString) doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(anyString)
val error = leftResultOf(underTest.deleteGroup("ok", dummyAuth).value) val error = underTest.deleteGroup("ok", dummyAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -549,7 +544,7 @@ class MembershipServiceSpec
doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(anyString) doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(anyString)
doReturn(IO.pure(List())).when(mockZoneRepo).getZonesByAdminGroupId(anyString) doReturn(IO.pure(List())).when(mockZoneRepo).getZonesByAdminGroupId(anyString)
val error = leftResultOf(underTest.deleteGroup("ok", okAuth).value) val error = underTest.deleteGroup("ok", okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[GroupNotFoundError] error shouldBe a[GroupNotFoundError]
} }
@@ -560,7 +555,7 @@ class MembershipServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getZonesByAdminGroupId(anyString) .getZonesByAdminGroupId(anyString)
val error = leftResultOf(underTest.deleteGroup("ok", okAuth).value) val error = underTest.deleteGroup("ok", okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidGroupRequestError] error shouldBe an[InvalidGroupRequestError]
} }
@@ -570,7 +565,7 @@ class MembershipServiceSpec
doReturn(IO.pure(Some("somerecordsetid"))) doReturn(IO.pure(Some("somerecordsetid")))
.when(mockRecordSetRepo) .when(mockRecordSetRepo)
.getFirstOwnedRecordByGroup(anyString()) .getFirstOwnedRecordByGroup(anyString())
val error = leftResultOf(underTest.deleteGroup("ok", okAuth).value) val error = underTest.deleteGroup("ok", okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidGroupRequestError] error shouldBe an[InvalidGroupRequestError]
} }
@@ -580,7 +575,7 @@ class MembershipServiceSpec
doReturn(IO.pure(Some("someId"))) doReturn(IO.pure(Some("someId")))
.when(mockZoneRepo) .when(mockZoneRepo)
.getFirstOwnedZoneAclGroupId(anyString()) .getFirstOwnedZoneAclGroupId(anyString())
val error = leftResultOf(underTest.deleteGroup("ok", okAuth).value) val error = underTest.deleteGroup("ok", okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidGroupRequestError] error shouldBe an[InvalidGroupRequestError]
} }
@@ -590,13 +585,13 @@ class MembershipServiceSpec
"get a group" should { "get a group" should {
"return the group" in { "return the group" in {
doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(anyString) doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(anyString)
val result: Group = rightResultOf(underTest.getGroup(okGroup.id, okAuth).value) val result: Group = underTest.getGroup(okGroup.id, okAuth).value.unsafeRunSync().toOption.get
result shouldBe okGroup result shouldBe okGroup
} }
"return an error if the group is not found" in { "return an error if the group is not found" in {
doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(anyString) doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(anyString)
val error = leftResultOf(underTest.getGroup("notfound", okAuth).value) val error = underTest.getGroup("notfound", okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[GroupNotFoundError] error shouldBe a[GroupNotFoundError]
} }
} }
@@ -607,7 +602,7 @@ class MembershipServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListMyGroupsResponse = val result: ListMyGroupsResponse =
rightResultOf(underTest.listMyGroups(None, None, 100, listOfDummyGroupsAuth, false).value) underTest.listMyGroups(None, None, 100, listOfDummyGroupsAuth, false).value.unsafeRunSync().toOption.get
verify(mockGroupRepo, never()).getAllGroups() verify(mockGroupRepo, never()).getAllGroups()
result shouldBe ListMyGroupsResponse( result shouldBe ListMyGroupsResponse(
groups = listOfDummyGroupInfo.take(100), groups = listOfDummyGroupInfo.take(100),
@@ -622,7 +617,7 @@ class MembershipServiceSpec
doReturn(IO.pure(listOfDummyGroups.toSet)) doReturn(IO.pure(listOfDummyGroups.toSet))
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListMyGroupsResponse = rightResultOf( val result: ListMyGroupsResponse =
underTest underTest
.listMyGroups( .listMyGroups(
groupNameFilter = Some("name-dummy01"), groupNameFilter = Some("name-dummy01"),
@@ -631,8 +626,8 @@ class MembershipServiceSpec
listOfDummyGroupsAuth, listOfDummyGroupsAuth,
false false
) )
.value .value.unsafeRunSync().toOption.get
)
result shouldBe ListMyGroupsResponse( result shouldBe ListMyGroupsResponse(
groups = listOfDummyGroupInfo.slice(10, 20), groups = listOfDummyGroupInfo.slice(10, 20),
groupNameFilter = Some("name-dummy01"), groupNameFilter = Some("name-dummy01"),
@@ -646,7 +641,7 @@ class MembershipServiceSpec
doReturn(IO.pure(listOfDummyGroups.toSet)) doReturn(IO.pure(listOfDummyGroups.toSet))
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListMyGroupsResponse = rightResultOf( val result: ListMyGroupsResponse =
underTest underTest
.listMyGroups( .listMyGroups(
groupNameFilter = Some("Name-Dummy01"), groupNameFilter = Some("Name-Dummy01"),
@@ -655,8 +650,8 @@ class MembershipServiceSpec
listOfDummyGroupsAuth, listOfDummyGroupsAuth,
false false
) )
.value .value.unsafeRunSync().toOption.get
)
result shouldBe ListMyGroupsResponse( result shouldBe ListMyGroupsResponse(
groups = listOfDummyGroupInfo.slice(10, 20), groups = listOfDummyGroupInfo.slice(10, 20),
groupNameFilter = Some("Name-Dummy01"), groupNameFilter = Some("Name-Dummy01"),
@@ -670,7 +665,7 @@ class MembershipServiceSpec
doReturn(IO.pure(listOfDummyGroups.toSet)) doReturn(IO.pure(listOfDummyGroups.toSet))
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListMyGroupsResponse = rightResultOf( val result: ListMyGroupsResponse =
underTest underTest
.listMyGroups( .listMyGroups(
groupNameFilter = None, groupNameFilter = None,
@@ -679,8 +674,8 @@ class MembershipServiceSpec
listOfDummyGroupsAuth, listOfDummyGroupsAuth,
ignoreAccess = false ignoreAccess = false
) )
.value .value.unsafeRunSync().toOption.get
)
result shouldBe ListMyGroupsResponse( result shouldBe ListMyGroupsResponse(
groups = listOfDummyGroupInfo.slice(100, 200), groups = listOfDummyGroupInfo.slice(100, 200),
groupNameFilter = None, groupNameFilter = None,
@@ -694,7 +689,7 @@ class MembershipServiceSpec
doReturn(IO.pure(listOfDummyGroups.toSet)) doReturn(IO.pure(listOfDummyGroups.toSet))
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListMyGroupsResponse = rightResultOf( val result: ListMyGroupsResponse =
underTest underTest
.listMyGroups( .listMyGroups(
groupNameFilter = None, groupNameFilter = None,
@@ -703,8 +698,8 @@ class MembershipServiceSpec
listOfDummyGroupsAuth, listOfDummyGroupsAuth,
ignoreAccess = false ignoreAccess = false
) )
.value .value.unsafeRunSync().toOption.get
)
result shouldBe ListMyGroupsResponse( result shouldBe ListMyGroupsResponse(
groups = listOfDummyGroupInfo.slice(0, 10), groups = listOfDummyGroupInfo.slice(0, 10),
groupNameFilter = None, groupNameFilter = None,
@@ -717,13 +712,13 @@ class MembershipServiceSpec
"return an empty set if the user is not a member of any groups" in { "return an empty set if the user is not a member of any groups" in {
doReturn(IO.pure(Set())).when(mockGroupRepo).getGroups(any[Set[String]]) doReturn(IO.pure(Set())).when(mockGroupRepo).getGroups(any[Set[String]])
val result: ListMyGroupsResponse = val result: ListMyGroupsResponse =
rightResultOf(underTest.listMyGroups(None, None, 100, notAuth, false).value) underTest.listMyGroups(None, None, 100, notAuth, false).value.unsafeRunSync().toOption.get
result shouldBe ListMyGroupsResponse(Seq(), None, None, None, 100, false) result shouldBe ListMyGroupsResponse(Seq(), None, None, None, 100, false)
} }
"return all groups from the database if ignoreAccess is true" in { "return all groups from the database if ignoreAccess is true" in {
doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups() doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups()
val result: ListMyGroupsResponse = val result: ListMyGroupsResponse =
rightResultOf(underTest.listMyGroups(None, None, 100, notAuth, true).value) underTest.listMyGroups(None, None, 100, notAuth, true).value.unsafeRunSync().toOption.get
verify(mockGroupRepo).getAllGroups() verify(mockGroupRepo).getAllGroups()
result.groups should contain theSameElementsAs Seq( result.groups should contain theSameElementsAs Seq(
GroupInfo(dummyGroup), GroupInfo(dummyGroup),
@@ -733,7 +728,7 @@ class MembershipServiceSpec
"return all groups from the database for super users even if ignoreAccess is false" in { "return all groups from the database for super users even if ignoreAccess is false" in {
doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups() doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups()
val result: ListMyGroupsResponse = val result: ListMyGroupsResponse =
rightResultOf(underTest.listMyGroups(None, None, 100, superUserAuth, false).value) underTest.listMyGroups(None, None, 100, superUserAuth, false).value.unsafeRunSync().toOption.get
verify(mockGroupRepo).getAllGroups() verify(mockGroupRepo).getAllGroups()
result.groups should contain theSameElementsAs Seq( result.groups should contain theSameElementsAs Seq(
GroupInfo(dummyGroup), GroupInfo(dummyGroup),
@@ -743,7 +738,7 @@ class MembershipServiceSpec
"return all groups from the database for super users if ignoreAccess is true" in { "return all groups from the database for super users if ignoreAccess is true" in {
doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups() doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups()
val result: ListMyGroupsResponse = val result: ListMyGroupsResponse =
rightResultOf(underTest.listMyGroups(None, None, 100, superUserAuth, true).value) underTest.listMyGroups(None, None, 100, superUserAuth, true).value.unsafeRunSync().toOption.get
verify(mockGroupRepo).getAllGroups() verify(mockGroupRepo).getAllGroups()
result.groups should contain theSameElementsAs Seq( result.groups should contain theSameElementsAs Seq(
GroupInfo(dummyGroup), GroupInfo(dummyGroup),
@@ -754,7 +749,7 @@ class MembershipServiceSpec
val supportAuth = AuthPrincipal(okUser.copy(isSupport = true), Seq()) val supportAuth = AuthPrincipal(okUser.copy(isSupport = true), Seq())
doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups() doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups()
val result: ListMyGroupsResponse = val result: ListMyGroupsResponse =
rightResultOf(underTest.listMyGroups(None, None, 100, supportAuth, false).value) underTest.listMyGroups(None, None, 100, supportAuth, false).value.unsafeRunSync().toOption.get
verify(mockGroupRepo).getAllGroups() verify(mockGroupRepo).getAllGroups()
result.groups should contain theSameElementsAs Seq( result.groups should contain theSameElementsAs Seq(
GroupInfo(dummyGroup), GroupInfo(dummyGroup),
@@ -765,7 +760,7 @@ class MembershipServiceSpec
val supportAuth = AuthPrincipal(okUser.copy(isSupport = true), Seq()) val supportAuth = AuthPrincipal(okUser.copy(isSupport = true), Seq())
doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups() doReturn(IO.pure(Set(okGroup, dummyGroup))).when(mockGroupRepo).getAllGroups()
val result: ListMyGroupsResponse = val result: ListMyGroupsResponse =
rightResultOf(underTest.listMyGroups(None, None, 100, supportAuth, true).value) underTest.listMyGroups(None, None, 100, supportAuth, true).value.unsafeRunSync().toOption.get
verify(mockGroupRepo).getAllGroups() verify(mockGroupRepo).getAllGroups()
result.groups should contain theSameElementsAs Seq( result.groups should contain theSameElementsAs Seq(
GroupInfo(dummyGroup), GroupInfo(dummyGroup),
@@ -778,7 +773,7 @@ class MembershipServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListMyGroupsResponse = val result: ListMyGroupsResponse =
rightResultOf(underTest.listMyGroups(None, None, 100, deletedGroupAuth, false).value) underTest.listMyGroups(None, None, 100, deletedGroupAuth, false).value.unsafeRunSync().toOption.get
result shouldBe ListMyGroupsResponse(Seq(), None, None, None, 100, false) result shouldBe ListMyGroupsResponse(Seq(), None, None, None, 100, false)
} }
} }
@@ -799,7 +794,7 @@ class MembershipServiceSpec
listOfDummyGroupChanges.map(change => GroupChangeInfo.apply(change.copy(userName = userMap.get(change.userId)))).take(1).head listOfDummyGroupChanges.map(change => GroupChangeInfo.apply(change.copy(userName = userMap.get(change.userId)))).take(1).head
val result: GroupChangeInfo = val result: GroupChangeInfo =
rightResultOf(underTest.getGroupChange(dummyGroup.id, dummyAuth).value) underTest.getGroupChange(dummyGroup.id, dummyAuth).value.unsafeRunSync().toOption.get
result shouldBe expected result shouldBe expected
} }
@@ -818,7 +813,7 @@ class MembershipServiceSpec
listOfDummyGroupChanges.map(change => GroupChangeInfo.apply(change.copy(userName = userMap.get(change.userId)))).take(1).head listOfDummyGroupChanges.map(change => GroupChangeInfo.apply(change.copy(userName = userMap.get(change.userId)))).take(1).head
val result: GroupChangeInfo = val result: GroupChangeInfo =
rightResultOf(underTest.getGroupChange(dummyGroup.id, okAuth).value) underTest.getGroupChange(dummyGroup.id, okAuth).value.unsafeRunSync().toOption.get
result shouldBe expected result shouldBe expected
} }
@@ -831,7 +826,7 @@ class MembershipServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(any[Set[String]], any[Option[String]], any[Option[Int]]) .getUsers(any[Set[String]], any[Option[String]], any[Option[Int]])
val result = leftResultOf(underTest.getGroupChange(dummyGroup.id, okAuth).value) val result = underTest.getGroupChange(dummyGroup.id, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[InvalidGroupRequestError] result shouldBe a[InvalidGroupRequestError]
} }
} }
@@ -855,7 +850,7 @@ class MembershipServiceSpec
listOfDummyGroupChanges.map(change => GroupChangeInfo.apply(change.copy(userName = userMap.get(change.userId)))).take(100) listOfDummyGroupChanges.map(change => GroupChangeInfo.apply(change.copy(userName = userMap.get(change.userId)))).take(100)
val result: ListGroupChangesResponse = val result: ListGroupChangesResponse =
rightResultOf(underTest.getGroupActivity(dummyGroup.id, None, 100, dummyAuth).value) underTest.getGroupActivity(dummyGroup.id, None, 100, dummyAuth).value.unsafeRunSync().toOption.get
result.changes should contain theSameElementsAs expected result.changes should contain theSameElementsAs expected
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe Some(listOfDummyGroupChanges(100).id) result.nextId shouldBe Some(listOfDummyGroupChanges(100).id)
@@ -880,7 +875,7 @@ class MembershipServiceSpec
listOfDummyGroupChanges.map(change => GroupChangeInfo.apply(change.copy(userName = userMap.get(change.userId)))).take(100) listOfDummyGroupChanges.map(change => GroupChangeInfo.apply(change.copy(userName = userMap.get(change.userId)))).take(100)
val result: ListGroupChangesResponse = val result: ListGroupChangesResponse =
rightResultOf(underTest.getGroupActivity(dummyGroup.id, None, 100, okAuth).value) underTest.getGroupActivity(dummyGroup.id, None, 100, okAuth).value.unsafeRunSync().toOption.get
result.changes should contain theSameElementsAs expected result.changes should contain theSameElementsAs expected
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.nextId shouldBe Some(listOfDummyGroupChanges(100).id) result.nextId shouldBe Some(listOfDummyGroupChanges(100).id)
@@ -891,7 +886,7 @@ class MembershipServiceSpec
"determine group difference" should { "determine group difference" should {
"return difference between two groups" in { "return difference between two groups" in {
val groupChange = Seq(okGroupChange, dummyGroupChangeUpdate, okGroupChange.copy(changeType = GroupChangeType.Delete)) val groupChange = Seq(okGroupChange, dummyGroupChangeUpdate, okGroupChange.copy(changeType = GroupChangeType.Delete))
val result: Seq[String] = rightResultOf(underTest.determineGroupDifference(groupChange).value) val result: Seq[String] = underTest.determineGroupDifference(groupChange).value.unsafeRunSync().toOption.get
// Newly created group's change message // Newly created group's change message
result(0) shouldBe "Group Created." result(0) shouldBe "Group Created."
// Updated group's change message // Updated group's change message
@@ -914,7 +909,7 @@ class MembershipServiceSpec
.getUsers(testGroup.adminUserIds, None, None) .getUsers(testGroup.adminUserIds, None, None)
val result: ListAdminsResponse = val result: ListAdminsResponse =
rightResultOf(underTest.listAdmins(testGroup.id, okAuth).value) underTest.listAdmins(testGroup.id, okAuth).value.unsafeRunSync().toOption.get
result.admins should contain theSameElementsAs expectedAdmins result.admins should contain theSameElementsAs expectedAdmins
} }
@@ -930,7 +925,7 @@ class MembershipServiceSpec
.getUsers(testGroup.adminUserIds, None, None) .getUsers(testGroup.adminUserIds, None, None)
val result: ListAdminsResponse = val result: ListAdminsResponse =
rightResultOf(underTest.listAdmins(testGroup.id, dummyAuth).value) underTest.listAdmins(testGroup.id, dummyAuth).value.unsafeRunSync().toOption.get
result.admins should contain theSameElementsAs expectedAdmins result.admins should contain theSameElementsAs expectedAdmins
} }
} }
@@ -951,7 +946,7 @@ class MembershipServiceSpec
.getUsers(testGroup.memberIds, None, Some(100)) .getUsers(testGroup.memberIds, None, Some(100))
val result: ListMembersResponse = val result: ListMembersResponse =
rightResultOf(underTest.listMembers(testGroup.id, None, 100, testAuth).value) underTest.listMembers(testGroup.id, None, 100, testAuth).value.unsafeRunSync().toOption.get
result.members should contain theSameElementsAs expectedMembers result.members should contain theSameElementsAs expectedMembers
result.nextId shouldBe testListUsersResult.lastEvaluatedId result.nextId shouldBe testListUsersResult.lastEvaluatedId
@@ -976,7 +971,7 @@ class MembershipServiceSpec
.getUsers(testGroup.memberIds, None, Some(100)) .getUsers(testGroup.memberIds, None, Some(100))
val result: ListMembersResponse = val result: ListMembersResponse =
rightResultOf(underTest.listMembers(testGroup.id, None, 100, supportAuth).value) underTest.listMembers(testGroup.id, None, 100, supportAuth).value.unsafeRunSync().toOption.get
result.members should contain theSameElementsAs expectedMembers result.members should contain theSameElementsAs expectedMembers
result.nextId shouldBe testListUsersResult.lastEvaluatedId result.nextId shouldBe testListUsersResult.lastEvaluatedId
@@ -997,7 +992,7 @@ class MembershipServiceSpec
.getUsers(testGroup.memberIds, None, Some(100)) .getUsers(testGroup.memberIds, None, Some(100))
val result: ListMembersResponse = val result: ListMembersResponse =
rightResultOf(underTest.listMembers(testGroup.id, None, 100, dummyAuth).value) underTest.listMembers(testGroup.id, None, 100, dummyAuth).value.unsafeRunSync().toOption.get
result.members should contain theSameElementsAs expectedMembers result.members should contain theSameElementsAs expectedMembers
result.nextId shouldBe testListUsersResult.lastEvaluatedId result.nextId shouldBe testListUsersResult.lastEvaluatedId
@@ -1010,21 +1005,21 @@ class MembershipServiceSpec
"return true when a group with the same name does not exist" in { "return true when a group with the same name does not exist" in {
doReturn(IO.pure(None)).when(mockGroupRepo).getGroupByName("foo") doReturn(IO.pure(None)).when(mockGroupRepo).getGroupByName("foo")
val result = awaitResultOf(underTest.groupWithSameNameDoesNotExist("foo").value) val result = underTest.groupWithSameNameDoesNotExist("foo").value.unsafeRunSync()
result should be(right) result should be(right)
} }
"return a GroupAlreadyExistsError if a group with the same name already exists" in { "return a GroupAlreadyExistsError if a group with the same name already exists" in {
doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroupByName("foo") doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroupByName("foo")
val result = leftResultOf(underTest.groupWithSameNameDoesNotExist("foo").value) val result = underTest.groupWithSameNameDoesNotExist("foo").value.unsafeRunSync().swap.toOption.get
result shouldBe a[GroupAlreadyExistsError] result shouldBe a[GroupAlreadyExistsError]
} }
"return true if a group with the same name exists but is deleted" in { "return true if a group with the same name exists but is deleted" in {
doReturn(IO.pure(Some(deletedGroup))).when(mockGroupRepo).getGroupByName("foo") doReturn(IO.pure(Some(deletedGroup))).when(mockGroupRepo).getGroupByName("foo")
val result = awaitResultOf(underTest.groupWithSameNameDoesNotExist("foo").value) val result = underTest.groupWithSameNameDoesNotExist("foo").value.unsafeRunSync()
result should be(right) result should be(right)
} }
} }
@@ -1035,7 +1030,7 @@ class MembershipServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(okGroup.memberIds, None, None) .getUsers(okGroup.memberIds, None, None)
val result = awaitResultOf(underTest.usersExist(okGroup.memberIds).value) val result = underTest.usersExist(okGroup.memberIds).value.unsafeRunSync()
result should be(right) result should be(right)
} }
@@ -1044,7 +1039,7 @@ class MembershipServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set(okUser.id, dummyUser.id), None, None) .getUsers(Set(okUser.id, dummyUser.id), None, None)
val result = leftResultOf(underTest.usersExist(Set(okUser.id, dummyUser.id)).value) val result = underTest.usersExist(Set(okUser.id, dummyUser.id)).value.unsafeRunSync().swap.toOption.get
result shouldBe a[UserNotFoundError] result shouldBe a[UserNotFoundError]
} }
} }
@@ -1056,7 +1051,7 @@ class MembershipServiceSpec
doReturn(IO.pure(Some(existingGroup))).when(mockGroupRepo).getGroupByName("foo") doReturn(IO.pure(Some(existingGroup))).when(mockGroupRepo).getGroupByName("foo")
val error = val error =
leftResultOf(underTest.differentGroupWithSameNameDoesNotExist("foo", "bar").value) underTest.differentGroupWithSameNameDoesNotExist("foo", "bar").value.unsafeRunSync().swap.toOption.get
error shouldBe a[GroupAlreadyExistsError] error shouldBe a[GroupAlreadyExistsError]
} }
@@ -1064,9 +1059,8 @@ class MembershipServiceSpec
doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroupByName(okGroup.name) doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroupByName(okGroup.name)
val result = awaitResultOf( val result =
underTest.differentGroupWithSameNameDoesNotExist(okGroup.name, okGroup.id).value underTest.differentGroupWithSameNameDoesNotExist(okGroup.name, okGroup.id).value.unsafeRunSync()
)
result should be(right) result should be(right)
} }
@@ -1077,9 +1071,8 @@ class MembershipServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroupByName(okGroup.name) .getGroupByName(okGroup.name)
val result = awaitResultOf( val result =
underTest.differentGroupWithSameNameDoesNotExist(okGroup.name, okGroup.id).value underTest.differentGroupWithSameNameDoesNotExist(okGroup.name, okGroup.id).value.unsafeRunSync()
)
result should be(right) result should be(right)
} }
} }
@@ -1088,7 +1081,7 @@ class MembershipServiceSpec
"return true when a group for deletion is not the admin of a zone" in { "return true when a group for deletion is not the admin of a zone" in {
doReturn(IO.pure(List())).when(mockZoneRepo).getZonesByAdminGroupId(okGroup.id) doReturn(IO.pure(List())).when(mockZoneRepo).getZonesByAdminGroupId(okGroup.id)
val result = awaitResultOf(underTest.isNotZoneAdmin(okGroup).value) val result = underTest.isNotZoneAdmin(okGroup).value.unsafeRunSync()
result should be(right) result should be(right)
} }
@@ -1097,7 +1090,7 @@ class MembershipServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getZonesByAdminGroupId(okGroup.id) .getZonesByAdminGroupId(okGroup.id)
val error = leftResultOf(underTest.isNotZoneAdmin(okGroup).value) val error = underTest.isNotZoneAdmin(okGroup).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidGroupRequestError] error shouldBe an[InvalidGroupRequestError]
} }
} }
@@ -1106,7 +1099,7 @@ class MembershipServiceSpec
"return true when a group for deletion is not the admin of a zone" in { "return true when a group for deletion is not the admin of a zone" in {
doReturn(IO.pure(None)).when(mockRecordSetRepo).getFirstOwnedRecordByGroup(okGroup.id) doReturn(IO.pure(None)).when(mockRecordSetRepo).getFirstOwnedRecordByGroup(okGroup.id)
val result = awaitResultOf(underTest.isNotRecordOwnerGroup(okGroup).value) val result = underTest.isNotRecordOwnerGroup(okGroup).value.unsafeRunSync()
result should be(right) result should be(right)
} }
@@ -1115,7 +1108,7 @@ class MembershipServiceSpec
.when(mockRecordSetRepo) .when(mockRecordSetRepo)
.getFirstOwnedRecordByGroup(okGroup.id) .getFirstOwnedRecordByGroup(okGroup.id)
val error = leftResultOf(underTest.isNotRecordOwnerGroup(okGroup).value) val error = underTest.isNotRecordOwnerGroup(okGroup).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidGroupRequestError] error shouldBe an[InvalidGroupRequestError]
} }
} }
@@ -1124,7 +1117,7 @@ class MembershipServiceSpec
"return successfully when a groupId is not in any zone ACL" in { "return successfully when a groupId is not in any zone ACL" in {
doReturn(IO.pure(None)).when(mockZoneRepo).getFirstOwnedZoneAclGroupId(okGroup.id) doReturn(IO.pure(None)).when(mockZoneRepo).getFirstOwnedZoneAclGroupId(okGroup.id)
val result = awaitResultOf(underTest.isNotInZoneAclRule(okGroup).value) val result = underTest.isNotInZoneAclRule(okGroup).value.unsafeRunSync()
result should be(right) result should be(right)
} }
@@ -1133,7 +1126,7 @@ class MembershipServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getFirstOwnedZoneAclGroupId(okGroup.id) .getFirstOwnedZoneAclGroupId(okGroup.id)
val error = leftResultOf(underTest.isNotInZoneAclRule(okGroup).value) val error = underTest.isNotInZoneAclRule(okGroup).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidGroupRequestError] error shouldBe an[InvalidGroupRequestError]
} }
} }
@@ -1176,11 +1169,10 @@ class MembershipServiceSpec
} }
"return an error if the signed in user is not a super user" in { "return an error if the signed in user is not a super user" in {
val error = leftResultOf( val error =
underTest underTest
.updateUserLockStatus(okUser.id, LockStatus.Locked, dummyAuth) .updateUserLockStatus(okUser.id, LockStatus.Locked, dummyAuth)
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -1190,22 +1182,22 @@ class MembershipServiceSpec
signedInUser = dummyAuth.signedInUser.copy(isSupport = true), signedInUser = dummyAuth.signedInUser.copy(isSupport = true),
memberGroupIds = Seq.empty memberGroupIds = Seq.empty
) )
val error = leftResultOf( val error =
underTest underTest
.updateUserLockStatus(okUser.id, LockStatus.Locked, supportAuth) .updateUserLockStatus(okUser.id, LockStatus.Locked, supportAuth)
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
"return an error if the requested user is not found" in { "return an error if the requested user is not found" in {
doReturn(IO.pure(None)).when(mockUserRepo).getUser(okUser.id) doReturn(IO.pure(None)).when(mockUserRepo).getUser(okUser.id)
val error = leftResultOf( val error =
underTest underTest
.updateUserLockStatus(okUser.id, LockStatus.Locked, superUserAuth) .updateUserLockStatus(okUser.id, LockStatus.Locked, superUserAuth)
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[UserNotFoundError] error shouldBe a[UserNotFoundError]
} }
} }
@@ -1213,13 +1205,13 @@ class MembershipServiceSpec
"get user" should { "get user" should {
"return the user" in { "return the user" in {
doReturn(IO.pure(Some(okUser))).when(mockUserRepo).getUserByIdOrName(anyString) doReturn(IO.pure(Some(okUser))).when(mockUserRepo).getUserByIdOrName(anyString)
val result: User = rightResultOf(underTest.getUser(okUser.id, okAuth).value) val result: User = underTest.getUser(okUser.id, okAuth).value.unsafeRunSync().toOption.get
result shouldBe okUser result shouldBe okUser
} }
"return an error if the user is not found" in { "return an error if the user is not found" in {
doReturn(IO.pure(None)).when(mockUserRepo).getUserByIdOrName(anyString) doReturn(IO.pure(None)).when(mockUserRepo).getUserByIdOrName(anyString)
val error = leftResultOf(underTest.getUser("notfound", okAuth).value) val error = underTest.getUser("notfound", okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[UserNotFoundError] error shouldBe a[UserNotFoundError]
} }
} }

View File

@@ -24,8 +24,8 @@ import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.BeforeAndAfterEach import org.scalatest.BeforeAndAfterEach
import vinyldns.api.VinylDNSTestHelpers
import vinyldns.api.config.{ZoneAuthConfigs, DottedHostsConfig} import vinyldns.api.config.{ZoneAuthConfigs, DottedHostsConfig}
import vinyldns.api.{ResultHelpers, VinylDNSTestHelpers}
import vinyldns.api.domain.access.AccessValidations import vinyldns.api.domain.access.AccessValidations
import vinyldns.api.domain.record.RecordSetHelpers._ import vinyldns.api.domain.record.RecordSetHelpers._
import vinyldns.api.domain.zone._ import vinyldns.api.domain.zone._
@@ -46,7 +46,6 @@ class RecordSetServiceSpec
with EitherMatchers with EitherMatchers
with Matchers with Matchers
with MockitoSugar with MockitoSugar
with ResultHelpers
with BeforeAndAfterEach { with BeforeAndAfterEach {
private val mockZoneRepo = mock[ZoneRepository] private val mockZoneRepo = mock[ZoneRepository]
@@ -187,9 +186,7 @@ class RecordSetServiceSpec
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = val result: RecordSetChange =
rightResultOf( underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value
)
matches(result.recordSet, record, okZone.name) shouldBe true matches(result.recordSet, record, okZone.name) shouldBe true
result.changeType shouldBe RecordSetChangeType.Create result.changeType shouldBe RecordSetChangeType.Create
@@ -199,7 +196,7 @@ class RecordSetServiceSpec
val mockZone = okZone.copy(id = "fakeZone") val mockZone = okZone.copy(id = "fakeZone")
doReturn(IO.pure(None)).when(mockZoneRepo).getZone(mockZone.id) doReturn(IO.pure(None)).when(mockZoneRepo).getZone(mockZone.id)
val result = leftResultOf(underTest.getRecordSetByZone(aaaa.id, mockZone.id, okAuth).value) val result = underTest.getRecordSetByZone(aaaa.id, mockZone.id, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[ZoneNotFoundError] result shouldBe a[ZoneNotFoundError]
} }
"fail when the account is not authorized" in { "fail when the account is not authorized" in {
@@ -207,7 +204,7 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSet(aaaa.id) .getRecordSet(aaaa.id)
val result = val result =
leftResultOf(underTest.getRecordSetByZone(aaaa.id, zoneNotAuthorized.id, okAuth).value) underTest.getRecordSetByZone(aaaa.id, zoneNotAuthorized.id, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
"fail if the record already exists" in { "fail if the record already exists" in {
@@ -221,7 +218,7 @@ class RecordSetServiceSpec
.when(mockBackend) .when(mockBackend)
.resolve(record.name, okZone.name, record.typ) .resolve(record.name, okZone.name, record.typ)
val result = leftResultOf(underTest.addRecordSet(aaaa, okAuth).value) val result = underTest.addRecordSet(aaaa, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[RecordSetAlreadyExists] result shouldBe a[RecordSetAlreadyExists]
} }
"fail if the record is dotted and does not satisfy properties in dotted hosts config" in { "fail if the record is dotted and does not satisfy properties in dotted hosts config" in {
@@ -256,7 +253,7 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result = leftResultOf(underTest.addRecordSet(record, okAuth).value) val result = underTest.addRecordSet(record, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"fail if the record is dotted and dotted hosts config is empty" in { "fail if the record is dotted and dotted hosts config is empty" in {
@@ -291,7 +288,7 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result = leftResultOf(underTestWithEmptyDottedHostsConfig.addRecordSet(record, okAuth).value) val result = underTestWithEmptyDottedHostsConfig.addRecordSet(record, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"fail if the record is relative with trailing dot" in { "fail if the record is relative with trailing dot" in {
@@ -327,14 +324,14 @@ class RecordSetServiceSpec
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result = val result =
leftResultOf(underTestWithDnsBackendValidations.addRecordSet(record, okAuth).value) underTestWithDnsBackendValidations.addRecordSet(record, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"fail if the record is a high value domain" in { "fail if the record is a high value domain" in {
val record = val record =
aaaa.copy(name = "high-value-domain", zoneId = okZone.id, status = RecordSetStatus.Active) aaaa.copy(name = "high-value-domain", zoneId = okZone.id, status = RecordSetStatus.Active)
val result = leftResultOf(underTest.addRecordSet(record, okAuth).value) val result = underTest.addRecordSet(record, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe InvalidRequest( result shouldBe InvalidRequest(
HighValueDomainError(s"high-value-domain.${okZone.name}").message HighValueDomainError(s"high-value-domain.${okZone.name}").message
) )
@@ -372,9 +369,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe okZone.name result.recordSet.name shouldBe okZone.name
} }
@@ -411,9 +407,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe okZone.name result.recordSet.name shouldBe okZone.name
} }
@@ -429,9 +424,8 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSetsByName(okZone.id, record.name) .getRecordSetsByName(okZone.id, record.name)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe okZone.name result.recordSet.name shouldBe okZone.name
} }
@@ -469,9 +463,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.addRecordSet(record, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.ownerGroupId shouldBe Some(okGroup.id) result.recordSet.ownerGroupId shouldBe Some(okGroup.id)
} }
@@ -488,7 +481,7 @@ class RecordSetServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroup(dummyGroup.id) .getGroup(dummyGroup.id)
val result = leftResultOf(underTest.addRecordSet(record, okAuth).value) val result = underTest.addRecordSet(record, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
@@ -505,7 +498,7 @@ class RecordSetServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroup(dummyGroup.id) .getGroup(dummyGroup.id)
val result = leftResultOf(underTest.addRecordSet(record, okAuth).value) val result = underTest.addRecordSet(record, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidGroupError] result shouldBe an[InvalidGroupError]
} }
@@ -544,12 +537,10 @@ class RecordSetServiceSpec
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = val result: RecordSetChange =
rightResultOf(
underTestWithDnsBackendValidations underTestWithDnsBackendValidations
.addRecordSet(record, okAuth) .addRecordSet(record, okAuth)
.map(_.asInstanceOf[RecordSetChange]) .map(_.asInstanceOf[RecordSetChange])
.value .value.unsafeRunSync().toOption.get
)
matches(result.recordSet, record, okZone.name) shouldBe true matches(result.recordSet, record, okZone.name) shouldBe true
result.changeType shouldBe RecordSetChangeType.Create result.changeType shouldBe RecordSetChangeType.Create
@@ -594,9 +585,8 @@ class RecordSetServiceSpec
.getUsers(dummyGroup.memberIds, None, None) .getUsers(dummyGroup.memberIds, None, None)
// passes as all three properties within dotted hosts config (allowed zones, users and record types) are satisfied // passes as all three properties within dotted hosts config (allowed zones, users and record types) are satisfied
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.addRecordSet(record, xyzAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.addRecordSet(record, xyzAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe record.name result.recordSet.name shouldBe record.name
} }
@@ -638,9 +628,8 @@ class RecordSetServiceSpec
.getUsers(xyzGroup.memberIds, None, None) .getUsers(xyzGroup.memberIds, None, None)
// passes as all three properties within dotted hosts config (allowed zones, users and record types) are satisfied // passes as all three properties within dotted hosts config (allowed zones, users and record types) are satisfied
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.addRecordSet(record, xyzAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.addRecordSet(record, xyzAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe record.name result.recordSet.name shouldBe record.name
} }
@@ -682,7 +671,7 @@ class RecordSetServiceSpec
.getUsers(xyzGroup.memberIds, None, None) .getUsers(xyzGroup.memberIds, None, None)
// fails as dotted host record name has dot at the end and is not an apex record // fails as dotted host record name has dot at the end and is not an apex record
val result = leftResultOf(underTest.addRecordSet(record, xyzAuth).value) val result = underTest.addRecordSet(record, xyzAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"fail if the record is dotted and zone, user, record type is allowed but number of dots allowed in config is 0" in { "fail if the record is dotted and zone, user, record type is allowed but number of dots allowed in config is 0" in {
@@ -723,7 +712,7 @@ class RecordSetServiceSpec
.getUsers(dummyGroup.memberIds, None, None) .getUsers(dummyGroup.memberIds, None, None)
// fails as no.of.dots allowed for the zone in the config is 0 // fails as no.of.dots allowed for the zone in the config is 0
val result = leftResultOf(underTest.addRecordSet(record, xyzAuth).value) val result = underTest.addRecordSet(record, xyzAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"fail if the record is dotted and user, record type is in allowed dotted hosts config except zone" in { "fail if the record is dotted and user, record type is in allowed dotted hosts config except zone" in {
@@ -759,7 +748,7 @@ class RecordSetServiceSpec
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
// fails as only two properties within dotted hosts config (users and record types) are satisfied while zone is not allowed // fails as only two properties within dotted hosts config (users and record types) are satisfied while zone is not allowed
val result = leftResultOf(underTest.addRecordSet(record, okAuth).value) val result = underTest.addRecordSet(record, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"fail if the record is dotted and zone, record type is in allowed dotted hosts config except user" in { "fail if the record is dotted and zone, record type is in allowed dotted hosts config except user" in {
@@ -800,7 +789,7 @@ class RecordSetServiceSpec
.getUsers(dummyGroup.memberIds, None, None) .getUsers(dummyGroup.memberIds, None, None)
// fails as only two properties within dotted hosts config (zones and record types) are satisfied while user is not allowed // fails as only two properties within dotted hosts config (zones and record types) are satisfied while user is not allowed
val result = leftResultOf(underTest.addRecordSet(record, abcAuth).value) val result = underTest.addRecordSet(record, abcAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"fail if the record is dotted and zone, user is in allowed dotted hosts config except record type" in { "fail if the record is dotted and zone, user is in allowed dotted hosts config except record type" in {
@@ -843,7 +832,7 @@ class RecordSetServiceSpec
.getUsers(dummyGroup.memberIds, None, None) .getUsers(dummyGroup.memberIds, None, None)
// fails as only two properties within dotted hosts config (zone and user) are satisfied while record type is not allowed // fails as only two properties within dotted hosts config (zone and user) are satisfied while record type is not allowed
val result = leftResultOf(underTest.addRecordSet(record, xyzAuth).value) val result = underTest.addRecordSet(record, xyzAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
@@ -883,9 +872,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
matches(result.recordSet, newRecord, okZone.name) shouldBe true matches(result.recordSet, newRecord, okZone.name) shouldBe true
matches(result.updates.get, oldRecord, okZone.name) shouldBe true matches(result.updates.get, oldRecord, okZone.name) shouldBe true
@@ -899,9 +887,9 @@ class RecordSetServiceSpec
doReturn(IO.pure(Some(aaaa.copy(zoneId = zoneNotAuthorized.id)))) doReturn(IO.pure(Some(aaaa.copy(zoneId = zoneNotAuthorized.id))))
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSet(aaaa.id) .getRecordSet(aaaa.id)
val result = leftResultOf( val result =
underTest.updateRecordSet(aaaa.copy(zoneId = zoneNotAuthorized.id), okAuth).value underTest.updateRecordSet(aaaa.copy(zoneId = zoneNotAuthorized.id), okAuth).value.unsafeRunSync().swap.toOption.get
)
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
"succeed if the dotted record name is unchanged" in { "succeed if the dotted record name is unchanged" in {
@@ -940,9 +928,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe oldRecord.name result.recordSet.name shouldBe oldRecord.name
result.recordSet.ttl shouldBe oldRecord.ttl + 1000 result.recordSet.ttl shouldBe oldRecord.ttl + 1000
@@ -961,7 +948,7 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSetsByName(okZone.id, newRecord.name) .getRecordSetsByName(okZone.id, newRecord.name)
val result = leftResultOf(underTest.updateRecordSet(newRecord, okAuth).value) val result = underTest.updateRecordSet(newRecord, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"succeed if record is apex with dot" in { "succeed if record is apex with dot" in {
@@ -1000,9 +987,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe okZone.name result.recordSet.name shouldBe okZone.name
result.recordSet.ttl shouldBe oldRecord.ttl + 1000 result.recordSet.ttl shouldBe oldRecord.ttl + 1000
@@ -1043,9 +1029,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe okZone.name result.recordSet.name shouldBe okZone.name
result.recordSet.ttl shouldBe oldRecord.ttl + 1000 result.recordSet.ttl shouldBe oldRecord.ttl + 1000
@@ -1086,9 +1071,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value underTest.updateRecordSet(newRecord, okAuth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.name shouldBe okZone.name result.recordSet.name shouldBe okZone.name
result.recordSet.ttl shouldBe oldRecord.ttl + 1000 result.recordSet.ttl shouldBe oldRecord.ttl + 1000
@@ -1109,7 +1093,7 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSetsByName(okZone.id, newRecord.name) .getRecordSetsByName(okZone.id, newRecord.name)
val result = leftResultOf(underTest.updateRecordSet(newRecord, okAuth).value) val result = underTest.updateRecordSet(newRecord, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe InvalidRequest( result shouldBe InvalidRequest(
HighValueDomainError(s"high-value-domain.${okZone.name}").message HighValueDomainError(s"high-value-domain.${okZone.name}").message
) )
@@ -1135,7 +1119,7 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSetsByName(okZone.id, newRecord.name) .getRecordSetsByName(okZone.id, newRecord.name)
val result = leftResultOf(underTest.updateRecordSet(newRecord, auth).value) val result = underTest.updateRecordSet(newRecord, auth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
"fail if new owner group does not exist" in { "fail if new owner group does not exist" in {
@@ -1164,7 +1148,7 @@ class RecordSetServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroup("doesnt-exist") .getGroup("doesnt-exist")
val result = leftResultOf(underTest.updateRecordSet(newRecord, auth).value) val result = underTest.updateRecordSet(newRecord, auth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidGroupError] result shouldBe an[InvalidGroupError]
} }
"fail if user not in new owner group" in { "fail if user not in new owner group" in {
@@ -1193,7 +1177,7 @@ class RecordSetServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroup(okGroup.id) .getGroup(okGroup.id)
val result = leftResultOf(underTest.updateRecordSet(newRecord, auth).value) val result = underTest.updateRecordSet(newRecord, auth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"succeed if user is in owner group and zone is shared" in { "succeed if user is in owner group and zone is shared" in {
@@ -1242,9 +1226,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result = rightResultOf( val result =
underTest.updateRecordSet(newRecord, auth).map(_.asInstanceOf[RecordSetChange]).value underTest.updateRecordSet(newRecord, auth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.ttl shouldBe newRecord.ttl result.recordSet.ttl shouldBe newRecord.ttl
result.recordSet.ownerGroupId shouldBe Some(oneUserDummyGroup.id) result.recordSet.ownerGroupId shouldBe Some(oneUserDummyGroup.id)
@@ -1292,9 +1275,8 @@ class RecordSetServiceSpec
.when(mockUserRepo) .when(mockUserRepo)
.getUsers(Set.empty, None, None) .getUsers(Set.empty, None, None)
val result = rightResultOf( val result =
underTest.updateRecordSet(newRecord, auth).map(_.asInstanceOf[RecordSetChange]).value underTest.updateRecordSet(newRecord, auth).map(_.asInstanceOf[RecordSetChange]).value.unsafeRunSync().toOption.get
)
result.recordSet.ttl shouldBe newRecord.ttl result.recordSet.ttl shouldBe newRecord.ttl
result.recordSet.ownerGroupId shouldBe None result.recordSet.ownerGroupId shouldBe None
@@ -1312,7 +1294,7 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSet(newRecord.id) .getRecordSet(newRecord.id)
val result = leftResultOf(underTest.updateRecordSet(newRecord, auth).value) val result = underTest.updateRecordSet(newRecord, auth).value.unsafeRunSync().swap.toOption.get
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
"succeed if new record exists in database but not in DNS backend" in { "succeed if new record exists in database but not in DNS backend" in {
@@ -1332,12 +1314,11 @@ class RecordSetServiceSpec
.when(mockBackend) .when(mockBackend)
.resolve(newRecord.name, okZone.name, newRecord.typ) .resolve(newRecord.name, okZone.name, newRecord.typ)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTestWithDnsBackendValidations underTestWithDnsBackendValidations
.updateRecordSet(newRecord, okAuth) .updateRecordSet(newRecord, okAuth)
.map(_.asInstanceOf[RecordSetChange]) .map(_.asInstanceOf[RecordSetChange])
.value .value.unsafeRunSync().toOption.get
)
matches(result.recordSet, newRecord, okZone.name) shouldBe true matches(result.recordSet, newRecord, okZone.name) shouldBe true
matches(result.updates.get, oldRecord, okZone.name) shouldBe true matches(result.updates.get, oldRecord, okZone.name) shouldBe true
@@ -1358,7 +1339,7 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSet(newRecord.id) .getRecordSet(newRecord.id)
val result = leftResultOf(underTest.updateRecordSet(newRecord, auth).value) val result = underTest.updateRecordSet(newRecord, auth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[InvalidRequest] result shouldBe a[InvalidRequest]
} }
} }
@@ -1370,12 +1351,11 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSet(record.id) .getRecordSet(record.id)
val result: RecordSetChange = rightResultOf( val result: RecordSetChange =
underTest underTest
.deleteRecordSet(record.id, okZone.id, okAuth) .deleteRecordSet(record.id, okZone.id, okAuth)
.map(_.asInstanceOf[RecordSetChange]) .map(_.asInstanceOf[RecordSetChange])
.value .value.unsafeRunSync().toOption.get
)
matches(result.recordSet, record, okZone.name) shouldBe true matches(result.recordSet, record, okZone.name) shouldBe true
result.changeType shouldBe RecordSetChangeType.Delete result.changeType shouldBe RecordSetChangeType.Delete
@@ -1386,7 +1366,7 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSet(aaaa.id) .getRecordSet(aaaa.id)
val result = val result =
leftResultOf(underTest.deleteRecordSet(aaaa.id, zoneNotAuthorized.id, okAuth).value) underTest.deleteRecordSet(aaaa.id, zoneNotAuthorized.id, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
"fail if the record is a high value domain" in { "fail if the record is a high value domain" in {
@@ -1398,16 +1378,14 @@ class RecordSetServiceSpec
.getRecordSet(record.id) .getRecordSet(record.id)
val result = val result =
leftResultOf(underTest.deleteRecordSet(record.id, okZone.id, okAuth).value) underTest.deleteRecordSet(record.id, okZone.id, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe InvalidRequest( result shouldBe InvalidRequest(
HighValueDomainError(s"high-value-domain.${okZone.name}").message HighValueDomainError(s"high-value-domain.${okZone.name}").message
) )
} }
"fail for user who is not in record owner group in shared zone" in { "fail for user who is not in record owner group in shared zone" in {
val result = val result =
leftResultOf( underTest.deleteRecordSet(sharedZoneRecord.id, sharedZoneRecord.zoneId, dummyAuth).value.unsafeRunSync().swap.toOption.get
underTest.deleteRecordSet(sharedZoneRecord.id, sharedZoneRecord.zoneId, dummyAuth).value
)
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
@@ -1417,9 +1395,7 @@ class RecordSetServiceSpec
.getZone(sharedZone.id) .getZone(sharedZone.id)
val result = val result =
leftResultOf( underTest.deleteRecordSet(sharedZoneRecord.id, sharedZoneRecord.zoneId, okAuth).value.unsafeRunSync().swap.toOption.get
underTest.deleteRecordSet(sharedZoneRecord.id, sharedZoneRecord.zoneId, okAuth).value
)
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
@@ -1468,7 +1444,7 @@ class RecordSetServiceSpec
doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(any[String]) doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(any[String])
val result: RecordSetInfo = val result: RecordSetInfo =
rightResultOf(underTest.getRecordSet(aaaa.id, okAuth).value) underTest.getRecordSet(aaaa.id, okAuth).value.unsafeRunSync().toOption.get
result shouldBe expectedRecordSetInfo result shouldBe expectedRecordSetInfo
} }
@@ -1479,7 +1455,7 @@ class RecordSetServiceSpec
.when(mockRecordRepo) .when(mockRecordRepo)
.getRecordSet(mockRecord.id) .getRecordSet(mockRecord.id)
val result = leftResultOf(underTest.getRecordSet(mockRecord.id, okAuth).value) val result = underTest.getRecordSet(mockRecord.id, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[RecordSetNotFoundError] result shouldBe a[RecordSetNotFoundError]
} }
@@ -1497,7 +1473,7 @@ class RecordSetServiceSpec
doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(any[String]) doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(any[String])
val result: RecordSetInfo = val result: RecordSetInfo =
rightResultOf(underTest.getRecordSetByZone(aaaa.id, okZone.id, okAuth).value) underTest.getRecordSetByZone(aaaa.id, okZone.id, okAuth).value.unsafeRunSync().toOption.get
result shouldBe expectedRecordSetInfo result shouldBe expectedRecordSetInfo
} }
@@ -1509,7 +1485,7 @@ class RecordSetServiceSpec
.getRecordSet(mockRecord.id) .getRecordSet(mockRecord.id)
val result = val result =
leftResultOf(underTest.getRecordSetByZone(mockRecord.id, okZone.id, okAuth).value) underTest.getRecordSetByZone(mockRecord.id, okZone.id, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[RecordSetNotFoundError] result shouldBe a[RecordSetNotFoundError]
} }
@@ -1523,9 +1499,8 @@ class RecordSetServiceSpec
val expectedRecordSetInfo = RecordSetInfo(sharedZoneRecord, Some(okGroup.name)) val expectedRecordSetInfo = RecordSetInfo(sharedZoneRecord, Some(okGroup.name))
val result: RecordSetInfo = val result: RecordSetInfo =
rightResultOf( underTest.getRecordSetByZone(sharedZoneRecord.id, sharedZone.id, okAuth).value.unsafeRunSync().toOption.get
underTest.getRecordSetByZone(sharedZoneRecord.id, sharedZone.id, okAuth).value
)
result shouldBe expectedRecordSetInfo result shouldBe expectedRecordSetInfo
} }
@@ -1539,9 +1514,8 @@ class RecordSetServiceSpec
val expectedRecordSetInfo = RecordSetInfo(sharedZoneRecord, None) val expectedRecordSetInfo = RecordSetInfo(sharedZoneRecord, None)
val result: RecordSetInfo = val result: RecordSetInfo =
rightResultOf( underTest.getRecordSetByZone(sharedZoneRecord.id, sharedZone.id, sharedAuth).value.unsafeRunSync().toOption.get
underTest.getRecordSetByZone(sharedZoneRecord.id, sharedZone.id, sharedAuth).value
)
result shouldBe expectedRecordSetInfo result shouldBe expectedRecordSetInfo
} }
@@ -1553,7 +1527,7 @@ class RecordSetServiceSpec
doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(any[String]) doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(any[String])
val result = val result =
leftResultOf(underTest.getRecordSetByZone(aaaa.id, zoneNotAuthorized.id, okAuth).value) underTest.getRecordSetByZone(aaaa.id, zoneNotAuthorized.id, okAuth).value.unsafeRunSync().swap.toOption.get
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
@@ -1567,11 +1541,10 @@ class RecordSetServiceSpec
val expectedRecordSetInfo = RecordSetInfo(sharedZoneRecordNoOwnerGroup, None) val expectedRecordSetInfo = RecordSetInfo(sharedZoneRecordNoOwnerGroup, None)
val result: RecordSetInfo = val result: RecordSetInfo =
rightResultOf(
underTest underTest
.getRecordSetByZone(sharedZoneRecordNoOwnerGroup.id, sharedZone.id, sharedAuth) .getRecordSetByZone(sharedZoneRecordNoOwnerGroup.id, sharedZone.id, sharedAuth)
.value .value.unsafeRunSync().toOption.get
)
result shouldBe expectedRecordSetInfo result shouldBe expectedRecordSetInfo
} }
@@ -1583,11 +1556,9 @@ class RecordSetServiceSpec
doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(any[String]) doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(any[String])
val result = val result =
leftResultOf(
underTest underTest
.getRecordSetByZone(sharedZoneRecordNotApprovedRecordType.id, sharedZone.id, okAuth) .getRecordSetByZone(sharedZoneRecordNotApprovedRecordType.id, sharedZone.id, okAuth)
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
@@ -1613,11 +1584,10 @@ class RecordSetServiceSpec
doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(any[String]) doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(any[String])
val result = leftResultOf( val result =
underTest underTest
.getRecordSetByZone(notSharedZoneRecordWithOwnerGroup.id, zoneNotAuthorized.id, okAuth) .getRecordSetByZone(notSharedZoneRecordWithOwnerGroup.id, zoneNotAuthorized.id, okAuth)
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
} }
@@ -1626,12 +1596,12 @@ class RecordSetServiceSpec
"return the group name if a record owner group ID is present" in { "return the group name if a record owner group ID is present" in {
doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(any[String]) doReturn(IO.pure(Some(okGroup))).when(mockGroupRepo).getGroup(any[String])
val result = rightResultOf(underTest.getGroupName(Some(okGroup.id)).value) val result = underTest.getGroupName(Some(okGroup.id)).value.unsafeRunSync().toOption.get
result shouldBe Some("ok") result shouldBe Some("ok")
} }
"return None if a record owner group ID is not present" in { "return None if a record owner group ID is not present" in {
val result = rightResultOf(underTest.getGroupName(None).value) val result = underTest.getGroupName(None).value.unsafeRunSync().toOption.get
result shouldBe None result shouldBe None
} }
} }
@@ -1666,7 +1636,7 @@ class RecordSetServiceSpec
nameSort = any[NameSort.NameSort] nameSort = any[NameSort.NameSort]
) )
val result: ListGlobalRecordSetsResponse = rightResultOf( val result: ListGlobalRecordSetsResponse =
underTest underTest
.listRecordSets( .listRecordSets(
startFrom = None, startFrom = None,
@@ -1677,8 +1647,8 @@ class RecordSetServiceSpec
nameSort = NameSort.ASC, nameSort = NameSort.ASC,
authPrincipal = sharedAuth authPrincipal = sharedAuth
) )
.value .value.unsafeRunSync().toOption.get
)
result.recordSets shouldBe result.recordSets shouldBe
List( List(
RecordSetGlobalInfo( RecordSetGlobalInfo(
@@ -1691,7 +1661,7 @@ class RecordSetServiceSpec
} }
"fail if recordNameFilter is fewer than two characters" in { "fail if recordNameFilter is fewer than two characters" in {
val result = leftResultOf( val result =
underTest underTest
.listRecordSets( .listRecordSets(
startFrom = None, startFrom = None,
@@ -1702,8 +1672,8 @@ class RecordSetServiceSpec
nameSort = NameSort.ASC, nameSort = NameSort.ASC,
authPrincipal = okAuth authPrincipal = okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
} }
@@ -1738,7 +1708,7 @@ class RecordSetServiceSpec
nameSort = any[NameSort.NameSort] nameSort = any[NameSort.NameSort]
) )
val result = rightResultOf( val result =
underTest underTest
.searchRecordSets( .searchRecordSets(
startFrom = None, startFrom = None,
@@ -1749,8 +1719,8 @@ class RecordSetServiceSpec
nameSort = NameSort.ASC, nameSort = NameSort.ASC,
authPrincipal = sharedAuth authPrincipal = sharedAuth
) )
.value .value.unsafeRunSync().toOption.get
)
result.recordSets shouldBe result.recordSets shouldBe
List( List(
RecordSetGlobalInfo( RecordSetGlobalInfo(
@@ -1763,7 +1733,7 @@ class RecordSetServiceSpec
} }
"fail recordSetData if recordNameFilter is fewer than two characters" in { "fail recordSetData if recordNameFilter is fewer than two characters" in {
val result = leftResultOf( val result =
underTest underTest
.searchRecordSets( .searchRecordSets(
startFrom = None, startFrom = None,
@@ -1774,8 +1744,8 @@ class RecordSetServiceSpec
nameSort = NameSort.ASC, nameSort = NameSort.ASC,
authPrincipal = okAuth authPrincipal = okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe an[InvalidRequest] result shouldBe an[InvalidRequest]
} }
} }
@@ -1805,7 +1775,7 @@ class RecordSetServiceSpec
nameSort = NameSort.ASC nameSort = NameSort.ASC
) )
val result: ListRecordSetsByZoneResponse = rightResultOf( val result: ListRecordSetsByZoneResponse =
underTest underTest
.listRecordSetsByZone( .listRecordSetsByZone(
sharedZone.id, sharedZone.id,
@@ -1817,8 +1787,8 @@ class RecordSetServiceSpec
recordOwnerGroupFilter = None, recordOwnerGroupFilter = None,
nameSort = NameSort.ASC nameSort = NameSort.ASC
) )
.value .value.unsafeRunSync().toOption.get
)
result.recordSets shouldBe result.recordSets shouldBe
List( List(
RecordSetListInfo( RecordSetListInfo(
@@ -1848,7 +1818,7 @@ class RecordSetServiceSpec
nameSort = NameSort.ASC nameSort = NameSort.ASC
) )
val result: ListRecordSetsByZoneResponse = rightResultOf( val result: ListRecordSetsByZoneResponse =
underTest underTest
.listRecordSetsByZone( .listRecordSetsByZone(
okZone.id, okZone.id,
@@ -1860,14 +1830,14 @@ class RecordSetServiceSpec
nameSort = NameSort.ASC, nameSort = NameSort.ASC,
authPrincipal = AuthPrincipal(okAuth.signedInUser.copy(isSupport = true), Seq.empty) authPrincipal = AuthPrincipal(okAuth.signedInUser.copy(isSupport = true), Seq.empty)
) )
.value .value.unsafeRunSync().toOption.get
)
result.recordSets shouldBe List( result.recordSets shouldBe List(
RecordSetListInfo(RecordSetInfo(aaaa, None), AccessLevel.Read) RecordSetListInfo(RecordSetInfo(aaaa, None), AccessLevel.Read)
) )
} }
"fails when the account is not authorized" in { "fails when the account is not authorized" in {
val result = leftResultOf( val result =
underTest underTest
.listRecordSetsByZone( .listRecordSetsByZone(
zoneNotAuthorized.id, zoneNotAuthorized.id,
@@ -1879,8 +1849,8 @@ class RecordSetServiceSpec
nameSort = NameSort.ASC, nameSort = NameSort.ASC,
authPrincipal = okAuth authPrincipal = okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
result shouldBe a[NotAuthorizedError] result shouldBe a[NotAuthorizedError]
} }
} }
@@ -1898,7 +1868,7 @@ class RecordSetServiceSpec
.getUsers(any[Set[String]], any[Option[String]], any[Option[Int]]) .getUsers(any[Set[String]], any[Option[String]], any[Option[Int]])
val result: ListRecordSetChangesResponse = val result: ListRecordSetChangesResponse =
rightResultOf(underTest.listRecordSetChanges(okZone.id, authPrincipal = okAuth).value) underTest.listRecordSetChanges(okZone.id, authPrincipal = okAuth).value.unsafeRunSync().toOption.get
val changesWithName = val changesWithName =
completeRecordSetChanges.map(change => RecordSetChangeInfo(change, Some("ok"))) completeRecordSetChanges.map(change => RecordSetChangeInfo(change, Some("ok")))
val expectedResults = ListRecordSetChangesResponse( val expectedResults = ListRecordSetChangesResponse(
@@ -1917,7 +1887,7 @@ class RecordSetServiceSpec
.listRecordSetChanges(zoneId = okZone.id, startFrom = None, maxItems = 100) .listRecordSetChanges(zoneId = okZone.id, startFrom = None, maxItems = 100)
val result: ListRecordSetChangesResponse = val result: ListRecordSetChangesResponse =
rightResultOf(underTest.listRecordSetChanges(okZone.id, authPrincipal = okAuth).value) underTest.listRecordSetChanges(okZone.id, authPrincipal = okAuth).value.unsafeRunSync().toOption.get
val expectedResults = ListRecordSetChangesResponse( val expectedResults = ListRecordSetChangesResponse(
zoneId = okZone.id, zoneId = okZone.id,
recordSetChanges = List(), recordSetChanges = List(),
@@ -1929,9 +1899,9 @@ class RecordSetServiceSpec
} }
"return a NotAuthorizedError" in { "return a NotAuthorizedError" in {
val error = leftResultOf( val error =
underTest.listRecordSetChanges(zoneNotAuthorized.id, authPrincipal = okAuth).value underTest.listRecordSetChanges(zoneNotAuthorized.id, authPrincipal = okAuth).value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -1944,7 +1914,7 @@ class RecordSetServiceSpec
.listRecordSetChanges(zoneId = okZone.id, startFrom = None, maxItems = 100) .listRecordSetChanges(zoneId = okZone.id, startFrom = None, maxItems = 100)
val result: ListRecordSetChangesResponse = val result: ListRecordSetChangesResponse =
rightResultOf(underTest.listRecordSetChanges(okZone.id, authPrincipal = okAuth).value) underTest.listRecordSetChanges(okZone.id, authPrincipal = okAuth).value.unsafeRunSync().toOption.get
val changesWithName = val changesWithName =
List(RecordSetChangeInfo(rsChange2, Some("ok")), RecordSetChangeInfo(rsChange1, Some("ok"))) List(RecordSetChangeInfo(rsChange2, Some("ok")), RecordSetChangeInfo(rsChange1, Some("ok")))
val expectedResults = ListRecordSetChangesResponse( val expectedResults = ListRecordSetChangesResponse(
@@ -1965,7 +1935,7 @@ class RecordSetServiceSpec
.getRecordSetChange(okZone.id, pendingCreateAAAA.id) .getRecordSetChange(okZone.id, pendingCreateAAAA.id)
val actual: RecordSetChange = val actual: RecordSetChange =
rightResultOf(underTest.getRecordSetChange(okZone.id, pendingCreateAAAA.id, okAuth).value) underTest.getRecordSetChange(okZone.id, pendingCreateAAAA.id, okAuth).value.unsafeRunSync().toOption.get
actual shouldBe pendingCreateAAAA actual shouldBe pendingCreateAAAA
} }
@@ -1975,9 +1945,8 @@ class RecordSetServiceSpec
.getRecordSetChange(sharedZone.id, pendingCreateSharedRecord.id) .getRecordSetChange(sharedZone.id, pendingCreateSharedRecord.id)
val actual: RecordSetChange = val actual: RecordSetChange =
rightResultOf( underTest.getRecordSetChange(sharedZone.id, pendingCreateSharedRecord.id, okAuth).value.unsafeRunSync().toOption.get
underTest.getRecordSetChange(sharedZone.id, pendingCreateSharedRecord.id, okAuth).value
)
actual shouldBe pendingCreateSharedRecord actual shouldBe pendingCreateSharedRecord
} }
@@ -1986,7 +1955,7 @@ class RecordSetServiceSpec
.when(mockRecordChangeRepo) .when(mockRecordChangeRepo)
.getRecordSetChange(okZone.id, pendingCreateAAAA.id) .getRecordSetChange(okZone.id, pendingCreateAAAA.id)
val error = val error =
leftResultOf(underTest.getRecordSetChange(okZone.id, pendingCreateAAAA.id, okAuth).value) underTest.getRecordSetChange(okZone.id, pendingCreateAAAA.id, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[RecordSetChangeNotFoundError] error shouldBe a[RecordSetChangeNotFoundError]
} }
@@ -1996,9 +1965,8 @@ class RecordSetServiceSpec
.when(mockRecordChangeRepo) .when(mockRecordChangeRepo)
.getRecordSetChange(zoneActive.id, pendingCreateAAAA.id) .getRecordSetChange(zoneActive.id, pendingCreateAAAA.id)
val error = leftResultOf( val error =
underTest.getRecordSetChange(zoneActive.id, pendingCreateAAAA.id, dummyAuth).value underTest.getRecordSetChange(zoneActive.id, pendingCreateAAAA.id, dummyAuth).value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -2009,15 +1977,14 @@ class RecordSetServiceSpec
.when(mockRecordChangeRepo) .when(mockRecordChangeRepo)
.getRecordSetChange(zoneNotAuthorized.id, pendingCreateSharedRecordNotSharedZone.id) .getRecordSetChange(zoneNotAuthorized.id, pendingCreateSharedRecordNotSharedZone.id)
val error = leftResultOf( val error =
underTest underTest
.getRecordSetChange( .getRecordSetChange(
zoneNotAuthorized.id, zoneNotAuthorized.id,
pendingCreateSharedRecordNotSharedZone.id, pendingCreateSharedRecordNotSharedZone.id,
okAuth okAuth
) )
.value .value.unsafeRunSync().swap.toOption.get
)
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -2025,17 +1992,17 @@ class RecordSetServiceSpec
"formatRecordNameFilter" should { "formatRecordNameFilter" should {
"return an FQDN from an IPv4 address" in { "return an FQDN from an IPv4 address" in {
rightResultOf(underTest.formatRecordNameFilter("10.10.0.25").value) shouldBe underTest.formatRecordNameFilter("10.10.0.25").value.unsafeRunSync().toOption.get shouldBe
"25.0.10.10.in-addr.arpa." "25.0.10.10.in-addr.arpa."
} }
"return an FQDN from an IPv6 address" in { "return an FQDN from an IPv6 address" in {
rightResultOf(underTest.formatRecordNameFilter("10.10.0.25").value) shouldBe underTest.formatRecordNameFilter("10.10.0.25").value.unsafeRunSync().toOption.get shouldBe
"25.0.10.10.in-addr.arpa." "25.0.10.10.in-addr.arpa."
} }
"return a string with a trailing dot" in { "return a string with a trailing dot" in {
rightResultOf(underTest.formatRecordNameFilter("thing.com").value) shouldBe underTest.formatRecordNameFilter("thing.com").value.unsafeRunSync().toOption.get shouldBe
"thing.com." "thing.com."
} }
} }

View File

@@ -25,7 +25,6 @@ import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.BeforeAndAfterEach import org.scalatest.BeforeAndAfterEach
import vinyldns.core.domain.record._ import vinyldns.core.domain.record._
import vinyldns.api.ResultHelpers
import cats.effect._ import cats.effect._
import org.mockito.Matchers.any import org.mockito.Matchers.any
import vinyldns.core.domain.Fqdn import vinyldns.core.domain.Fqdn
@@ -40,7 +39,6 @@ class ZoneConnectionValidatorSpec
with Matchers with Matchers
with MockitoSugar with MockitoSugar
with BeforeAndAfterEach with BeforeAndAfterEach
with ResultHelpers
with EitherMatchers with EitherMatchers
with EitherValues { with EitherValues {
@@ -153,7 +151,7 @@ class ZoneConnectionValidatorSpec
doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone]) doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone])
doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone]) doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone])
val result = awaitResultOf(underTest.validateZoneConnections(testZone).value) val result = underTest.validateZoneConnections(testZone).value.unsafeRunSync()
result should be(right) result should be(right)
} }
@@ -165,7 +163,7 @@ class ZoneConnectionValidatorSpec
doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone]) doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone])
doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone]) doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone])
val result = leftResultOf(underTest.validateZoneConnections(testZone).value) val result = underTest.validateZoneConnections(testZone).value.unsafeRunSync().swap.toOption.get
result shouldBe ZoneValidationFailed( result shouldBe ZoneValidationFailed(
testZone, testZone,
List(s"Name Server not.approved. is not an approved name server."), List(s"Name Server not.approved. is not an approved name server."),
@@ -182,7 +180,7 @@ class ZoneConnectionValidatorSpec
doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone]) doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone])
doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone]) doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone])
val result = leftResultOf(underTest.validateZoneConnections(testZone).value) val result = underTest.validateZoneConnections(testZone).value.unsafeRunSync().swap.toOption.get
result shouldBe a[ZoneValidationFailed] result shouldBe a[ZoneValidationFailed]
result shouldBe ZoneValidationFailed( result shouldBe ZoneValidationFailed(
testZone, testZone,
@@ -203,7 +201,7 @@ class ZoneConnectionValidatorSpec
doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone]) doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone])
doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone]) doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone])
val result = leftResultOf(underTest.validateZoneConnections(badZone).value) val result = underTest.validateZoneConnections(badZone).value.unsafeRunSync().swap.toOption.get
result shouldBe a[ConnectionFailed] result shouldBe a[ConnectionFailed]
} }
@@ -220,7 +218,7 @@ class ZoneConnectionValidatorSpec
doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone]) doReturn(IO.pure(true)).when(mockBackend).zoneExists(any[Zone])
doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone]) doReturn(mockBackend).when(mockBackendResolver).resolve(any[Zone])
val result = leftResultOf(underTest.validateZoneConnections(badZone).value) val result = underTest.validateZoneConnections(badZone).value.unsafeRunSync().swap.toOption.get
result shouldBe a[ConnectionFailed] result shouldBe a[ConnectionFailed]
result.getMessage should include("transfer connection failure!") result.getMessage should include("transfer connection failure!")
} }

View File

@@ -23,7 +23,6 @@ import org.scalatest.wordspec.AnyWordSpec
import org.scalatestplus.mockito.MockitoSugar import org.scalatestplus.mockito.MockitoSugar
import cats.implicits._ import cats.implicits._
import vinyldns.api.Interfaces._ import vinyldns.api.Interfaces._
import vinyldns.api.ResultHelpers
import cats.effect._ import cats.effect._
import org.scalatest.{BeforeAndAfterEach, EitherValues} import org.scalatest.{BeforeAndAfterEach, EitherValues}
import vinyldns.api.domain.access.AccessValidations import vinyldns.api.domain.access.AccessValidations
@@ -37,13 +36,10 @@ import vinyldns.core.TestZoneData._
import vinyldns.core.crypto.NoOpCrypto import vinyldns.core.crypto.NoOpCrypto
import vinyldns.core.domain.backend.BackendResolver import vinyldns.core.domain.backend.BackendResolver
import scala.concurrent.duration._
class ZoneServiceSpec class ZoneServiceSpec
extends AnyWordSpec extends AnyWordSpec
with Matchers with Matchers
with MockitoSugar with MockitoSugar
with ResultHelpers
with BeforeAndAfterEach with BeforeAndAfterEach
with EitherValues { with EitherValues {
@@ -109,9 +105,8 @@ class ZoneServiceSpec
"return an appropriate zone change response" in { "return an appropriate zone change response" in {
doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString) doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString)
val resultChange: ZoneChange = rightResultOf( val resultChange: ZoneChange =
underTest.connectToZone(createZoneAuthorized, okAuth).map(_.asInstanceOf[ZoneChange]).value underTest.connectToZone(createZoneAuthorized, okAuth).map(_.asInstanceOf[ZoneChange]).value.unsafeRunSync().toOption.get
)
resultChange.changeType shouldBe ZoneChangeType.Create resultChange.changeType shouldBe ZoneChangeType.Create
Option(resultChange.created) shouldBe defined Option(resultChange.created) shouldBe defined
@@ -131,12 +126,11 @@ class ZoneServiceSpec
doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString) doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString)
val nonTestUser = okAuth.copy(signedInUser = okAuth.signedInUser.copy(isTest = false)) val nonTestUser = okAuth.copy(signedInUser = okAuth.signedInUser.copy(isTest = false))
val resultChange: ZoneChange = rightResultOf( val resultChange: ZoneChange =
underTest underTest
.connectToZone(createZoneAuthorized, nonTestUser) .connectToZone(createZoneAuthorized, nonTestUser)
.map(_.asInstanceOf[ZoneChange]) .map(_.asInstanceOf[ZoneChange])
.value .value.unsafeRunSync().toOption.get
)
resultChange.zone.isTest shouldBe false resultChange.zone.isTest shouldBe false
} }
@@ -146,12 +140,11 @@ class ZoneServiceSpec
val testUser = okAuth.copy(signedInUser = okAuth.signedInUser.copy(isTest = true)) val testUser = okAuth.copy(signedInUser = okAuth.signedInUser.copy(isTest = true))
testUser.isTestUser shouldBe true testUser.isTestUser shouldBe true
val resultChange: ZoneChange = rightResultOf( val resultChange: ZoneChange =
underTest underTest
.connectToZone(createZoneAuthorized, testUser) .connectToZone(createZoneAuthorized, testUser)
.map(_.asInstanceOf[ZoneChange]) .map(_.asInstanceOf[ZoneChange])
.value .value.unsafeRunSync().toOption.get
)
resultChange.zone.isTest shouldBe true resultChange.zone.isTest shouldBe true
} }
@@ -159,7 +152,7 @@ class ZoneServiceSpec
"return a ZoneAlreadyExists error if the zone exists" in { "return a ZoneAlreadyExists error if the zone exists" in {
doReturn(IO.pure(Some(okZone))).when(mockZoneRepo).getZoneByName(anyString) doReturn(IO.pure(Some(okZone))).when(mockZoneRepo).getZoneByName(anyString)
val error = leftResultOf(underTest.connectToZone(createZoneAuthorized, okAuth).value) val error = underTest.connectToZone(createZoneAuthorized, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[ZoneAlreadyExistsError] error shouldBe a[ZoneAlreadyExistsError]
} }
@@ -168,7 +161,7 @@ class ZoneServiceSpec
doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString) doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString)
doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(anyString) doReturn(IO.pure(None)).when(mockGroupRepo).getGroup(anyString)
val error = leftResultOf(underTest.connectToZone(createZoneAuthorized, okAuth).value) val error = underTest.connectToZone(createZoneAuthorized, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidGroupError] error shouldBe an[InvalidGroupError]
} }
@@ -176,9 +169,9 @@ class ZoneServiceSpec
"allow the zone to be created if it exists and the zone is deleted" in { "allow the zone to be created if it exists and the zone is deleted" in {
doReturn(IO.pure(Some(zoneDeleted))).when(mockZoneRepo).getZoneByName(anyString) doReturn(IO.pure(Some(zoneDeleted))).when(mockZoneRepo).getZoneByName(anyString)
val resultChange: ZoneChange = rightResultOf( val resultChange: ZoneChange =
underTest.connectToZone(createZoneAuthorized, okAuth).map(_.asInstanceOf[ZoneChange]).value underTest.connectToZone(createZoneAuthorized, okAuth).map(_.asInstanceOf[ZoneChange]).value.unsafeRunSync().toOption.get
)
resultChange.changeType shouldBe ZoneChangeType.Create resultChange.changeType shouldBe ZoneChangeType.Create
} }
@@ -186,7 +179,7 @@ class ZoneServiceSpec
val badAcl = ACLRule(baseAclRuleInfo.copy(recordMask = Some("x{5,-3}"))) val badAcl = ACLRule(baseAclRuleInfo.copy(recordMask = Some("x{5,-3}")))
val newZone = createZoneAuthorized.copy(acl = ZoneACL(Set(badAcl))) val newZone = createZoneAuthorized.copy(acl = ZoneACL(Set(badAcl)))
val error = leftResultOf(underTest.connectToZone(newZone, okAuth).value) val error = underTest.connectToZone(newZone, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidRequest] error shouldBe an[InvalidRequest]
} }
@@ -194,9 +187,8 @@ class ZoneServiceSpec
val newZone = createZoneAuthorized.copy(shared = true) val newZone = createZoneAuthorized.copy(shared = true)
doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString) doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString)
val resultZone = rightResultOf( val resultZone =
underTest.connectToZone(newZone, superUserAuth).map(_.asInstanceOf[ZoneChange]).value underTest.connectToZone(newZone, superUserAuth).map(_.asInstanceOf[ZoneChange]).value.unsafeRunSync().toOption.get.zone
).zone
Option(resultZone.id) should not be None Option(resultZone.id) should not be None
resultZone.email shouldBe okZone.email resultZone.email shouldBe okZone.email
@@ -210,12 +202,11 @@ class ZoneServiceSpec
val newZone = createZoneAuthorized.copy(shared = true) val newZone = createZoneAuthorized.copy(shared = true)
doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString) doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString)
val resultZone = rightResultOf( val resultZone =
underTest underTest
.connectToZone(newZone, supportUserAuth) .connectToZone(newZone, supportUserAuth)
.map(_.asInstanceOf[ZoneChange]) .map(_.asInstanceOf[ZoneChange])
.value .value.unsafeRunSync().toOption.get.zone
).zone
Option(resultZone.id) should not be None Option(resultZone.id) should not be None
resultZone.email shouldBe okZone.email resultZone.email shouldBe okZone.email
@@ -229,14 +220,14 @@ class ZoneServiceSpec
val newZone = createZoneAuthorized.copy(shared = true) val newZone = createZoneAuthorized.copy(shared = true)
doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString) doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName(anyString)
val error = leftResultOf(underTest.connectToZone(newZone, okAuth).value) val error = underTest.connectToZone(newZone, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
"return an InvalidRequest if zone has a specified backend ID that is invalid" in { "return an InvalidRequest if zone has a specified backend ID that is invalid" in {
val newZone = createZoneAuthorized.copy(backendId = Some("badId")) val newZone = createZoneAuthorized.copy(backendId = Some("badId"))
val error = leftResultOf(underTest.connectToZone(newZone, okAuth).value) val error = underTest.connectToZone(newZone, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidRequest] error shouldBe an[InvalidRequest]
} }
} }
@@ -248,13 +239,11 @@ class ZoneServiceSpec
val doubleAuth = AuthPrincipal(TestDataLoader.okUser, Seq(twoUserGroup.id, okGroup.id)) val doubleAuth = AuthPrincipal(TestDataLoader.okUser, Seq(twoUserGroup.id, okGroup.id))
val updateZoneInput = updateZoneAuthorized.copy(adminGroupId = twoUserGroup.id) val updateZoneInput = updateZoneAuthorized.copy(adminGroupId = twoUserGroup.id)
val resultChange: ZoneChange = rightResultOf( val resultChange: ZoneChange =
underTest underTest
.updateZone(updateZoneInput, doubleAuth) .updateZone(updateZoneInput, doubleAuth)
.map(_.asInstanceOf[ZoneChange]) .map(_.asInstanceOf[ZoneChange])
.value, .value.unsafeRunSync().toOption.get
duration = 2.seconds
)
resultChange.zone.id shouldBe okZone.id resultChange.zone.id shouldBe okZone.id
resultChange.changeType shouldBe ZoneChangeType.Update resultChange.changeType shouldBe ZoneChangeType.Update
@@ -272,12 +261,11 @@ class ZoneServiceSpec
val doubleAuth = AuthPrincipal(TestDataLoader.okUser, Seq(okGroup.id, okGroup.id)) val doubleAuth = AuthPrincipal(TestDataLoader.okUser, Seq(okGroup.id, okGroup.id))
val resultChange: ZoneChange = val resultChange: ZoneChange =
rightResultOf(
underTest underTest
.updateZone(newZone, doubleAuth) .updateZone(newZone, doubleAuth)
.map(_.asInstanceOf[ZoneChange]) .map(_.asInstanceOf[ZoneChange])
.value .value.unsafeRunSync().toOption.get
)
resultChange.zone.id shouldBe oldZone.id resultChange.zone.id shouldBe oldZone.id
resultChange.zone.connection shouldBe oldZone.connection resultChange.zone.connection shouldBe oldZone.connection
} }
@@ -288,7 +276,7 @@ class ZoneServiceSpec
val newZone = val newZone =
updateZoneAuthorized.copy(connection = Some(badConnection), adminGroupId = okGroup.id) updateZoneAuthorized.copy(connection = Some(badConnection), adminGroupId = okGroup.id)
val error = leftResultOf(underTest.updateZone(newZone, okAuth).value) val error = underTest.updateZone(newZone, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[ConnectionFailed] error shouldBe a[ConnectionFailed]
} }
@@ -297,7 +285,7 @@ class ZoneServiceSpec
val noAuth = AuthPrincipal(TestDataLoader.okUser, Seq()) val noAuth = AuthPrincipal(TestDataLoader.okUser, Seq())
val error = leftResultOf(underTest.updateZone(updateZoneAuthorized, noAuth).value) val error = underTest.updateZone(updateZoneAuthorized, noAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -307,7 +295,7 @@ class ZoneServiceSpec
val badAcl = ACLRule(baseAclRuleInfo.copy(recordMask = Some("x{5,-3}"))) val badAcl = ACLRule(baseAclRuleInfo.copy(recordMask = Some("x{5,-3}")))
val newZone = updateZoneAuthorized.copy(acl = ZoneACL(Set(badAcl))) val newZone = updateZoneAuthorized.copy(acl = ZoneACL(Set(badAcl)))
val error = leftResultOf(underTest.updateZone(newZone, okAuth).value) val error = underTest.updateZone(newZone, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidRequest] error shouldBe an[InvalidRequest]
} }
@@ -317,11 +305,11 @@ class ZoneServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getZone(newZone.id) .getZone(newZone.id)
val result = rightResultOf( val result =
underTest underTest
.updateZone(newZone, AuthPrincipal(superUser, List.empty)) .updateZone(newZone, AuthPrincipal(superUser, List.empty))
.value .value.unsafeRunSync().toOption.get
)
result shouldBe a[ZoneChange] result shouldBe a[ZoneChange]
} }
@@ -331,11 +319,11 @@ class ZoneServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getZone(newZone.id) .getZone(newZone.id)
val result = rightResultOf( val result =
underTest underTest
.updateZone(newZone, supportUserAuth) .updateZone(newZone, supportUserAuth)
.value .value.unsafeRunSync().toOption.get
)
result shouldBe a[ZoneChange] result shouldBe a[ZoneChange]
} }
@@ -346,7 +334,7 @@ class ZoneServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getZone(newZone.id) .getZone(newZone.id)
val error = leftResultOf(underTest.updateZone(newZone, okAuth).value) val error = underTest.updateZone(newZone, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -356,13 +344,13 @@ class ZoneServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getZone(newZone.id) .getZone(newZone.id)
val result = rightResultOf(underTest.updateZone(newZone, okAuth).value) val result = underTest.updateZone(newZone, okAuth).value.unsafeRunSync().toOption.get
result shouldBe a[ZoneChange] result shouldBe a[ZoneChange]
} }
"return an InvalidRequest if zone has a specified backend ID that is invalid" in { "return an InvalidRequest if zone has a specified backend ID that is invalid" in {
val newZone = updateZoneAuthorized.copy(backendId = Some("badId")) val newZone = updateZoneAuthorized.copy(backendId = Some("badId"))
val error = leftResultOf(underTest.updateZone(newZone, okAuth).value) val error = underTest.updateZone(newZone, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidRequest] error shouldBe an[InvalidRequest]
} }
} }
@@ -372,7 +360,7 @@ class ZoneServiceSpec
doReturn(IO.pure(Some(okZone))).when(mockZoneRepo).getZone(anyString) doReturn(IO.pure(Some(okZone))).when(mockZoneRepo).getZone(anyString)
val resultChange: ZoneChange = val resultChange: ZoneChange =
rightResultOf(underTest.deleteZone(okZone.id, okAuth).map(_.asInstanceOf[ZoneChange]).value) underTest.deleteZone(okZone.id, okAuth).map(_.asInstanceOf[ZoneChange]).value.unsafeRunSync().toOption.get
resultChange.zone.id shouldBe okZone.id resultChange.zone.id shouldBe okZone.id
resultChange.changeType shouldBe ZoneChangeType.Delete resultChange.changeType shouldBe ZoneChangeType.Delete
@@ -383,7 +371,7 @@ class ZoneServiceSpec
val noAuth = AuthPrincipal(TestDataLoader.okUser, Seq()) val noAuth = AuthPrincipal(TestDataLoader.okUser, Seq())
val error = leftResultOf(underTest.deleteZone(okZone.id, noAuth).value) val error = underTest.deleteZone(okZone.id, noAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
} }
@@ -393,7 +381,7 @@ class ZoneServiceSpec
doReturn(IO.pure(Some(okZone))).when(mockZoneRepo).getZone(anyString) doReturn(IO.pure(Some(okZone))).when(mockZoneRepo).getZone(anyString)
val resultChange: ZoneChange = val resultChange: ZoneChange =
rightResultOf(underTest.syncZone(okZone.id, okAuth).map(_.asInstanceOf[ZoneChange]).value) underTest.syncZone(okZone.id, okAuth).map(_.asInstanceOf[ZoneChange]).value.unsafeRunSync().toOption.get
resultChange.zone.id shouldBe okZone.id resultChange.zone.id shouldBe okZone.id
resultChange.changeType shouldBe ZoneChangeType.Sync resultChange.changeType shouldBe ZoneChangeType.Sync
@@ -405,7 +393,7 @@ class ZoneServiceSpec
val noAuth = AuthPrincipal(TestDataLoader.okUser, Seq()) val noAuth = AuthPrincipal(TestDataLoader.okUser, Seq())
val error = leftResultOf(underTest.syncZone(okZone.id, noAuth).value) val error = underTest.syncZone(okZone.id, noAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
} }
@@ -414,7 +402,7 @@ class ZoneServiceSpec
"fail with no zone returned" in { "fail with no zone returned" in {
doReturn(IO.pure(None)).when(mockZoneRepo).getZone("notAZoneId") doReturn(IO.pure(None)).when(mockZoneRepo).getZone("notAZoneId")
val error = leftResultOf(underTest.getZone("notAZoneId", okAuth).value) val error = underTest.getZone("notAZoneId", okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[ZoneNotFoundError] error shouldBe a[ZoneNotFoundError]
} }
@@ -423,7 +411,7 @@ class ZoneServiceSpec
val noAuth = AuthPrincipal(TestDataLoader.okUser, Seq()) val noAuth = AuthPrincipal(TestDataLoader.okUser, Seq())
val error = leftResultOf(underTest.getZone(okZone.id, noAuth).value) val error = underTest.getZone(okZone.id, noAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -471,7 +459,7 @@ class ZoneServiceSpec
goodGroup.name, goodGroup.name,
AccessLevel.Delete AccessLevel.Delete
) )
val result: ZoneInfo = rightResultOf(underTest.getZone(zoneWithRules.id, abcAuth).value) val result: ZoneInfo = underTest.getZone(zoneWithRules.id, abcAuth).value.unsafeRunSync().toOption.get
result shouldBe expectedZoneInfo result shouldBe expectedZoneInfo
} }
@@ -485,14 +473,14 @@ class ZoneServiceSpec
val expectedZoneInfo = val expectedZoneInfo =
ZoneInfo(abcZone, ZoneACLInfo(Set()), "Unknown group name", AccessLevel.Delete) ZoneInfo(abcZone, ZoneACLInfo(Set()), "Unknown group name", AccessLevel.Delete)
val result: ZoneInfo = rightResultOf(underTest.getZone(abcZone.id, abcAuth).value) val result: ZoneInfo = underTest.getZone(abcZone.id, abcAuth).value.unsafeRunSync().toOption.get
result shouldBe expectedZoneInfo result shouldBe expectedZoneInfo
} }
"return a zone by name with failure when no zone is found" in { "return a zone by name with failure when no zone is found" in {
doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName("someZoneName.") doReturn(IO.pure(None)).when(mockZoneRepo).getZoneByName("someZoneName.")
val error = leftResultOf(underTest.getZoneByName("someZoneName", okAuth).value) val error = underTest.getZoneByName("someZoneName", okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[ZoneNotFoundError] error shouldBe a[ZoneNotFoundError]
} }
@@ -518,7 +506,7 @@ class ZoneServiceSpec
.listZones(abcAuth, None, None, 100, false) .listZones(abcAuth, None, None, 100, false)
doReturn(IO.pure(Set(abcGroup))).when(mockGroupRepo).getGroups(any[Set[String]]) doReturn(IO.pure(Set(abcGroup))).when(mockGroupRepo).getGroups(any[Set[String]])
val result: ListZonesResponse = rightResultOf(underTest.listZones(abcAuth).value) val result: ListZonesResponse = underTest.listZones(abcAuth).value.unsafeRunSync().toOption.get
result.zones shouldBe List() result.zones shouldBe List()
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.startFrom shouldBe None result.startFrom shouldBe None
@@ -535,7 +523,7 @@ class ZoneServiceSpec
.when(mockGroupRepo) .when(mockGroupRepo)
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListZonesResponse = rightResultOf(underTest.listZones(abcAuth).value) val result: ListZonesResponse = underTest.listZones(abcAuth).value.unsafeRunSync().toOption.get
result.zones shouldBe List(abcZoneSummary) result.zones shouldBe List(abcZoneSummary)
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.startFrom shouldBe None result.startFrom shouldBe None
@@ -553,7 +541,7 @@ class ZoneServiceSpec
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListZonesResponse = val result: ListZonesResponse =
rightResultOf(underTest.listZones(abcAuth, ignoreAccess = true).value) underTest.listZones(abcAuth, ignoreAccess = true).value.unsafeRunSync().toOption.get
result.zones shouldBe List(abcZoneSummary, xyzZoneSummary) result.zones shouldBe List(abcZoneSummary, xyzZoneSummary)
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.startFrom shouldBe None result.startFrom shouldBe None
@@ -573,7 +561,7 @@ class ZoneServiceSpec
// When searchByAdminGroup is true, zones are filtered by admin group name given in nameFilter // When searchByAdminGroup is true, zones are filtered by admin group name given in nameFilter
val result: ListZonesResponse = val result: ListZonesResponse =
rightResultOf(underTest.listZones(abcAuth, Some("abcGroup"), None, 100, searchByAdminGroup = true, ignoreAccess = true).value) underTest.listZones(abcAuth, Some("abcGroup"), None, 100, searchByAdminGroup = true, ignoreAccess = true).value.unsafeRunSync().toOption.get
result.zones shouldBe List(abcZoneSummary) result.zones shouldBe List(abcZoneSummary)
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.startFrom shouldBe None result.startFrom shouldBe None
@@ -592,7 +580,7 @@ class ZoneServiceSpec
// When searchByAdminGroup is false, zone name given in nameFilter is returned // When searchByAdminGroup is false, zone name given in nameFilter is returned
val result: ListZonesResponse = val result: ListZonesResponse =
rightResultOf(underTest.listZones(abcAuth, Some("abcZone"), None, 100, searchByAdminGroup = false, ignoreAccess = true).value) underTest.listZones(abcAuth, Some("abcZone"), None, 100, searchByAdminGroup = false, ignoreAccess = true).value.unsafeRunSync().toOption.get
result.zones shouldBe List(abcZoneSummary) result.zones shouldBe List(abcZoneSummary)
result.maxItems shouldBe 100 result.maxItems shouldBe 100
result.startFrom shouldBe None result.startFrom shouldBe None
@@ -607,7 +595,7 @@ class ZoneServiceSpec
.listZones(abcAuth, None, None, 100, false) .listZones(abcAuth, None, None, 100, false)
doReturn(IO.pure(Set(okGroup))).when(mockGroupRepo).getGroups(any[Set[String]]) doReturn(IO.pure(Set(okGroup))).when(mockGroupRepo).getGroups(any[Set[String]])
val result: ListZonesResponse = rightResultOf(underTest.listZones(abcAuth).value) val result: ListZonesResponse = underTest.listZones(abcAuth).value.unsafeRunSync().toOption.get
val expectedZones = val expectedZones =
List(abcZoneSummary, xyzZoneSummary).map(_.copy(adminGroupName = "Unknown group name")) List(abcZoneSummary, xyzZoneSummary).map(_.copy(adminGroupName = "Unknown group name"))
result.zones shouldBe expectedZones result.zones shouldBe expectedZones
@@ -634,7 +622,7 @@ class ZoneServiceSpec
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListZonesResponse = val result: ListZonesResponse =
rightResultOf(underTest.listZones(abcAuth, maxItems = 2).value) underTest.listZones(abcAuth, maxItems = 2).value.unsafeRunSync().toOption.get
result.zones shouldBe List(abcZoneSummary, xyzZoneSummary) result.zones shouldBe List(abcZoneSummary, xyzZoneSummary)
result.maxItems shouldBe 2 result.maxItems shouldBe 2
result.startFrom shouldBe None result.startFrom shouldBe None
@@ -660,7 +648,7 @@ class ZoneServiceSpec
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListZonesResponse = val result: ListZonesResponse =
rightResultOf(underTest.listZones(abcAuth, nameFilter = Some("foo"), maxItems = 2).value) underTest.listZones(abcAuth, nameFilter = Some("foo"), maxItems = 2).value.unsafeRunSync().toOption.get
result.zones shouldBe List(abcZoneSummary, xyzZoneSummary) result.zones shouldBe List(abcZoneSummary, xyzZoneSummary)
result.nameFilter shouldBe Some("foo") result.nameFilter shouldBe Some("foo")
result.nextId shouldBe Some("zone2.") result.nextId shouldBe Some("zone2.")
@@ -684,7 +672,7 @@ class ZoneServiceSpec
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListZonesResponse = val result: ListZonesResponse =
rightResultOf(underTest.listZones(abcAuth, startFrom = Some("zone4."), maxItems = 2).value) underTest.listZones(abcAuth, startFrom = Some("zone4."), maxItems = 2).value.unsafeRunSync().toOption.get
result.zones shouldBe List(abcZoneSummary, xyzZoneSummary) result.zones shouldBe List(abcZoneSummary, xyzZoneSummary)
result.startFrom shouldBe Some("zone4.") result.startFrom shouldBe Some("zone4.")
} }
@@ -707,7 +695,7 @@ class ZoneServiceSpec
.getGroups(any[Set[String]]) .getGroups(any[Set[String]])
val result: ListZonesResponse = val result: ListZonesResponse =
rightResultOf(underTest.listZones(abcAuth, startFrom = Some("zone4."), maxItems = 2).value) underTest.listZones(abcAuth, startFrom = Some("zone4."), maxItems = 2).value.unsafeRunSync().toOption.get
result.zones shouldBe List(abcZoneSummary, xyzZoneSummary) result.zones shouldBe List(abcZoneSummary, xyzZoneSummary)
result.nextId shouldBe Some("zone6.") result.nextId shouldBe Some("zone6.")
} }
@@ -723,7 +711,7 @@ class ZoneServiceSpec
.listZoneChanges(okZone.id, startFrom = None, maxItems = 100) .listZoneChanges(okZone.id, startFrom = None, maxItems = 100)
val result: ListZoneChangesResponse = val result: ListZoneChangesResponse =
rightResultOf(underTest.listZoneChanges(okZone.id, okAuth).value) underTest.listZoneChanges(okZone.id, okAuth).value.unsafeRunSync().toOption.get
result.zoneChanges shouldBe List(zoneUpdate, zoneCreate) result.zoneChanges shouldBe List(zoneUpdate, zoneCreate)
result.zoneId shouldBe okZone.id result.zoneId shouldBe okZone.id
@@ -738,7 +726,7 @@ class ZoneServiceSpec
.listZoneChanges(okZone.id, startFrom = None, maxItems = 100) .listZoneChanges(okZone.id, startFrom = None, maxItems = 100)
val result: ListZoneChangesResponse = val result: ListZoneChangesResponse =
rightResultOf(underTest.listZoneChanges(okZone.id, okAuth).value) underTest.listZoneChanges(okZone.id, okAuth).value.unsafeRunSync().toOption.get
result.zoneChanges shouldBe empty result.zoneChanges shouldBe empty
result.zoneId shouldBe okZone.id result.zoneId shouldBe okZone.id
@@ -749,7 +737,7 @@ class ZoneServiceSpec
.when(mockZoneRepo) .when(mockZoneRepo)
.getZone(zoneNotAuthorized.id) .getZone(zoneNotAuthorized.id)
val error = leftResultOf(underTest.listZoneChanges(zoneNotAuthorized.id, okAuth).value) val error = underTest.listZoneChanges(zoneNotAuthorized.id, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -764,7 +752,7 @@ class ZoneServiceSpec
.listZoneChanges(zoneId = okZone.id, startFrom = None, maxItems = 100) .listZoneChanges(zoneId = okZone.id, startFrom = None, maxItems = 100)
val result: ListZoneChangesResponse = val result: ListZoneChangesResponse =
rightResultOf(underTest.listZoneChanges(okZone.id, okAuth).value) underTest.listZoneChanges(okZone.id, okAuth).value.unsafeRunSync().toOption.get
result.zoneChanges.head shouldBe zoneUpdate result.zoneChanges.head shouldBe zoneUpdate
result.zoneChanges(1) shouldBe zoneCreate result.zoneChanges(1) shouldBe zoneCreate
@@ -776,19 +764,18 @@ class ZoneServiceSpec
doReturn(IO.pure(Some(zoneNotAuthorized))).when(mockZoneRepo).getZone(anyString) doReturn(IO.pure(Some(zoneNotAuthorized))).when(mockZoneRepo).getZone(anyString)
val error = val error =
leftResultOf(underTest.addACLRule(zoneNotAuthorized.id, baseAclRuleInfo, okAuth).value) underTest.addACLRule(zoneNotAuthorized.id, baseAclRuleInfo, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
"generate a zone update if the request is valid" in { "generate a zone update if the request is valid" in {
doReturn(IO.pure(Some(okZone))).when(mockZoneRepo).getZone(anyString) doReturn(IO.pure(Some(okZone))).when(mockZoneRepo).getZone(anyString)
val result: ZoneChange = rightResultOf( val result: ZoneChange =
underTest underTest
.addACLRule(okZone.id, userAclRuleInfo, okAuth) .addACLRule(okZone.id, userAclRuleInfo, okAuth)
.map(_.asInstanceOf[ZoneChange]) .map(_.asInstanceOf[ZoneChange])
.value .value.unsafeRunSync().toOption.get
)
result.changeType shouldBe ZoneChangeType.Update result.changeType shouldBe ZoneChangeType.Update
result.zone.acl.rules.size shouldBe 1 result.zone.acl.rules.size shouldBe 1
@@ -800,7 +787,7 @@ class ZoneServiceSpec
val invalidRegexMaskRuleInfo = baseAclRuleInfo.copy(recordMask = Some("x{5,-3}")) val invalidRegexMaskRuleInfo = baseAclRuleInfo.copy(recordMask = Some("x{5,-3}"))
val error = val error =
leftResultOf(underTest.addACLRule(okZone.id, invalidRegexMaskRuleInfo, okAuth).value) underTest.addACLRule(okZone.id, invalidRegexMaskRuleInfo, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe an[InvalidRequest] error shouldBe an[InvalidRequest]
} }
} }
@@ -810,7 +797,7 @@ class ZoneServiceSpec
doReturn(IO.pure(Some(zoneNotAuthorized))).when(mockZoneRepo).getZone(anyString) doReturn(IO.pure(Some(zoneNotAuthorized))).when(mockZoneRepo).getZone(anyString)
val error = val error =
leftResultOf(underTest.deleteACLRule(zoneNotAuthorized.id, baseAclRuleInfo, okAuth).value) underTest.deleteACLRule(zoneNotAuthorized.id, baseAclRuleInfo, okAuth).value.unsafeRunSync().swap.toOption.get
error shouldBe a[NotAuthorizedError] error shouldBe a[NotAuthorizedError]
} }
@@ -819,12 +806,11 @@ class ZoneServiceSpec
val zone = okZone.copy(acl = acl) val zone = okZone.copy(acl = acl)
doReturn(IO.pure(Some(zone))).when(mockZoneRepo).getZone(anyString) doReturn(IO.pure(Some(zone))).when(mockZoneRepo).getZone(anyString)
val result: ZoneChange = rightResultOf( val result: ZoneChange =
underTest underTest
.deleteACLRule(zone.id, userAclRuleInfo, okAuth) .deleteACLRule(zone.id, userAclRuleInfo, okAuth)
.map(_.asInstanceOf[ZoneChange]) .map(_.asInstanceOf[ZoneChange])
.value .value.unsafeRunSync().toOption.get
)
result.changeType shouldBe ZoneChangeType.Update result.changeType shouldBe ZoneChangeType.Update
result.zone.acl.rules.size shouldBe 0 result.zone.acl.rules.size shouldBe 0

View File

@@ -24,7 +24,6 @@ import org.mockito.Mockito.{doReturn, verify}
import org.scalatest.BeforeAndAfterEach import org.scalatest.BeforeAndAfterEach
import org.scalatest.wordspec.AnyWordSpec import org.scalatest.wordspec.AnyWordSpec
import org.scalatestplus.mockito.MockitoSugar import org.scalatestplus.mockito.MockitoSugar
import vinyldns.api.CatsHelpers
import vinyldns.api.repository.InMemoryBatchChangeRepository import vinyldns.api.repository.InMemoryBatchChangeRepository
import vinyldns.core.domain.batch._ import vinyldns.core.domain.batch._
import vinyldns.core.domain.record._ import vinyldns.core.domain.record._
@@ -35,8 +34,7 @@ import scala.concurrent.ExecutionContext
class BatchChangeHandlerSpec class BatchChangeHandlerSpec
extends AnyWordSpec extends AnyWordSpec
with MockitoSugar with MockitoSugar
with BeforeAndAfterEach with BeforeAndAfterEach {
with CatsHelpers {
implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.global implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.global
implicit val contextShift: ContextShift[IO] = IO.contextShift(ec) implicit val contextShift: ContextShift[IO] = IO.contextShift(ec)
@@ -77,7 +75,7 @@ class BatchChangeHandlerSpec
"notify on batch change complete" in { "notify on batch change complete" in {
doReturn(IO.unit).when(mockNotifier).notify(any[Notification[_]]) doReturn(IO.unit).when(mockNotifier).notify(any[Notification[_]])
await(batchRepo.save(completedBatchChange)) batchRepo.save(completedBatchChange).unsafeRunSync()
BatchChangeHandler BatchChangeHandler
.process(batchRepo, notifiers, BatchChangeCommand(completedBatchChange.id)) .process(batchRepo, notifiers, BatchChangeCommand(completedBatchChange.id))
@@ -92,7 +90,7 @@ class BatchChangeHandlerSpec
val partiallyFailedBatchChange = val partiallyFailedBatchChange =
completedBatchChange.copy(changes = List(addChange.copy(status = SingleChangeStatus.Failed))) completedBatchChange.copy(changes = List(addChange.copy(status = SingleChangeStatus.Failed)))
await(batchRepo.save(partiallyFailedBatchChange)) batchRepo.save(partiallyFailedBatchChange).unsafeRunSync()
BatchChangeHandler BatchChangeHandler
.process(batchRepo, notifiers, BatchChangeCommand(partiallyFailedBatchChange.id)) .process(batchRepo, notifiers, BatchChangeCommand(partiallyFailedBatchChange.id))

View File

@@ -29,7 +29,6 @@ import org.scalatest.{BeforeAndAfterEach, EitherValues}
import vinyldns.api.backend.dns.DnsProtocol.{NotAuthorized, TryAgain} import vinyldns.api.backend.dns.DnsProtocol.{NotAuthorized, TryAgain}
import vinyldns.api.engine.RecordSetChangeHandler.{AlreadyApplied, ReadyToApply, Requeue} import vinyldns.api.engine.RecordSetChangeHandler.{AlreadyApplied, ReadyToApply, Requeue}
import vinyldns.api.repository.InMemoryBatchChangeRepository import vinyldns.api.repository.InMemoryBatchChangeRepository
import vinyldns.api.CatsHelpers
import vinyldns.core.domain.batch.{BatchChange, BatchChangeApprovalStatus, SingleAddChange, SingleChangeStatus} import vinyldns.core.domain.batch.{BatchChange, BatchChangeApprovalStatus, SingleAddChange, SingleChangeStatus}
import vinyldns.core.domain.record.RecordType.RecordType import vinyldns.core.domain.record.RecordType.RecordType
import vinyldns.core.domain.record.{ChangeSet, RecordChangeRepository, RecordSetRepository, _} import vinyldns.core.domain.record.{ChangeSet, RecordChangeRepository, RecordSetRepository, _}
@@ -46,7 +45,6 @@ class RecordSetChangeHandlerSpec
with Matchers with Matchers
with MockitoSugar with MockitoSugar
with BeforeAndAfterEach with BeforeAndAfterEach
with CatsHelpers
with EitherValues with EitherValues
with TransactionProvider { with TransactionProvider {
@@ -116,7 +114,7 @@ class RecordSetChangeHandlerSpec
batchRepo.clear() batchRepo.clear()
// seed the linked batch change in the DB // seed the linked batch change in the DB
await(batchRepo.save(batchChange)) batchRepo.save(batchChange).unsafeRunSync()
doReturn(IO.pure(Nil)) doReturn(IO.pure(Nil))
.when(mockRsRepo) .when(mockRsRepo)
@@ -151,7 +149,7 @@ class RecordSetChangeHandlerSpec
savedCs.status shouldBe ChangeSetStatus.Complete savedCs.status shouldBe ChangeSetStatus.Complete
savedCs.changes.head.status shouldBe RecordSetChangeStatus.Complete savedCs.changes.head.status shouldBe RecordSetChangeStatus.Complete
val batchChangeUpdates = await(batchRepo.getBatchChange(batchChange.id)) val batchChangeUpdates = batchRepo.getBatchChange(batchChange.id).unsafeRunSync()
val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch => val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch =>
ch.copy( ch.copy(
systemMessage= None, systemMessage= None,
@@ -197,7 +195,7 @@ class RecordSetChangeHandlerSpec
verify(mockBackend).applyChange(rsChange) verify(mockBackend).applyChange(rsChange)
verify(mockBackend, times(2)).resolve(rs.name, rsChange.zone.name, rs.typ) verify(mockBackend, times(2)).resolve(rs.name, rsChange.zone.name, rs.typ)
val batchChangeUpdates = await(batchRepo.getBatchChange(batchChange.id)) val batchChangeUpdates = batchRepo.getBatchChange(batchChange.id).unsafeRunSync()
val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch => val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch =>
ch.copy( ch.copy(
systemMessage= None, systemMessage= None,
@@ -248,7 +246,7 @@ class RecordSetChangeHandlerSpec
// make sure we only called resolve once when validating, ensures that verify was not called // make sure we only called resolve once when validating, ensures that verify was not called
verify(mockBackend, times(1)).resolve(rs.name, rsChange.zone.name, rs.typ) verify(mockBackend, times(1)).resolve(rs.name, rsChange.zone.name, rs.typ)
val batchChangeUpdates = await(batchRepo.getBatchChange(batchChange.id)) val batchChangeUpdates = batchRepo.getBatchChange(batchChange.id).unsafeRunSync()
val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch => val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch =>
ch.copy( ch.copy(
status = SingleChangeStatus.Failed, status = SingleChangeStatus.Failed,
@@ -294,7 +292,7 @@ class RecordSetChangeHandlerSpec
// we will retry the verify 3 times based on the mock setup // we will retry the verify 3 times based on the mock setup
verify(mockBackend, times(2)).resolve(rs.name, rsChange.zone.name, rs.typ) verify(mockBackend, times(2)).resolve(rs.name, rsChange.zone.name, rs.typ)
val batchChangeUpdates = await(batchRepo.getBatchChange(batchChange.id)) val batchChangeUpdates = batchRepo.getBatchChange(batchChange.id).unsafeRunSync()
val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch => val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch =>
ch.copy( ch.copy(
status = SingleChangeStatus.Failed, status = SingleChangeStatus.Failed,
@@ -350,7 +348,7 @@ class RecordSetChangeHandlerSpec
verify(mockBackend, never()).applyChange(rsChange) verify(mockBackend, never()).applyChange(rsChange)
verify(mockBackend, times(1)).resolve(rs.name, rsChange.zone.name, rs.typ) verify(mockBackend, times(1)).resolve(rs.name, rsChange.zone.name, rs.typ)
val batchChangeUpdates = await(batchRepo.getBatchChange(batchChange.id)) val batchChangeUpdates = batchRepo.getBatchChange(batchChange.id).unsafeRunSync()
val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch => val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch =>
ch.copy( ch.copy(
status = SingleChangeStatus.Failed, status = SingleChangeStatus.Failed,
@@ -393,7 +391,7 @@ class RecordSetChangeHandlerSpec
verify(mockBackend, times(1)).applyChange(rsChange) verify(mockBackend, times(1)).applyChange(rsChange)
verify(mockBackend, times(1)).resolve(rs.name, rsChange.zone.name, rs.typ) verify(mockBackend, times(1)).resolve(rs.name, rsChange.zone.name, rs.typ)
val batchChangeUpdates = await(batchRepo.getBatchChange(batchChange.id)) val batchChangeUpdates = batchRepo.getBatchChange(batchChange.id).unsafeRunSync()
val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch => val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch =>
ch.copy( ch.copy(
status = SingleChangeStatus.Failed, status = SingleChangeStatus.Failed,
@@ -448,7 +446,7 @@ class RecordSetChangeHandlerSpec
// make sure we never called resolve, as we skip validate step and verify // make sure we never called resolve, as we skip validate step and verify
verify(mockBackend, never).resolve(rs.name, rsChange.zone.name, rs.typ) verify(mockBackend, never).resolve(rs.name, rsChange.zone.name, rs.typ)
val batchChangeUpdates = await(batchRepo.getBatchChange(batchChange.id)) val batchChangeUpdates = batchRepo.getBatchChange(batchChange.id).unsafeRunSync()
val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch => val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch =>
ch.copy( ch.copy(
status = SingleChangeStatus.Complete, status = SingleChangeStatus.Complete,
@@ -602,7 +600,7 @@ class RecordSetChangeHandlerSpec
savedCs.status shouldBe ChangeSetStatus.Complete savedCs.status shouldBe ChangeSetStatus.Complete
savedCs.changes.head.status shouldBe RecordSetChangeStatus.Complete savedCs.changes.head.status shouldBe RecordSetChangeStatus.Complete
val batchChangeUpdates = await(batchRepo.getBatchChange(batchChange.id)) val batchChangeUpdates = batchRepo.getBatchChange(batchChange.id).unsafeRunSync()
val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch => val updatedSingleChanges = completeCreateAAAASingleChanges.map { ch =>
ch.copy( ch.copy(
systemMessage= None, systemMessage= None,