Skip to content

Commit

Permalink
fix(test): do not try to delete already deleted groups
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Apr 18, 2024
1 parent 65213ab commit 4b181cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
27 changes: 7 additions & 20 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
35 changes: 21 additions & 14 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4b181cb

Please sign in to comment.