From 4b181cb733809b449db604913b0b806ec013e529 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Thu, 18 Apr 2024 12:16:12 +0545 Subject: [PATCH] fix(test): do not try to delete already deleted groups --- .../features/bootstrap/GraphContext.php | 27 ++++---------- .../features/bootstrap/Provisioning.php | 35 +++++++++++-------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 2d06a49d69e..d19e6211d39 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -274,7 +274,7 @@ public function adminHasRetrievedUserUsingTheGraphApi(string $user): ResponseInt * @return ResponseInterface * @throws GuzzleException */ - public function userDeletesGroupWithGroupId( + public function deleteGroupWithId( string $groupId, ?string $user = null ): ResponseInterface { @@ -289,31 +289,18 @@ public function userDeletesGroupWithGroupId( ); } - /** - * @param string $groupId - * - * @return void - * @throws GuzzleException - */ - public function adminDeletesGroupWithGroupId( - string $groupId - ): void { - $response = $this->userDeletesGroupWithGroupId($groupId); - $this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response); - } - /** * @param string $group * - * @return void + * @return ResponseInterface * @throws Exception * @throws GuzzleException */ - public function adminDeletesGroupUsingTheGraphApi( + public function deleteGroupWithName( string $group - ): void { + ): ResponseInterface { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); - $this->adminDeletesGroupWithGroupId($groupId); + return $this->deleteGroupWithId($groupId); } /** @@ -1054,7 +1041,7 @@ public function userRetrievesAllMemberInformationOfSingleOrAllGroups(string $use */ public function userDeletesGroupUsingTheGraphApi(string $group, ?string $user = null): void { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); - $response = $this->userDeletesGroupWithGroupId($groupId, $user); + $response = $this->deleteGroupWithId($groupId, $user); $this->featureContext->setResponse($response); } @@ -1067,7 +1054,7 @@ public function userDeletesGroupUsingTheGraphApi(string $group, ?string $user = */ public function theAdministratorHasDeletedGroup(string $group): void { $groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id"); - $response = $this->userDeletesGroupWithGroupId($groupId); + $response = $this->deleteGroupWithId($groupId); $this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response); } diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 0a8c1b22ba6..aa34a80b801 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -2213,6 +2213,7 @@ public function rememberThatUserIsNotExpectedToExist(string $user):void { $normalizedUsername = $this->normalizeUsername($user); if (\array_key_exists($normalizedUsername, $this->createdUsers)) { $this->createdUsers[$normalizedUsername]['shouldExist'] = false; + $this->createdUsers[$normalizedUsername]['possibleToDelete'] = false; } } @@ -2316,7 +2317,8 @@ public function cleanupGroup(string $group):void { if ($this->isTestingWithLdap()) { $this->deleteLdapGroup($group); } else { - $this->graphContext->adminDeletesGroupUsingTheGraphApi($group); + $response = $this->graphContext->deleteGroupWithName($group); + $this->theHTTPStatusCodeShouldBe(204, "", $response); } } catch (Exception $e) { \error_log( @@ -2623,6 +2625,7 @@ public function addGroupToCreatedGroupsList( public function rememberThatGroupIsNotExpectedToExist(string $group):void { if (\array_key_exists($group, $this->createdGroups)) { $this->createdGroups[$group]['shouldExist'] = false; + $this->createdGroups[$group]['possibleToDelete'] = false; } } @@ -3121,8 +3124,10 @@ public function groupHasBeenDeleted(string $group):void { if ($this->isTestingWithLdap()) { $this->deleteLdapGroup($group); } else { - $this->graphContext->adminDeletesGroupUsingTheGraphApi($group); + $response = $this->graphContext->deleteGroupWithName($group); + $this->theHTTPStatusCodeShouldBe(204, "", $response); } + $this->rememberThatGroupIsNotExpectedToExist($group); $this->groupShouldNotExist($group); } @@ -4247,22 +4252,24 @@ public function cleanupDatabaseGroups():void { $previousServer = $this->currentServer; $this->usingServer('LOCAL'); foreach ($this->createdGroups as $group => $groupData) { - if ($this->isTestingWithLdap()) { - $this->cleanupGroup((string)$group); - } else { - $this->graphContext->adminDeletesGroupWithGroupId( - $groupData['id'] - ); + if ($groupData["possibleToDelete"]) { + if ($this->isTestingWithLdap()) { + $this->cleanupGroup((string)$group); + } else { + $response = $this->graphContext->deleteGroupWithId($groupData['id']); + $this->theHTTPStatusCodeShouldBe(204, "", $response); + } } } $this->usingServer('REMOTE'); foreach ($this->createdRemoteGroups as $remoteGroup => $groupData) { - if ($this->isTestingWithLdap()) { - $this->cleanupGroup((string)$remoteGroup); - } else { - $this->graphContext->adminDeletesGroupWithGroupId( - $groupData['id'] - ); + if ($groupData["possibleToDelete"]) { + if ($this->isTestingWithLdap()) { + $this->cleanupGroup((string)$remoteGroup); + } else { + $response = $this->graphContext->deleteGroupWithId($groupData['id']); + $this->theHTTPStatusCodeShouldBe(204, "", $response); + } } } $this->usingServer($previousServer);