[tests-only][full-ci]Refactor test function for handeling errors (#5745)

* Refactor test function for handeling errors

* fix return types

* clean up code

* address reviews
This commit is contained in:
Swikriti Tripathi authored and GitHub committed 2023-03-08 12:55:03 +05:45
1 parent 950f17543b
commit da94701dca
4 files changed
+9 -19

No files matched your search

@@ -198,7 +198,7 @@ Feature: add users to group
| username |
| Brian |
And user "Alice" has created a group "grp1" using the Graph API
When the administrator "Alice" tries to add the following users to a group "grp1" at once using the Graph API
When the administrator "Alice" tries to add the following existent and nonexistent users to a group "grp1" at once using the Graph API
| username |
| Brian |
| Carol |
@@ -4627,7 +4627,7 @@ class FeatureContext extends BehatVariablesContext {
* @return string
* @throws Exception|GuzzleException
*/
public function getGroupIdByGroupName(string $groupName): string {
public function getGroupIdByGroupName(string $groupName):string {
$response = GraphHelper::getGroup(
$this->getBaseUrl(),
$this->getStepLineRef(),
@@ -241,12 +241,8 @@ class GraphContext implements Context {
*/
public function adminHasRetrievedUserUsingTheGraphApi(string $user): void {
$user = $this->featureContext->getActualUsername($user);
try {
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$userId = $userId ?? $user;
} catch (Exception $e) {
$userId = $user;
}
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$userId = $userId ? $userId : $user;
$result = GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
@@ -1747,6 +1743,7 @@ class GraphContext implements Context {
/**
* @When /^the administrator "([^"]*)" tries to add the following users to a group "([^"]*)" at once using the Graph API$/
* @When /^the administrator "([^"]*)" tries to add the following existent and nonexistent users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
@@ -1760,11 +1757,8 @@ class GraphContext implements Context {
$userIds = [];
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
foreach ($table->getHash() as $row) {
try {
$userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
} catch (Exception $e) {
$userIds[] = WebDavHelper::generateUUIDv4();
}
$userId = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
$userIds[] = $userId ? $userId : WebDavHelper::generateUUIDv4();
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
}
@@ -265,9 +265,7 @@ trait Provisioning {
);
}
} else {
throw new Exception(
__METHOD__ . ": User '$user' does not exist in the created list."
);
return false;
}
}
@@ -296,9 +294,7 @@ trait Provisioning {
);
}
} else {
throw new Exception(
__METHOD__ . ": Group '$group' does not exist in the created list."
);
return false;
}
}