diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index f979251b469..300280a1f2d 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1058,4 +1058,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() + ); + } } diff --git a/tests/acceptance/features/apiGraph/getApplications.feature b/tests/acceptance/features/apiGraph/getApplications.feature new file mode 100644 index 00000000000..0843683dc77 --- /dev/null +++ b/tests/acceptance/features/apiGraph/getApplications.feature @@ -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 "" 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 | \ No newline at end of file diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index adffb557a79..fdb97fad9df 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -1665,4 +1665,65 @@ class GraphContext implements Context { } $this->addMultipleUsersToGroup($user, $userIds, $groupId, $table); } + + /** + * @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]"); + } + } }