[test-only] Api test. get applications list. (#5529)

This commit is contained in:
Viktor Scharf
2023-02-13 09:38:04 +05:45
committed by GitHub
parent b3b27f4490
commit 139cf79f61
3 changed files with 114 additions and 37 deletions
+25 -37
View File
@@ -499,43 +499,6 @@ class GraphHelper {
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $adminUser
* @param string $adminPassword
* @param string $groupId
* @param array $users expects users array with user ids
* [ [ 'id' => 'some_id' ], ]
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function addUsersToGroup(
string $baseUrl,
string $xRequestId,
string $adminUser,
string $adminPassword,
string $groupId,
array $users
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'groups/' . $groupId . '/users');
$payload = [
"members@odata.bind" => []
];
foreach ($users as $user) {
$payload[0][] = self::getFullUrl($baseUrl, 'users/' . $user["id"]);
}
return HttpRequestHelper::post(
$url,
$xRequestId,
$adminUser,
$adminPassword,
self::getRequestHeaders(),
\json_encode($payload)
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
@@ -1031,4 +994,29 @@ class GraphHelper {
\json_encode($payload)
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function getApplications(
string $baseUrl,
string $xRequestId,
string $user,
string $password
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'applications');
return HttpRequestHelper::get(
$url,
$xRequestId,
$user,
$password,
self::getRequestHeaders()
);
}
}
@@ -0,0 +1,28 @@
@api @skipOnOcV10
Feature: get applications
As an user
I want to be able to get applications information with existings roles
Background:
Given user "Alice" has been created with default attributes and without skeleton files
Scenario Outline: admin user lists all the groups
Given the administrator has given "Alice" the role "<role>" using the settings api
When user "Alice" gets all applications using the Graph API
Then the HTTP status code should be "200"
And the user retrieve API response should contain the following applications information:
| key | value |
| displayName | ownCloud Infinite Scale |
| id | %uuid_v4% |
And the user retrieve API response should contain the following app roles:
| Admin |
| Space Admin |
| User |
| Guest |
Examples:
| role |
| Admin |
| Space Admin |
| User |
| Guest |
@@ -1459,4 +1459,65 @@ class GraphContext implements Context {
throw new Error('Response is not an array or the array does not consist key "drive"');
}
}
/**
* @When user :user gets all applications using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userGetsAllApplicationsUsingTheGraphApi(string $user) {
$response = GraphHelper::getApplications(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
);
$this->featureContext->setResponse($response);
}
/**
* @Then the user retrieve API response should contain the following applications information:
*
* @param TableNode $table
*
* @return void
*/
public function theResponseShouldContainTheFollowingApplicationsInformation(TableNode $table): void {
Assert::assertIsArray($responseArray = ($this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse()))['value'][0]);
foreach ($table->getHash() as $row) {
$key = $row["key"];
if ($key === 'id') {
Assert::assertTrue(
GraphHelper::isUUIDv4($responseArray[$key]),
__METHOD__ . ' Expected id to have UUIDv4 pattern but found: ' . $row["value"]
);
} else {
Assert::assertEquals($responseArray[$key], $row["value"]);
}
}
}
/**
* @Then the user retrieve API response should contain the following app roles:
*
* @param TableNode $table
*
* @return void
*/
public function theResponseShouldContainTheFollowingAppRolesInformation(TableNode $table): void {
Assert::assertIsArray($responseArray = ($this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse()))['value'][0]);
foreach ($table->getRows() as $row) {
$foundRoleInResponse = false;
foreach ($responseArray['appRoles'] as $role) {
if ($role['displayName'] === $row[0]) {
$foundRoleInResponse = true;
break;
}
}
Assert::assertTrue($foundRoleInResponse, "the response does not contain the role $row[0]");
}
}
}