From 065c4fa02711a263994d0bde047503f6ea5f9e58 Mon Sep 17 00:00:00 2001 From: Salipa-Gurung Date: Tue, 23 Jul 2024 16:57:58 +0545 Subject: [PATCH] add test coverage for activities api for a file --- tests/TestHelpers/GraphHelper.php | 27 +++++ .../features/apiGraph/activities.feature | 99 +++++++++++++++++++ .../features/bootstrap/GraphContext.php | 23 +++++ 3 files changed, 149 insertions(+) create mode 100644 tests/acceptance/features/apiGraph/activities.feature diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 7e5c77b8d1..6926a633a4 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -2293,4 +2293,31 @@ class GraphHelper { self::getRequestHeaders() ); } + + /** + * @param string $baseUrl + * @param string $requestId + * @param string $user + * @param string $password + * @param string $resourceId + * + * @return ResponseInterface + */ + public static function getActivities( + string $baseUrl, + string $requestId, + string $user, + string $password, + string $resourceId + ): ResponseInterface { + // 'kql=itemId' filter is required for the current implementation but it might change in future + // See: https://github.com/owncloud/ocis/issues/9194 + $fullUrl = self::getBetaFullUrl($baseUrl, "extensions/org.libregraph/activities?kql=itemid%3A$resourceId"); + return HttpRequestHelper::get( + $fullUrl, + $requestId, + $user, + $password + ); + } } diff --git a/tests/acceptance/features/apiGraph/activities.feature b/tests/acceptance/features/apiGraph/activities.feature new file mode 100644 index 0000000000..e3b22857f1 --- /dev/null +++ b/tests/acceptance/features/apiGraph/activities.feature @@ -0,0 +1,99 @@ +Feature: check activities + As a user + I want to check who made which changes to files + So that I can track modifications + + + Scenario: check activities after uploading a file + Given user "Alice" has been created with default attributes and without skeleton files + And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt" + When user "Alice" checks the activities for file "textfile0.txt" in space "Personal" using the Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": ["value"], + "properties": { + "value": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": ["id","template","times"], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "template": { + "type": "object", + "required": ["message","variables"], + "properties": { + "message": { + "const": "{user} added {resource} to {space}" + }, + "variables": { + "type": "object", + "required": ["resource","space","user"], + "properties": { + "resource": { + "type": "object", + "required": ["id","name"], + "properties": { + "id": { + "type": "string", + "pattern": "%file_id_pattern%" + }, + "name": { + "const": "textfile0.txt" + } + } + }, + "space": { + "type": "object", + "required": ["id","name"], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%!%user_id_pattern%$" + }, + "name": { + "const": "Alice Hansen" + } + } + }, + "user": { + "type": "object", + "required": ["id","displayName"], + "properties": { + "id": { + "type": "string", + "pattern": "%user_id_pattern%" + }, + "displayName": { + "const": "Alice" + } + } + } + } + } + } + }, + "times": { + "type": "object", + "required": ["recordedTime"], + "properties": { + "recordedTime": { + "type": "string", + "format": "date-time" + } + } + } + } + } + } + } + } + """ diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index ee33aa7fe9..9f6e0074ca 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2775,4 +2775,27 @@ class GraphContext implements Context { ) ); } + + /** + * @When /^user "([^"]*)" checks the activities for (?:folder|file) "([^"]*)" in space "([^"]*)" using the Graph API/ + * + * @param string $user + * @param string $resource + * @param string $spaceName + * + * @return void + * @throws Exception + * + */ + public function userChecksTheActivitiesForResourceInSpaceUsingTheGraphAPI(string $user, string $resource, string $spaceName): void { + $resourceId = $this->featureContext->spacesContext->getResourceId($user, $spaceName, $resource); + $response = GraphHelper::getActivities( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $resourceId + ); + $this->featureContext->setResponse($response); + } }