[tests-only][full-ci]Extend tests related to assign role (#5584)

* Extend assign role test coverage

* Check app Entity has been set or not
This commit is contained in:
Amrita
2023-03-03 09:17:34 +05:45
committed by GitHub
parent 8962038d6e
commit 4377754573
2 changed files with 42 additions and 14 deletions
@@ -31,3 +31,17 @@ Feature: assign role
| Space Admin | 401 |
| User | 401 |
| Guest | 401 |
Scenario Outline: assign role to the user with setting api and list role with graph api
Given user "Alice" has been created with default attributes and without skeleton files
And the administrator has given "Alice" the role "<userRole>" using the settings api
When the administrator retrieves the assigned role of user "Alice" using the Graph API
Then the HTTP status code should be "200"
And the Graph API response should have the role "<userRole>"
Examples:
| userRole |
| Admin |
| Space Admin |
| User |
| Guest |
@@ -1727,20 +1727,7 @@ class GraphContext implements Context {
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id') ?? $user;
if (empty($this->appEntity)) {
$applicationEntity = (
$this->featureContext->getJsonDecodedResponse(
GraphHelper::getApplications(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
)
)
)['value'][0];
$this->appEntity["id"] = $applicationEntity["id"];
foreach ($applicationEntity["appRoles"] as $value) {
$this->appEntity["appRoles"][$value['displayName']] = $value['id'];
}
$this->setApplicationEntity();
}
$response = GraphHelper::assignRole(
@@ -1782,6 +1769,29 @@ class GraphContext implements Context {
);
}
/**
* set application Entity in global variable
*
* @return void
* @throws GuzzleException
*/
public function setApplicationEntity(): void {
$applicationEntity = (
$this->featureContext->getJsonDecodedResponse(
GraphHelper::getApplications(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
)
)
)['value'][0];
$this->appEntity["id"] = $applicationEntity["id"];
foreach ($applicationEntity["appRoles"] as $value) {
$this->appEntity["appRoles"][$value['displayName']] = $value['id'];
}
}
/**
* @Then /^the Graph API response should have the role "([^"]*)"$/
*
@@ -1789,9 +1799,13 @@ class GraphContext implements Context {
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theGraphApiResponseShouldHaveTheRole(string $role): void {
$response = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['value'][0];
if (empty($this->appEntity)) {
$this->setApplicationEntity();
}
Assert::assertEquals(
$this->appEntity["appRoles"][$role],
$response['appRoleId'],