diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 7e5c77b8d1f..082c0ea39ca 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -2293,4 +2293,31 @@ public static function getPermissionRoleDefinition( 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 { + // resourceId 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 00000000000..124fd12e3a3 --- /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" + 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 ee33aa7fe9c..f1e8251a87c 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2775,4 +2775,27 @@ public function getPermissionRoleDefinitionUsingGraphAPI(string $user, string $p ) ); } + + /** + * @When /^user "([^"]*)" checks the activities for (?:folder|file) "([^"]*)" in space "([^"]*)"/ + * + * @param string $user + * @param string $resource + * @param string $spaceName + * + * @return void + * @throws Exception + * + */ + public function userChecksTheActivitiesForResource(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); + } }