2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-09-02 07:15:24 +00:00

Delete Group - Delete the Group from DynamoDB (#548)

This commit is contained in:
Varsha Chandrashekar
2019-03-29 14:38:23 -04:00
committed by GitHub
parent 9cb8df007b
commit defb05c3bc
3 changed files with 45 additions and 1 deletions

View File

@@ -165,5 +165,30 @@ class DynamoDBGroupRepositoryIntegrationSpec extends DynamoDBIntegrationSpec {
test.unsafeRunSync().get.description shouldBe None
}
"add and delete a group should return successfully" in {
val deleted = deletedGroup.copy(
id = "test-deleted-group-get-groups",
memberIds = Set("foo"),
adminUserIds = Set("foo"))
val f =
for {
_ <- repo.save(deleted)
retrieved <- repo.delete(deleted)
} yield retrieved
f.unsafeRunSync().id shouldBe deleted.id
val getAfterDeleted =
for {
get <- repo.getGroup("test-deleted-group-get-groups")
getAll <- repo.getAllGroups()
} yield (get, getAll)
val (get, getAll) = getAfterDeleted.unsafeRunSync()
get shouldBe None
getAll.filter(_.id == "test-deleted-group-get-groups") shouldBe Set.empty
getAll.filter(_.id == activeGroups.head.id) shouldBe Set(activeGroups.head)
}
}
}

View File

@@ -99,7 +99,13 @@ class DynamoDBGroupRepository private[repository] (
}
def delete(group: Group): IO[Group] =
save(group.copy(status = GroupStatus.Deleted))
monitor("repo.Group.delete") {
log.info(s"Deleting group ${group.id} ${group.name}.")
val key = new HashMap[String, AttributeValue]()
key.put(GROUP_ID, new AttributeValue(group.id))
val request = new DeleteItemRequest().withTableName(groupTableName).withKey(key)
dynamoDBHelper.deleteItem(request).map(_ => group)
}
/*Looks up a group. If the group is not found, or if the group's status is Deleted, will return None */
def getGroup(groupId: String): IO[Option[Group]] =

View File

@@ -268,4 +268,17 @@ class DynamoDBGroupRepositorySpec
a[ResourceNotFoundException] shouldBe thrownBy(result.unsafeRunSync())
}
}
"DynamoDBGroupRepository.delete" should {
"return a deleted group on delete" in {
val mockDeleteItemRequest = mock[DeleteItemResult]
doReturn(IO.pure(mockDeleteItemRequest))
.when(dynamoDBHelper)
.deleteItem(any[DeleteItemRequest])
val response = underTest.delete(okGroup).unsafeRunSync()
response shouldBe okGroup
}
}
}