From 78fa278ed077cffab839f1f68a98979e4fb08ca1 Mon Sep 17 00:00:00 2001 From: Prajwol Amatya Date: Mon, 2 Sep 2024 14:52:36 +0545 Subject: [PATCH] added test to create text file with /app/new endpoint --- .../bootstrap/CollaborationContext.php | 23 +++ .../features/apiCollaboration/wopi.feature | 186 ++++++++++++++++++ 2 files changed, 209 insertions(+) diff --git a/tests/acceptance/bootstrap/CollaborationContext.php b/tests/acceptance/bootstrap/CollaborationContext.php index 8f7e30e6aa..b0135706f5 100644 --- a/tests/acceptance/bootstrap/CollaborationContext.php +++ b/tests/acceptance/bootstrap/CollaborationContext.php @@ -89,4 +89,27 @@ class CollaborationContext implements Context { ) ); } + + /** + * @When user :user creates a file :file inside folder :folder in space :space using wopi endpoint + * @When user :user tries to create a file :file inside folder :folder in space :space using wopi endpoint + * + * @param string $user + * @param string $file + * @param string $folder + * @param string $space + * + * @return void + */ + public function userCreatesFileInsideFolderInSpaceUsingWopiEndpoint(string $user, string $file, string $folder, string $space): void { + $parent_container_id = $this->spacesContext->getResourceId($user, $space, $folder); + $this->featureContext->setResponse( + HttpRequestHelper::post( + $this->featureContext->getBaseUrl() . "/app/new?parent_container_id=$parent_container_id&filename=$file", + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user) + ) + ); + } } diff --git a/tests/acceptance/features/apiCollaboration/wopi.feature b/tests/acceptance/features/apiCollaboration/wopi.feature index 3b9d387014..9f5ccb00e2 100644 --- a/tests/acceptance/features/apiCollaboration/wopi.feature +++ b/tests/acceptance/features/apiCollaboration/wopi.feature @@ -552,3 +552,189 @@ Feature: collaboration (wopi) | app-endpoint | | /app/open-with-web?file_id=<>&app_name=FakeOffice | | /app/open-with-web?file_id=<> | + + + Scenario: create a text file using wopi endpoint in Personal space + Given user "Alice" has created folder "testFolder" + When user "Alice" creates a file "testfile.txt" inside folder "testFolder" in space "Personal" using wopi endpoint + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "file_id" + ], + "properties": { + "file_id": { + "type": "string", + "pattern": "^%file_id_pattern%$" + } + } + } + """ + And as "Alice" file "testFolder/testfile.txt" should exist + + + Scenario Outline: sharee with permission Editor/Uploader creates text file inside shared folder + Given user "Alice" has created folder "testFolder" + And user "Alice" has sent the following resource share invitation: + | resource | testFolder | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + When user "Brian" creates a file "testFile.txt" inside folder "testFolder" in space "Shares" using wopi endpoint + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "file_id" + ], + "properties": { + "file_id": { + "type": "string", + "pattern": "^%file_id_pattern%$" + } + } + } + """ + And as "Alice" file "testFolder/testFile.txt" should exist + And as "Brian" file "Shares/testFolder/testFile.txt" should exist + Examples: + | permissions-role | + | Editor | + | Uploader | + + + Scenario: sharee with permission Viewer tries to create text file inside shared folder + Given user "Alice" has created folder "testFolder" + And user "Alice" has sent the following resource share invitation: + | resource | testFolder | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Viewer | + When user "Brian" tries to create a file "testFile.txt" inside folder "testFolder" in space "Shares" using wopi endpoint + Then the HTTP status code should be "500" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "const": "SERVER_ERROR" + }, + "message": { + "const": "error calling InitiateFileUpload" + } + } + } + """ + And as "Alice" file "testFolder/testFile.txt" should not exist + And as "Brian" file "Shares/testFolder/testFile.txt" should not exist + + + Scenario: space admin creates a text file in project space using wopi endpoint + Given using spaces DAV path + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "new-space" with the default quota using the Graph API + And user "Alice" has created a folder "testFolder" in space "new-space" + When user "Alice" creates a file "testFile.txt" inside folder "testFolder" in space "new-space" using wopi endpoint + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "file_id" + ], + "properties": { + "file_id": { + "type": "string", + "pattern": "^%file_id_pattern%$" + } + } + } + """ + And for user "Alice" folder "testFolder" of the space "new-space" should contain these files: + | testFile.txt | + + + Scenario Outline: user with Space Editor/Manager role creates a text file inside shared project space using wopi endpoint + Given using spaces DAV path + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "new-space" with the default quota using the Graph API + And user "Alice" has created a folder "testFolder" in space "new-space" + And user "Alice" has sent the following space share invitation: + | space | new-space | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + When user "Brian" creates a file "testFile.txt" inside folder "testFolder" in space "new-space" using wopi endpoint + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "file_id" + ], + "properties": { + "file_id": { + "type": "string", + "pattern": "^%file_id_pattern%$" + } + } + } + """ + And for user "Alice" folder "testFolder" of the space "new-space" should contain these files: + | testFile.txt | + And for user "Brian" folder "testFolder" of the space "new-space" should contain these files: + | testFile.txt | + Examples: + | permissions-role | + | Space Editor | + | Manager | + + + Scenario: user with Viewer role tries to create a text file inside shared project space using wopi endpoint + Given using spaces DAV path + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "new-space" with the default quota using the Graph API + And user "Alice" has created a folder "testFolder" in space "new-space" + And user "Alice" has sent the following space share invitation: + | space | new-space | + | sharee | Brian | + | shareType | user | + | permissionsRole | Space Viewer | + When user "Brian" tries to create a file "testFile.txt" inside folder "testFolder" in space "new-space" using wopi endpoint + Then the HTTP status code should be "500" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "const": "SERVER_ERROR" + }, + "message": { + "const": "error calling InitiateFileUpload" + } + } + } + """ + And for user "Alice" folder "testFolder" of the space "new-space" should not contain these files: + | testFile.txt | + And for user "Brian" folder "testFolder" of the space "new-space" should not contain these files: + | testFile.txt |