From d6dae8f0e46143c28055c1a970311a441254ca2e Mon Sep 17 00:00:00 2001 From: prashant-gurung899 Date: Wed, 16 Oct 2024 12:02:26 +0545 Subject: [PATCH] add test to check file rename activity using file-id Signed-off-by: prashant-gurung899 --- tests/acceptance/bootstrap/SpacesContext.php | 59 ++ .../apiActivities/activitiesByFileId.feature | 511 ++++++++++++++++++ 2 files changed, 570 insertions(+) create mode 100644 tests/acceptance/features/apiActivities/activitiesByFileId.feature diff --git a/tests/acceptance/bootstrap/SpacesContext.php b/tests/acceptance/bootstrap/SpacesContext.php index e39b1771be7..3b0cb676879 100644 --- a/tests/acceptance/bootstrap/SpacesContext.php +++ b/tests/acceptance/bootstrap/SpacesContext.php @@ -2011,6 +2011,65 @@ public function userCopiesOrMovesFileWithFileIdFromAndToSpaceBetweenSpaces(strin } } + /** + * @Given /^user "([^"]*)" has (copied|moved|renamed) a file "([^"]*)" into "([^"]*)" inside space "([^"]*)" using file-id path "([^"]*)"$/ + * + * @param string $user + * @param string $actionType + * @param string $sourceFile + * @param string $destinationFile + * @param string $toSpaceName + * @param string $url + * + * @return void + * @throws GuzzleException + */ + public function userHasRenamedAFileIntoUsingFileIdPath(string $user, string $actionType, string $sourceFile, string $destinationFile, string $toSpaceName, string $url): void { + $sourceFile = \trim($sourceFile, "/"); + $sourceFile = \explode("/", $sourceFile); + $sourceFile = \end($sourceFile); + $destinationFile = \trim($destinationFile, "/"); + $fileDestination = ''; + if ($actionType === 'copied' || $actionType === 'moved') { + $fileDestination = $this->escapePath($destinationFile) . '/' . $this->escapePath($sourceFile); + } else { + $fileDestination = $destinationFile; + } + $baseUrl = $this->featureContext->getBaseUrl(); + if ($toSpaceName === 'Shares') { + $sharesPath = $this->featureContext->getSharesMountPath($user, $fileDestination); + $davPath = WebDavHelper::getDavPath($user, $this->featureContext->getDavPathVersion()); + $headers['Destination'] = $baseUrl . "/$davPath" . $sharesPath; + } else { + $headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName, $url); + } + $fullUrl = $baseUrl . $url; + if ($actionType === 'copied') { + $response = $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers); + } else { + $response = $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); + } + Assert::assertEquals( + 201, + $response->getStatusCode(), + "Response did not return expected status code" + ); + } + + /** + * @Given user :user has sent HTTP method :verb to URL :url with content :content + * + * @param string $user + * @param string $url + * @param string $content + * + * @return void + */ + public function userHasEditedAFileWithContentInsideSpaceUsingFileIdPath(string $user, string $url, string $content): void { + $response = $this->featureContext->sendingToWithDirectUrl($user, 'PUT', $url, $content); + $this->featureContext->theHTTPStatusCodeShouldBe(['201', '204'], "", $response); + } + /** * @When /^user "([^"]*)" tries to move (?:file|folder) "([^"]*)" of space "([^"]*)" to (space|folder) "([^"]*)" using its id in destination path "([^"]*)"$/ * @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" of space "([^"]*)" to (folder) "([^"]*)" using its id in destination path "([^"]*)"$/ diff --git a/tests/acceptance/features/apiActivities/activitiesByFileId.feature b/tests/acceptance/features/apiActivities/activitiesByFileId.feature new file mode 100644 index 00000000000..90b94c8653f --- /dev/null +++ b/tests/acceptance/features/apiActivities/activitiesByFileId.feature @@ -0,0 +1,511 @@ +Feature: check activities + As a user + I want to check who made which changes to files using file-id + So that I can track modifications + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + + + Scenario Outline: check add activity for a file using file-id + Given user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile.txt" + And we save it into "FILEID" + And user "Alice" has created folder "/New Folder" + And user "Alice" has copied a file "/textfile.txt" into "New Folder" inside space "Personal" using file-id path "" + When user "Alice" lists the activities of file "New Folder" from 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": 2, + "maxItems": 2, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "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 {folder}" + }, + "variables": { + "type": "object", + "required": ["folder", "resource", "user"], + "properties": { + "folder": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "const": "Alice Hansen" + } + } + }, + "resource": { + "type": "object", + "required": ["id","name"], + "properties": { + "id": { + "type": "string", + "pattern": "^%file_id_pattern%$" + }, + "name": { + "const": "New Folder" + } + } + }, + "user": { + "type": "object", + "required": ["id","displayName"], + "properties": { + "id": { + "type": "string", + "pattern": "%user_id_pattern%" + }, + "displayName": { + "const": "Alice Hansen" + } + } + } + } + } + } + } + } + }, + { + "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 {folder}" + }, + "variables": { + "type": "object", + "required": ["folder", "resource", "user"], + "properties": { + "folder": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "const": "New Folder" + } + } + }, + "resource": { + "type": "object", + "required": ["id","name"], + "properties": { + "id": { + "type": "string", + "pattern": "^%file_id_pattern%$" + }, + "name": { + "const": "textfile.txt" + } + } + }, + "user": { + "type": "object", + "required": ["id","displayName"], + "properties": { + "id": { + "type": "string", + "pattern": "%user_id_pattern%" + }, + "displayName": { + "const": "Alice Hansen" + } + } + } + } + } + } + }, + "times": { + "type": "object", + "required": ["recordedTime"], + "properties": { + "recordedTime": { + "type": "string", + "format": "date-time" + } + } + } + } + } + ] + } + } + } + } + """ + Examples: + | dav-path | + | /dav/spaces/<> | + + + Scenario Outline: check edit activity for a file using file-id + Given user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile.txt" + And we save it into "FILEID" + And user "Alice" has sent HTTP method "PUT" to URL "" with content "updated content" + When user "Alice" lists the activities of file "/textfile.txt" from 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": 2, + "maxItems": 2, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": ["id", "template", "times"], + "properties": { + "template": { + "type": "object", + "required": ["message", "variables"], + "properties": { + "message": { + "const": "{user} added {resource} to {folder}" + } + } + } + } + }, + { + "type": "object", + "required": ["id", "template", "times"], + "properties": { + "template": { + "type": "object", + "required": ["message", "variables"], + "properties": { + "message": { + "const": "{user} updated {resource} in {folder}" + }, + "variables": { + "type": "object", + "required": ["folder", "resource", "user"], + "properties": { + "folder": { + "type": "object", + "required": ["name"], + "properties": { + "id": { + "type": "string", + "pattern": "%user_id_pattern%" + }, + "name": { + "const": "Alice Hansen" + } + } + }, + "resource": { + "type": "object", + "required": ["id", "name"], + "properties": { + "id": { + "type": "string", + "pattern": "%file_id_pattern%" + }, + "name": { + "const": "textfile.txt" + } + } + }, + "user": { + "type": "object", + "required": ["id","displayName"], + "properties": { + "id": { + "type": "string", + "pattern": "%user_id_pattern%" + }, + "displayName": { + "const": "Alice Hansen" + } + } + } + } + } + } + }, + "times": { + "type": "object", + "required": ["recordedTime"] + } + } + } + ] + } + } + } + } + """ + Examples: + | dav-path | + | /dav/spaces/<> | + + @issue-9744 + Scenario Outline: check rename activity for a file using file-id + Given user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile.txt" + And we save it into "FILEID" + And user "Alice" has renamed a file "/textfile.txt" into "renamed.txt" inside space "Personal" using file-id path "" + When user "Alice" lists the activities of file "renamed.txt" from 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": 2, + "maxItems": 2, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": ["id", "template", "times"], + "properties": { + "template": { + "type": "object", + "required": ["message", "variables"], + "properties": { + "message": { + "const": "{user} added {resource} to {folder}" + } + } + } + } + }, + { + "type": "object", + "required": ["id", "template", "times"], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "template": { + "type": "object", + "required": ["message", "variables"], + "properties": { + "message": { + "const": "{user} renamed {oldResource} to {resource}" + }, + "variables": { + "type": "object", + "required": ["oldResource", "resource", "user"], + "properties": { + "oldResource": { + "type": "object", + "required": ["id", "name"], + "properties": { + "id": { + "const": "" + }, + "name": { + "const": "textfile.txt" + } + } + }, + "resource": { + "type": "object", + "required": ["id", "name"], + "properties": { + "id": { + "type": "string", + "pattern": "^%file_id_pattern%$" + }, + "name": { + "const": "renamed.txt" + } + } + }, + "user": { + "type": "object", + "required": ["id", "displayName"], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "displayName": { + "const": "Alice Hansen" + } + } + } + } + } + } + }, + "times": { + "type": "object", + "required": ["recordedTime"], + "properties": { + "recordedTime": { + "type": "string", + "format": "date-time" + } + } + } + } + } + ] + } + } + } + } + """ + Examples: + | dav-path | + | /dav/spaces/<> | + + + Scenario Outline: check move activity for a file using file-id + Given user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile.txt" + And we save it into "FILEID" + And user "Alice" has created folder "/New Folder" + And user "Alice" has moved a file "/textfile.txt" into "New Folder" inside space "Personal" using file-id path "" + When user "Alice" lists the activities of file "New Folder/textfile.txt" from 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": 2, + "maxItems": 2, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": ["id","template","times"], + "properties": { + "template": { + "type": "object", + "required": ["message","variables"], + "properties": { + "message": { + "const": "{user} added {resource} to {folder}" + } + } + } + } + }, + { + "type": "object", + "required": ["id","template","times"], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "template": { + "type": "object", + "required": ["message","variables"], + "properties": { + "message": { + "const": "{user} moved {resource} to {folder}" + }, + "variables": { + "type": "object", + "required": ["folder", "resource", "user"], + "properties": { + "folder": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "const": "New Folder" + } + } + }, + "resource": { + "type": "object", + "required": ["id","name"], + "properties": { + "id": { + "type": "string", + "pattern": "^%file_id_pattern%$" + }, + "name": { + "const": "textfile.txt" + } + } + }, + "user": { + "type": "object", + "required": ["id","displayName"], + "properties": { + "id": { + "type": "string", + "pattern": "%user_id_pattern%" + }, + "displayName": { + "const": "Alice Hansen" + } + } + } + } + } + } + }, + "times": { + "type": "object", + "required": ["recordedTime"], + "properties": { + "recordedTime": { + "type": "string", + "format": "date-time" + } + } + } + } + } + ] + } + } + } + } + """ + Examples: + | dav-path | + | /dav/spaces/<> |