Seperate test steps for positive and negative cases (#5773)

fix php style

use the correct step

fix other steps

fix other php style

remove unwanted param

Refactor test function for handeling errors

fix return types

clean up code

address reviews
This commit is contained in:
Swikriti Tripathi
2023-03-09 16:21:50 +05:45
committed by GitHub
parent d9092d7e17
commit 249adc7cd7
5 changed files with 65 additions and 48 deletions

View File

@@ -136,7 +136,7 @@ Feature: add users to group
Scenario: admin tries to add user to a non-existing group
When the administrator tries to add user "Alice" to group "nonexistentgroup" using the Graph API
When the administrator tries to add user "Alice" to a nonexistent group using the Graph API
Then the HTTP status code should be "404"
@@ -147,7 +147,7 @@ Feature: add users to group
Scenario: admin tries to add user to a group without sending the group
When the administrator tries to add user "Alice" to group "" using the Graph API
When the administrator tries to add user "Alice" to a nonexistent group using the Graph API
Then the HTTP status code should be "404"
@@ -175,7 +175,7 @@ Feature: add users to group
| username |
| Brian |
| Carol |
When the administrator "Alice" tries to add the following users to a non-existing group at once using the Graph API
When the administrator "Alice" tries to add the following users to a nonexistent group at once using the Graph API
| username |
| Brian |
| Carol |
@@ -185,7 +185,7 @@ Feature: add users to group
Scenario: admin tries to add multiple non-existing users to a group at once
Given the administrator has given "Alice" the role "Admin" using the settings api
And user "Alice" has created a group "grp1" using the Graph API
When the administrator "Alice" tries to add the following non-existing users to a group "grp1" at once using the Graph API
When the administrator "Alice" tries to add the following nonexistent users to a group "grp1" at once using the Graph API
| username |
| Brian |
| Carol |
@@ -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 |

View File

@@ -152,8 +152,8 @@ Feature: remove a user from a group
| Alice | var/../etc |
Scenario: admin tries to remove a user from a non-existing group
When the administrator tries to remove user "Alice" from group "nonexistentgroup" using the Graph API
Scenario: admin tries to remove a user from a nonexistent group
When the administrator tries to remove user "Alice" from a nonexistent group using the Graph API
Then the HTTP status code should be "404"

View File

@@ -4600,7 +4600,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(),

View File

@@ -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(),
@@ -816,17 +812,8 @@ class GraphContext implements Context {
*/
public function addUserToGroup(string $group, string $user, ?string $byUser = null): ResponseInterface {
$credentials = $this->getAdminOrUserCredentials($byUser);
try {
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
} catch (Exception $e) {
$groupId = WebDavHelper::generateUUIDv4();
}
try {
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
} catch (Exception $e) {
$userId = WebDavHelper::generateUUIDv4();
}
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
return GraphHelper::addUserToGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
@@ -888,6 +875,33 @@ class GraphContext implements Context {
$this->featureContext->setResponse($this->addUserToGroup($group, $user));
}
/**
* @When the administrator tries to add user :user to a nonexistent group using the Graph API
* @When the user :byUser tries to add user :user to a nonexistent group using the Graph API
*
* @param string $user
* @param string|null $byUser
*
* @return void
*
* @throws GuzzleException | Exception
*/
public function theAdministratorTriesToAddUserToNonExistentGroupUsingTheGraphAPI(string $user, ?string $byUser = null): void {
$credentials = $this->getAdminOrUserCredentials($byUser);
$groupId = WebDavHelper::generateUUIDv4();
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$this->featureContext->setResponse(
GraphHelper::addUserToGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials['username'],
$credentials['password'],
$userId,
$groupId
)
);
}
/**
* @When user :user tries to add himself/herself to group :group using the Graph API
*
@@ -1297,18 +1311,27 @@ class GraphContext implements Context {
* @param string|null $byUser
*
* @return void
* @throws Exception | GuzzleException
*/
public function theUserTriesToRemoveAnotherUserFromGroupUsingTheGraphAPI(string $user, string $group, ?string $byUser = null): void {
try {
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
} catch (Exception $e) {
$groupId = WebDavHelper::generateUUIDv4();
}
try {
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
} catch (Exception $e) {
$userId = WebDavHelper::generateUUIDv4();
}
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$this->featureContext->setResponse($this->removeUserFromGroup($groupId, $userId, $byUser));
}
/**
* @When the administrator tries to remove user :user from a nonexistent group using the Graph API
* @When user :byUser tries to remove user :user from a nonexistent group using the Graph API
*
* @param string $user
* @param string|null $byUser
*
* @return void
* @throws GuzzleException
*/
public function theUserTriesToRemoveAnotherUserFromNonExistentGroupUsingTheGraphAPI(string $user, ?string $byUser = null): void {
$groupId = WebDavHelper::generateUUIDv4();
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$this->featureContext->setResponse($this->removeUserFromGroup($groupId, $userId, $byUser));
}
@@ -1680,7 +1703,7 @@ class GraphContext implements Context {
}
/**
* @When /^the administrator "([^"]*)" tries to add the following users to a non-existing group at once using the Graph API$/
* @When /^the administrator "([^"]*)" tries to add the following users to a nonexistent group at once using the Graph API$/
*
* @param string $user
* @param TableNode $table
@@ -1699,7 +1722,7 @@ class GraphContext implements Context {
}
/**
* @When /^the administrator "([^"]*)" tries to add the following non-existing users to a group "([^"]*)" at once using the Graph API$/
* @When /^the administrator "([^"]*)" tries to add the following nonexistent users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
@@ -1720,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
@@ -1733,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);
}

View File

@@ -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;
}
}