From 28528db41487e146f408574f7ebe24847908e2b1 Mon Sep 17 00:00:00 2001 From: prashant-gurung899 Date: Fri, 4 Oct 2024 12:07:40 +0545 Subject: [PATCH] add test to check api activities with sort filter Signed-off-by: prashant-gurung899 --- tests/acceptance/TestHelpers/GraphHelper.php | 2 +- tests/acceptance/bootstrap/GraphContext.php | 34 +++++++++++++++++-- .../features/apiActivities/activities.feature | 20 +++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/TestHelpers/GraphHelper.php b/tests/acceptance/TestHelpers/GraphHelper.php index a080ab94d09..88008cb62bb 100644 --- a/tests/acceptance/TestHelpers/GraphHelper.php +++ b/tests/acceptance/TestHelpers/GraphHelper.php @@ -2344,7 +2344,7 @@ public static function getPermissionRoleDefinition( * @param string $user * @param string $password * @param string $resourceId - * @param array $filterParams + * @param array|null $filterParams * * @return ResponseInterface */ diff --git a/tests/acceptance/bootstrap/GraphContext.php b/tests/acceptance/bootstrap/GraphContext.php index b794575ff06..6120becd4c3 100644 --- a/tests/acceptance/bootstrap/GraphContext.php +++ b/tests/acceptance/bootstrap/GraphContext.php @@ -2935,7 +2935,7 @@ public function thePublicTriesToCheckTheActivitiesOfResourceFromSpaceOwnedByUser } /** - * @When /^user "([^"]*)" lists the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" with (depth|limit) "([^"]*)" using the Graph API/ + * @When /^user "([^"]*)" lists the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" with (depth|limit|sort) "([^"]*)" using the Graph API/ * * @param string $user * @param string $resource @@ -2953,11 +2953,41 @@ public function userListsTheActivitiesForFolderOfSpaceWithDepthOrLimitUsingTheGr $user, $this->featureContext->getPasswordForUser($user), $resourceId, - [$filterType => $filterValue] + [$filterType => $filterValue], ); $this->featureContext->setResponse($response); } + /** + * @Then the activities should be in the following order: + * + * @param TableNode $table + * + * @return void + * @throws Exception + */ + public function theActivitiesShouldBeInTheFollowingOrder(TableNode $table): void { + $responseBody = $this->featureContext->getJsonDecodedResponseBodyContent(); + $activities = $responseBody->value; + $expectedOrder = []; + foreach ($table->getHash() as $row) { + $expectedOrder[] = [ + 'resource' => $row['resource'], + 'message' => $row['message'] + ]; + } + + foreach ($expectedOrder as $index => $expectedActivity) { + $actualActivity = $activities[$index]; + if ($actualActivity->template->variables->resource->name !== $expectedActivity['resource']) { + throw new Exception("Expected resource '{$expectedActivity['resource']}' but got '{$actualActivity->template->variables->resource->name}' at index {$index}."); + } + if ($actualActivity->template->message !== $expectedActivity['message']) { + throw new Exception("Expected message '{$expectedActivity['message']}' but got '{$actualActivity->template->message}' at index {$index}."); + } + } + } + /** * @When the administrator gets federated users using the Graph API * @When user :user tries to get federated users using the Graph API diff --git a/tests/acceptance/features/apiActivities/activities.feature b/tests/acceptance/features/apiActivities/activities.feature index 3800f6cde4a..c1066229a20 100644 --- a/tests/acceptance/features/apiActivities/activities.feature +++ b/tests/acceptance/features/apiActivities/activities.feature @@ -2134,6 +2134,26 @@ Feature: check activities } """ + + Scenario: check activity with sort filter + Given user "Alice" has created folder "/New Folder" + And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/New Folder/textfile.txt" + And user "Alice" has uploaded file with content "updated ownCloud test text file" to "/New Folder/textfile.txt" + When user "Alice" lists the activities of folder "New Folder" from space "Personal" with sort "asc" using the Graph API + Then the HTTP status code should be "200" + And the activities should be in the following order: + | resource | message | + | New Folder | {user} added {resource} to {folder} | + | textfile.txt | {user} added {resource} to {folder} | + | textfile.txt | {user} updated {resource} in {folder} | + When user "Alice" lists the activities of folder "New Folder" from space "Personal" with sort "desc" using the Graph API + Then the HTTP status code should be "200" + And the activities should be in the following order: + | resource | message | + | textfile.txt | {user} updated {resource} in {folder} | + | textfile.txt | {user} added {resource} to {folder} | + | New Folder | {user} added {resource} to {folder} | + @issue-9860 Scenario: user tries to check activities of another user's file Given user "Brian" has been created with default attributes and without skeleton files