From 67296caf144ec053279ef04cf533628f3a2183f4 Mon Sep 17 00:00:00 2001 From: Sagar Gurung <46086950+SagarGi@users.noreply.github.com> Date: Wed, 15 Mar 2023 10:06:58 +0545 Subject: [PATCH] Forward port json drill `apispaces` (#5818) * Added json schema for response check in apiSpaces suite Signed-off-by: sagargurung1001@gmail.com * Review Address * Added schema for space management feature * Added new schema asper change in master * fix feature file --------- Signed-off-by: sagargurung1001@gmail.com --- ...ected-failures-localAPI-on-OCIS-storage.md | 2 +- .../features/apiSpaces/changeSpaces.feature | 533 ++++++++++++++-- .../features/apiSpaces/deleteSpaces.feature | 76 ++- .../features/apiSpaces/listSpaces.feature | 574 +++++++++++++++--- .../features/apiSpaces/quota.feature | 50 +- .../apiSpaces/removeSpaceObjects.feature | 50 +- .../apiSpaces/restoreSpaceObjects.feature | 78 ++- .../apiSpaces/spaceManagement.feature | 356 +++++++++-- .../features/apiSpaces/uploadSpaces.feature | 28 + .../features/bootstrap/FeatureContext.php | 66 +- .../features/bootstrap/SpacesContext.php | 93 ++- .../coreApiCapabilities/capabilities.feature | 10 +- .../capabilitiesWithNormalUser.feature | 2 +- 13 files changed, 1673 insertions(+), 245 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 8a4d6ea595..9099e9b219 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -99,7 +99,7 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiSpacesShares/shareSubItemOfSpace.feature:105](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpace.feature#L105) #### [Space admin should not not be able to change the user quota](https://github.com/owncloud/ocis/issues/5475) -- [apiSpaces/spaceManagement.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/spaceManagement.feature#L69) +- [apiSpaces/spaceManagement.feature:149](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/spaceManagement.feature#L149) #### [Normal user can get expanded members information of a group](https://github.com/owncloud/ocis/issues/5604) - [apiGraph/getGroup.feature:100](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L100) diff --git a/tests/acceptance/features/apiSpaces/changeSpaces.feature b/tests/acceptance/features/apiSpaces/changeSpaces.feature index 85be343617..e501722920 100644 --- a/tests/acceptance/features/apiSpaces/changeSpaces.feature +++ b/tests/acceptance/features/apiSpaces/changeSpaces.feature @@ -24,12 +24,28 @@ Feature: Change data of space Scenario Outline: Only space admin user can change the name of a Space via the Graph API - When user "" changes the name of the "Project Jupiter" space to "Project Death Star" + When user "" changes the name of the "Project Jupiter" space to "" Then the HTTP status code should be "" - And the user "" should have a space called "" with these key and value pairs: - | key | value | - | driveType | project | - | name | | + And for user "" the JSON response should contain space called "" and match + """ + { + "type": "object", + "required": [ + "name", + "driveType" + ], + "properties": { + "name": { + "type": "string", + "enum": [""] + }, + "driveType": { + "type": "string", + "enum": ["project"] + } + } + } + """ Examples: | user | code | expectedName | | Alice | 200 | Project Death Star | @@ -40,11 +56,31 @@ Feature: Change data of space Scenario: Only space admin user can change the description(subtitle) of a Space via the Graph API When user "Alice" changes the description of the "Project Jupiter" space to "The Death Star is a fictional mobile space station" Then the HTTP status code should be "200" - And the user "Alice" should have a space called "Project Jupiter" with these key and value pairs: - | key | value | - | driveType | project | - | name | Project Jupiter | - | description | The Death Star is a fictional mobile space station | + And for user "Alice" the JSON response should contain space called "Project Jupiter" and match + """ + { + "type": "object", + "required": [ + "name", + "driveType", + "description" + ], + "properties": { + "driveType": { + "type": "string", + "enum": ["project"] + }, + "name": { + "type": "string", + "enum": ["Project Jupiter"] + }, + "description": { + "type": "string", + "enum": ["The Death Star is a fictional mobile space station"] + } + } + } + """ Scenario Outline: Viewer and editor cannot change the description(subtitle) of a Space via the Graph API @@ -59,10 +95,35 @@ Feature: Change data of space Scenario Outline: An user tries to increase the quota of a Space via the Graph API When user "" changes the quota of the "Project Jupiter" space to "100" Then the HTTP status code should be "" - And the user "" should have a space called "Project Jupiter" with these key and value pairs: - | key | value | - | name | Project Jupiter | - | quota@@@total | | + And for user "" the JSON response should contain space called "Project Jupiter" and match + + """ + { + "type": "object", + "required": [ + "name", + "quota" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Jupiter"] + }, + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "total" : { + "type": "number", + "enum": [] + } + } + } + } + } + """ Examples: | user | code | expectedQuataValue | | Alice | 200 | 100 | @@ -75,11 +136,39 @@ Feature: Change data of space Then the HTTP status code should be "200" When user "Alice" uploads a file inside space "Project Jupiter" with content "some content" to "file.txt" using the WebDAV API Then the HTTP status code should be "201" - And the user "Alice" should have a space called "Project Jupiter" with these key and value pairs: - | key | value | - | name | Project Jupiter | - | quota@@@used | 12 | - | quota@@@total | 0 | + And for user "Alice" the JSON response should contain space called "Project Jupiter" and match + """ + { + "type": "object", + "required": [ + "name", + "quota" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Jupiter"] + }, + "quota": { + "type": "object", + "required": [ + "used", + "total" + ], + "properties": { + "used" : { + "type": "number", + "enum": [12] + }, + "total" : { + "type": "number", + "enum": [0] + } + } + } + } + } + """ Examples: | quotaValue | | 0 | @@ -91,15 +180,78 @@ Feature: Change data of space And user "Alice" has uploaded a file inside space "Project Jupiter" with content "space description" to ".space/readme.md" When user "Alice" sets the file ".space/readme.md" as a description in a special section of the "Project Jupiter" space Then the HTTP status code should be "200" - And the user "Alice" should have a space called "Project Jupiter" owned by "Alice" with description file ".space/readme.md" with these key and value pairs: - | key | value | - | name | Project Jupiter | - | special@@@0@@@size | 17 | - | special@@@0@@@name | readme.md | - | special@@@0@@@specialFolder@@@name | readme | - | special@@@0@@@file@@@mimeType | text/markdown | - | special@@@0@@@id | %file_id% | - | special@@@0@@@eTag | %eTag% | + And for user "Alice" the JSON response should contain space called "Project Jupiter" owned by "Alice" with description file ".space/readme.md" and match + """ + { + "type": "object", + "required": [ + "name", + "special" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Jupiter"] + }, + "special": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "size", + "name", + "specialFolder", + "file", + "id", + "eTag" + ], + "properties": { + "size": { + "type": "number", + "enum": [17] + }, + "name": { + "type": "string", + "enum": ["readme.md"] + }, + "specialFolder": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["readme"] + } + } + }, + "file": { + "type": "object", + "required": [ + "mimeType" + ], + "properties": { + "type": "string", + "enum": ["text/markdown"] + } + }, + "id": { + "type": "string", + "enum": ["%file_id%"] + }, + "tag": { + "type": "string", + "enum": ["%eTag%"] + } + } + } + ] + } + } + } + """ And for user "Alice" folder ".space/" of the space "Project Jupiter" should contain these entries: | readme.md | And for user "Alice" the content of the file ".space/readme.md" of the space "Project Jupiter" should be "space description" @@ -111,15 +263,78 @@ Feature: Change data of space And user "Alice" has set the file ".space/readme.md" as a description in a special section of the "Project Jupiter" space When user "" uploads a file inside space "Project Jupiter" with content "new description" to ".space/readme.md" using the WebDAV API Then the HTTP status code should be "" - And the user "" should have a space called "Project Jupiter" owned by "Alice" with description file ".space/readme.md" with these key and value pairs: - | key | value | - | name | Project Jupiter | - | special@@@0@@@size | | - | special@@@0@@@name | readme.md | - | special@@@0@@@specialFolder@@@name | readme | - | special@@@0@@@file@@@mimeType | text/markdown | - | special@@@0@@@id | %file_id% | - | special@@@0@@@eTag | %eTag% | + And for user "Alice" the JSON response should contain space called "Project Jupiter" owned by "Alice" with description file ".space/readme.md" and match + """ + { + "type": "object", + "required": [ + "name", + "special" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Jupiter"] + }, + "special": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "size", + "name", + "specialFolder", + "file", + "id", + "eTag" + ], + "properties": { + "size": { + "type": "number", + "enum": [] + }, + "name": { + "type": "string", + "enum": ["readme.md"] + }, + "specialFolder": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["readme"] + } + } + }, + "file": { + "type": "object", + "required": [ + "mimeType" + ], + "properties": { + "type": "string", + "enum": ["text/markdown"] + } + }, + "id": { + "type": "string", + "enum": ["%file_id%"] + }, + "tag": { + "type": "string", + "enum": ["%eTag%"] + } + } + } + ] + } + } + } + """ And for user "" folder ".space/" of the space "Project Jupiter" should contain these entries: | readme.md | And for user "" the content of the file ".space/readme.md" of the space "Project Jupiter" should be "" @@ -134,15 +349,78 @@ Feature: Change data of space And user "" has uploaded a file inside space "Project Jupiter" with content "" to ".space/" When user "" sets the file ".space/" as a space image in a special section of the "Project Jupiter" space Then the HTTP status code should be "200" - And the user "Alice" should have a space called "Project Jupiter" owned by "Alice" with description file ".space/" with these key and value pairs: - | key | value | - | name | Project Jupiter | - | special@@@0@@@size | 0 | - | special@@@0@@@name | | - | special@@@0@@@specialFolder@@@name | image | - | special@@@0@@@file@@@mimeType | | - | special@@@0@@@id | %file_id% | - | special@@@0@@@eTag | %eTag% | + And for user "Alice" the JSON response should contain space called "Project Jupiter" owned by "Alice" with description file ".space/" and match + """ + { + "type": "object", + "required": [ + "name", + "special" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Jupiter"] + }, + "special": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "size", + "name", + "specialFolder", + "file", + "id", + "eTag" + ], + "properties": { + "size": { + "type": "number", + "enum": [0] + }, + "name": { + "type": "string", + "enum": [""] + }, + "specialFolder": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["image"] + } + } + }, + "file": { + "type": "object", + "required": [ + "mimeType" + ], + "properties": { + "type": "string", + "enum": [""] + } + }, + "id": { + "type": "string", + "enum": ["%file_id%"] + }, + "tag": { + "type": "string", + "enum": ["%eTag%"] + } + } + } + ] + } + } + } + """ And for user "" folder ".space/" of the space "Project Jupiter" should contain these entries: | | Examples: @@ -151,7 +429,6 @@ Feature: Change data of space | Brian | spaceImage.png | spaceImage.png | image/png | | Alice | spaceImage.gif | spaceImage.gif | image/gif | - Scenario: An user viewer cannot set image file as space image of the space via the Graph API Given user "Alice" has created a folder ".space" in space "Project Jupiter" And user "Alice" has uploaded a file inside space "Project Jupiter" with content "" to ".space/someImageFile.jpg" @@ -166,15 +443,78 @@ Feature: Change data of space When user "" uploads a file inside space "Project Jupiter" owned by the user "Alice" with content "new content" to ".space/readme.md" using the WebDAV API Then the HTTP status code should be "" And for user "" the content of the file ".space/readme.md" of the space "Project Jupiter" should be "" - And the user "" should have a space called "Project Jupiter" owned by "Alice" with description file ".space/readme.md" with these key and value pairs: - | key | value | - | name | Project Jupiter | - | special@@@0@@@size | | - | special@@@0@@@name | readme.md | - | special@@@0@@@specialFolder@@@name | readme | - | special@@@0@@@file@@@mimeType | text/markdown | - | special@@@0@@@id | %file_id% | - | special@@@0@@@eTag | %eTag% | + And for user "" the JSON response should contain space called "Project Jupiter" owned by "Alice" with description file ".space/readme.md" and match + """ + { + "type": "object", + "required": [ + "name", + "special" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Jupiter"] + }, + "special": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "size", + "name", + "specialFolder", + "file", + "id", + "eTag" + ], + "properties": { + "size": { + "type": "number", + "enum": [] + }, + "name": { + "type": "string", + "enum": ["readme.md"] + }, + "specialFolder": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["readme"] + } + } + }, + "file": { + "type": "object", + "required": [ + "mimeType" + ], + "properties": { + "type": "string", + "enum": ["text/markdown"] + } + }, + "id": { + "type": "string", + "enum": ["%file_id%"] + }, + "tag": { + "type": "string", + "enum": ["%eTag%"] + } + } + } + ] + } + } + } + """ Examples: | user | code | expectedSize | expectedContent | | Alice | 204 | 11 | new content | @@ -189,15 +529,78 @@ Feature: Change data of space When user "" has uploaded a file inside space "Project Jupiter" with content "" to ".space/newSpaceImage.png" And user "" sets the file ".space/newSpaceImage.png" as a space image in a special section of the "Project Jupiter" space Then the HTTP status code should be "200" - And the user "" should have a space called "Project Jupiter" owned by "Alice" with space image ".space/newSpaceImage.png" with these key and value pairs: - | key | value | - | name | Project Jupiter | - | special@@@0@@@size | 0 | - | special@@@0@@@name | newSpaceImage.png | - | special@@@0@@@specialFolder@@@name | image | - | special@@@0@@@file@@@mimeType | image/png | - | special@@@0@@@id | %file_id% | - | special@@@0@@@eTag | %eTag% | + And for user "" the JSON response should contain space called "Project Jupiter" owned by "Alice" with description file ".space/newSpaceImage.png" and match + """ + { + "type": "object", + "required": [ + "name", + "special" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Jupiter"] + }, + "special": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "size", + "name", + "specialFolder", + "file", + "id", + "eTag" + ], + "properties": { + "size": { + "type": "number", + "enum": [0] + }, + "name": { + "type": "string", + "enum": ["newSpaceImage.png"] + }, + "specialFolder": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["image"] + } + } + }, + "file": { + "type": "object", + "required": [ + "mimeType" + ], + "properties": { + "type": "string", + "enum": ["image/png"] + } + }, + "id": { + "type": "string", + "enum": ["%file_id%"] + }, + "tag": { + "type": "string", + "enum": ["%eTag%"] + } + } + } + ] + } + } + } + """ Examples: | user | | Alice | diff --git a/tests/acceptance/features/apiSpaces/deleteSpaces.feature b/tests/acceptance/features/apiSpaces/deleteSpaces.feature index b5c6a77a2f..3d681bade4 100644 --- a/tests/acceptance/features/apiSpaces/deleteSpaces.feature +++ b/tests/acceptance/features/apiSpaces/deleteSpaces.feature @@ -26,10 +26,42 @@ Feature: Disabling and deleting space Scenario Outline: A space admin user can disable a Space via the Graph API When user "Alice" disables a space "Project Moon" Then the HTTP status code should be "204" - And the user "Alice" should have a space called "Project Moon" with these key and value pairs: - | key | value | - | name | Project Moon | - | root@@@deleted@@@state | trashed | + And for user "Alice" the JSON response should contain space called "Project Moon" and match + """ + { + "type": "object", + "required": [ + "name", + "root" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Moon"] + }, + "root": { + "type": "object", + "required": [ + "deleted" + ], + "properties": { + "deleted": { + "type": "object", + "required": [ + "state" + ], + "properties": { + "state": { + "type": "string", + "enum": ["trashed"] + } + } + } + } + } + } + } + """ And the user "" should not have a space called "Project Moon" Examples: | user | @@ -40,9 +72,21 @@ Feature: Disabling and deleting space Scenario Outline: An user without space admin role cannot disable a Space via the Graph API When user "" disables a space "Project Moon" Then the HTTP status code should be "403" - And the user "" should have a space called "Project Moon" with these key and value pairs: - | key | value | - | name | Project Moon | + And for user "" the JSON response should contain space called "Project Moon" and match + """ + { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Moon"] + } + } + } + """ Examples: | user | | Brian | @@ -69,6 +113,18 @@ Feature: Disabling and deleting space Scenario: An space manager cannot delete a space via the webDav API without first disabling it When user "Alice" deletes a space "Project Moon" Then the HTTP status code should be "400" - And the user "Alice" should have a space called "Project Moon" with these key and value pairs: - | key | value | - | name | Project Moon | + And for user "Alice" the JSON response should contain space called "Project Moon" and match + """ + { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Moon"] + } + } + } + """ diff --git a/tests/acceptance/features/apiSpaces/listSpaces.feature b/tests/acceptance/features/apiSpaces/listSpaces.feature index 3c4efc9d11..46278ac5d4 100644 --- a/tests/acceptance/features/apiSpaces/listSpaces.feature +++ b/tests/acceptance/features/apiSpaces/listSpaces.feature @@ -14,17 +14,67 @@ Feature: List and create spaces Scenario: An ordinary user can request information about their Space via the Graph API When user "Alice" lists all available spaces via the GraphApi Then the HTTP status code should be "200" - And the json responded should contain a space "Alice Hansen" owned by "Alice" with these key and value pairs: - | key | value | - | driveType | personal | - | driveAlias | personal/alice | - | id | %space_id% | - | name | Alice Hansen | - | owner@@@user@@@id | %user_id% | - | quota@@@state | normal | - | root@@@id | %space_id% | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + And the JSON response should contain space called "Alice Hansen" and match + """ + { + "type": "object", + "required": [ + "driveType", + "driveAlias", + "name", + "id", + "quota", + "root", + "webUrl" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Alice Hansen"] + }, + "driveType": { + "type": "string", + "enum": ["personal"] + }, + "driveAlias": { + "type": "string", + "enum": ["personal/alice"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + }, + "quota": { + "type": "object", + "required": [ + "state" + ], + "properties": { + "state": { + "type": "string", + "enum": ["normal"] + } + } + }, + "root": { + "type": "object", + "required": [ + "webDavUrl" + ], + "properties": { + "webDavUrl": { + "type": "string", + "enum": ["%base_url%/dav/spaces/%space_id%"] + } + } + }, + "webUrl": { + "type": "string", + "enum": ["%base_url%/f/%space_id%"] + } + } + } + """ Scenario: An ordinary user can request information about their Space via the Graph API using a filter @@ -32,21 +82,93 @@ Feature: List and create spaces And user "Brian" has created folder "folder" And user "Brian" has shared folder "folder" with user "Alice" with permissions "31" And user "Alice" has accepted share "/folder" offered by user "Brian" - Then the user "Alice" should have a space called "Shares" with these key and value pairs: - | key | value | - | driveType | virtual | - | id | %space_id% | - | name | Shares | + Then for user "Alice" the JSON response should contain space called "Shares" and match + """ + { + "type": "object", + "required": [ + "driveType", + "id", + "name" + ], + "properties": { + "driveType": { + "type": "string", + "enum": ["virtual"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + }, + "name": { + "type": "string", + "enum": ["Shares"] + } + } + } + """ When user "Alice" lists all available spaces via the GraphApi with query "$filter=driveType eq 'personal'" Then the HTTP status code should be "200" - And the json responded should contain a space "Alice Hansen" with these key and value pairs: - | key | value | - | driveType | personal | - | id | %space_id% | - | name | Alice Hansen | - | quota@@@state | normal | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + And the JSON response should contain space called "Alice Hansen" and match + """ + { + "type": "object", + "required": [ + "driveType", + "driveAlias", + "name", + "id", + "quota", + "root" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Alice Hansen"] + }, + "driveType": { + "type": "string", + "enum": ["personal"] + }, + "driveAlias": { + "type": "string", + "enum": ["personal/alice"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + }, + "quota": { + "type": "object", + "required": [ + "state" + ], + "properties": { + "state": { + "type": "string", + "enum": ["normal"] + } + } + }, + "root": { + "type": "object", + "required": [ + "webDavUrl" + ], + "properties": { + "webDavUrl": { + "type": "string", + "enum": ["%base_url%/dav/spaces/%space_id%"] + } + } + }, + "webUrl": { + "type": "string", + "enum": ["%base_url%/f/%space_id%"] + } + } + } + """ And the json responded should not contain a space with name "Shares" And the json responded should only contain spaces of type "personal" @@ -56,11 +178,31 @@ Feature: List and create spaces And user "Alice" has created a space "my project" of type "project" with quota "20" When user "Alice" lists all available spaces via the GraphApi with query "$filter=driveType eq 'project'" Then the HTTP status code should be "200" - And the json responded should contain a space "my project" with these key and value pairs: - | key | value | - | driveType | project | - | id | %space_id% | - | name | my project | + And the JSON response should contain space called "my project" and match + """ + { + "type": "object", + "required": [ + "driveType", + "name", + "id" + ], + "properties": { + "name": { + "type": "string", + "enum": ["my project"] + }, + "driveType": { + "type": "string", + "enum": ["project"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + } + } + } + """ And the json responded should not contain a space with name "Alice Hansen" @@ -85,14 +227,67 @@ Feature: List and create spaces Given the administrator has given "Alice" the role "" using the settings api When user "Alice" creates a space "Project Mars" of type "project" with the default quota using the GraphApi Then the HTTP status code should be "201" - And the json responded should contain a space "Project Mars" with these key and value pairs: - | key | value | - | driveType | project | - | driveAlias | project/project-mars | - | name | Project Mars | - | quota@@@total | 1000000000 | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + And the JSON response should contain space called "Project Mars" and match + """ + { + "type": "object", + "required": [ + "driveType", + "driveAlias", + "name", + "id", + "quota", + "root", + "webUrl" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Mars"] + }, + "driveType": { + "type": "string", + "enum": ["project"] + }, + "driveAlias": { + "type": "string", + "enum": ["project/project-mars"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + }, + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "state": { + "type": "number", + "enum": [1000000000] + } + } + }, + "root": { + "type": "object", + "required": [ + "webDavUrl" + ], + "properties": { + "webDavUrl": { + "type": "string", + "enum": ["%base_url%/dav/spaces/%space_id%"] + } + } + }, + "webUrl": { + "type": "string", + "enum": ["%base_url%/f/%space_id%"] + } + } + } + """ Examples: | role | | Admin | @@ -103,13 +298,62 @@ Feature: List and create spaces Given the administrator has given "Alice" the role "" using the settings api When user "Alice" creates a space "Project Venus" of type "project" with quota "2000" using the GraphApi Then the HTTP status code should be "201" - And the json responded should contain a space "Project Venus" with these key and value pairs: - | key | value | - | driveType | project | - | name | Project Venus | - | quota@@@total | 2000 | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + And the JSON response should contain space called "Project Venus" and match + """ + { + "type": "object", + "required": [ + "driveType", + "name", + "id", + "quota", + "root", + "webUrl" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Venus"] + }, + "driveType": { + "type": "string", + "enum": ["project"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + }, + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "state": { + "type": "number", + "enum": [2000] + } + } + }, + "root": { + "type": "object", + "required": [ + "webDavUrl" + ], + "properties": { + "webDavUrl": { + "type": "string", + "enum": ["%base_url%/dav/spaces/%space_id%"] + } + } + }, + "webUrl": { + "type": "string", + "enum": ["%base_url%/f/%space_id%"] + } + } + } + """ Examples: | role | | Admin | @@ -118,44 +362,228 @@ Feature: List and create spaces Scenario: A user can list his personal space via multiple endpoints When user "Alice" lists all available spaces via the GraphApi with query "$filter=driveType eq 'personal'" - Then the json responded should contain a space "Alice Hansen" owned by "Alice" with these key and value pairs: - | key | value | - | driveType | personal | - | name | Alice Hansen | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | owner@@@user@@@id | %user_id% | - | webUrl | %base_url%/f/%space_id% | + Then the HTTP status code should be "200" + And the JSON response should contain space called "Alice Hansen" owned by "Alice" and match + """ + { + "type": "object", + "required": [ + "driveType", + "name", + "root", + "owner", + "webUrl" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Alice Hansen"] + }, + "driveType": { + "type": "string", + "enum": ["personal"] + }, + "root": { + "type": "object", + "required": [ + "webDavUrl" + ], + "properties": { + "webDavUrl": { + "type": "string", + "enum": ["%base_url%/dav/spaces/%space_id%"] + } + } + }, + "owner": { + "type": "object", + "required": [ + "user" + ], + "properties": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "type": "string", + "enum": ["%user_id%"] + } + } + }, + "webUrl": { + "type": "string", + "enum": ["%base_url%/f/%space_id%"] + } + } + } + """ When user "Alice" looks up the single space "Alice Hansen" via the GraphApi by using its id - Then the json responded should contain a space "Alice Hansen" with these key and value pairs: - | key | value | - | driveType | personal | - | name | Alice Hansen | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + Then the HTTP status code should be "200" + And the JSON response should contain space called "Alice Hansen" and match + """ + { + "type": "object", + "required": [ + "driveType", + "name", + "root", + "webUrl" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Alice Hansen"] + }, + "driveType": { + "type": "string", + "enum": ["personal"] + }, + "root": { + "type": "object", + "required": [ + "webDavUrl" + ], + "properties": { + "webDavUrl": { + "type": "string", + "enum": ["%base_url%/dav/spaces/%space_id%"] + } + } + }, + "webUrl": { + "type": "string", + "enum": ["%base_url%/f/%space_id%"] + } + } + } + """ Scenario Outline: A user can list his created spaces via multiple endpoints Given the administrator has given "Alice" the role "" using the settings api When user "Alice" creates a space "Project Venus" of type "project" with quota "2000" using the GraphApi Then the HTTP status code should be "201" - And the json responded should contain a space "Project Venus" with these key and value pairs: - | key | value | - | driveType | project | - | driveAlias | project/project-venus | - | name | Project Venus | - | quota@@@total | 2000 | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + And the JSON response should contain space called "Project Venus" and match + """ + { + "type": "object", + "required": [ + "driveType", + "driveAlias", + "name", + "id", + "quota", + "root", + "webUrl" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Venus"] + }, + "driveType": { + "type": "string", + "enum": ["project"] + }, + "driveAlias": { + "type": "string", + "enum": ["project/project-venus"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + }, + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "total": { + "type": "number", + "enum": [2000] + } + } + }, + "root": { + "type": "object", + "required": [ + "webDavUrl" + ], + "properties": { + "webDavUrl": { + "type": "string", + "enum": ["%base_url%/dav/spaces/%space_id%"] + } + } + } + } + } + """ When user "Alice" looks up the single space "Project Venus" via the GraphApi by using its id Then the HTTP status code should be "200" - And the json responded should contain a space "Project Venus" with these key and value pairs: - | key | value | - | driveType | project | - | driveAlias | project/project-venus | - | name | Project Venus | - | quota@@@total | 2000 | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + And the JSON response should contain space called "Project Venus" and match + """ + { + "type": "object", + "required": [ + "driveType", + "driveAlias", + "name", + "id", + "quota", + "root", + "webUrl" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Venus"] + }, + "driveType": { + "type": "string", + "enum": ["project"] + }, + "driveAlias": { + "type": "string", + "enum": ["project/project-venus"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + }, + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "total": { + "type": "number", + "enum": [2000] + } + } + }, + "root": { + "type": "object", + "required": [ + "webDavUrl" + ], + "properties": { + "webDavUrl": { + "type": "string", + "enum": ["%base_url%/dav/spaces/%space_id%"] + } + } + }, + "webUrl": { + "type": "string", + "enum": ["%base_url%/f/%space_id%"] + } + } + } + """ Examples: | role | | Admin | diff --git a/tests/acceptance/features/apiSpaces/quota.feature b/tests/acceptance/features/apiSpaces/quota.feature index 3ba1bc5d8e..bbb973aaee 100644 --- a/tests/acceptance/features/apiSpaces/quota.feature +++ b/tests/acceptance/features/apiSpaces/quota.feature @@ -20,13 +20,49 @@ Feature: State of the quota Scenario Outline: Quota information is returned in the list of spaces returned via the Graph API Given user "Alice" has created a space "" of type "project" with quota "" When user "Alice" uploads a file inside space "" with content "" to "test.txt" using the WebDAV API - Then the user "Alice" should have a space called "" with these key and value pairs: - | key | value | - | name | | - | quota@@@state | | - | quota@@@total | | - | quota@@@remaining| | - | quota@@@used | | + Then for user "Alice" the JSON response should contain space called "" and match + """ + { + "type": "object", + "required": [ + "name", + "quota" + ], + "properties": { + "name": { + "type": "string", + "enum": [""] + }, + "quota": { + "type": "object", + "required": [ + "state", + "total", + "remaining", + "used" + ], + "properties": { + "state" : { + "type": "string", + "enum": [""] + }, + "total" : { + "type": "number", + "enum": [] + }, + "remaining" : { + "type": "number", + "enum": [] + }, + "used": { + "type": "number", + "enum": [] + } + } + } + } + } + """ Examples: | spaceName | fileContent | state | total | remaining | used | | Quota1% | 1 | normal | 100 | 99 | 1 | diff --git a/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature b/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature index 90eecbaf3c..a136cfba2f 100644 --- a/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature +++ b/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature @@ -65,10 +65,34 @@ Feature: Remove files, folder And for user "" the space "delete objects" contain these entries: | text.txt | And as "" file "text.txt" exist in the trashbin of the space "delete objects" - And the user "" should have a space called "delete objects" with these key and value pairs: - | key | value | - | name | delete objects | - | quota@@@used | | + And for user "" the JSON response should contain space called "delete objects" and match + """ + { + "type": "object", + "required": [ + "name", + "quota" + ], + "properties": { + "name": { + "type": "string", + "enum": ["delete objects"] + }, + "quota": { + "type": "object", + "required": [ + "used" + ], + "properties": { + "used": { + "type": "number", + "enum": [] + } + } + } + } + } + """ Examples: | user | role | code | shouldOrNotBeInSpace | shouldOrNotBeInTrash | quotaValue | | Alice | manager | 204 | should not | should | 0 | @@ -80,6 +104,18 @@ Feature: Remove files, folder Scenario: An user is unable to delete a Space via the webDav API When user "Alice" removes the folder "" from space "delete objects" Then the HTTP status code should be "405" - And the user "Alice" should have a space called "delete objects" with these key and value pairs: - | key | value | - | name | delete objects | + And for user "Alice" the JSON response should contain space called "delete objects" and match + """ + { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["delete objects"] + } + } + } + """ diff --git a/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature b/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature index 52cbdf99cb..f22920d813 100644 --- a/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature +++ b/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature @@ -82,11 +82,40 @@ Feature: Restore files, folder When user "Brian" restores version index "1" of file "/file.txt" using the WebDAV API Then the HTTP status code should be "204" And the content of file "/file.txt" for user "Brian" should be "file is less than 30 bytes" - And the user "Brian" should have a space called "Brian Murphy" with these key and value pairs: - | key | value | - | quota@@@total | 30 | - | quota@@@used | 38 | - | quota@@@state | exceeded | + And for user "Brian" the JSON response should contain space called "Brian Murphy" and match + """ + { + "type": "object", + "required": [ + "quota" + ], + "properties": { + "quota": { + "type": "object", + "required": [ + "state", + "total", + "remaining", + "used" + ], + "properties": { + "state" : { + "type": "string", + "enum": ["exceeded"] + }, + "total" : { + "type": "number", + "enum": [30] + }, + "used": { + "type": "number", + "enum": [38] + } + } + } + } + } + """ Scenario: The recipient can restore a file even if there is not enough owner's quota to do so @@ -100,8 +129,37 @@ Feature: Restore files, folder When user "Alice" restores version index "1" of file "/Shares/file.txt" using the WebDAV API Then the HTTP status code should be "204" And the content of file "/Shares/file.txt" for user "Alice" should be "file is less than 30 bytes" - And the user "Brian" should have a space called "Brian Murphy" with these key and value pairs: - | key | value | - | quota@@@total | 30 | - | quota@@@used | 38 | - | quota@@@state | exceeded | + And for user "Brian" the JSON response should contain space called "Brian Murphy" and match + """ + { + "type": "object", + "required": [ + "quota" + ], + "properties": { + "quota": { + "type": "object", + "required": [ + "state", + "total", + "remaining", + "used" + ], + "properties": { + "state" : { + "type": "string", + "enum": ["exceeded"] + }, + "total" : { + "type": "number", + "enum": [30] + }, + "used": { + "type": "number", + "enum": [38] + } + } + } + } + } + """ diff --git a/tests/acceptance/features/apiSpaces/spaceManagement.feature b/tests/acceptance/features/apiSpaces/spaceManagement.feature index b0b0307b95..e8dc5fb071 100644 --- a/tests/acceptance/features/apiSpaces/spaceManagement.feature +++ b/tests/acceptance/features/apiSpaces/spaceManagement.feature @@ -24,22 +24,62 @@ Feature: Space management Scenario: The space admin user can see another project space even if he is not member of the space When user "Brian" lists all spaces via the GraphApi with query "$filter=driveType eq 'project'" Then the HTTP status code should be "200" - And the json responded should contain a space "Project" with these key and value pairs: - | key | value | - | driveType | project | - | id | %space_id% | - | name | Project | + And the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "driveType", + "name", + "id" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project"] + }, + "driveType": { + "type": "string", + "enum": ["project"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + } + } + } + """ And the json responded should not contain a space with name "Alice Hansen" Scenario: The space admin user can see another personal spaces When user "Brian" lists all spaces via the GraphApi with query "$filter=driveType eq 'personal'" Then the HTTP status code should be "200" - And the json responded should contain a space "Alice Hansen" with these key and value pairs: - | key | value | - | driveType | personal | - | id | %space_id% | - | name | Alice Hansen | + And the JSON response should contain space called "Alice Hansen" and match + """ + { + "type": "object", + "required": [ + "driveType", + "name", + "id" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Alice Hansen"] + }, + "driveType": { + "type": "string", + "enum": ["personal"] + }, + "id": { + "type": "string", + "enum": ["%space_id%"] + } + } + } + """ And the json responded should not contain a space with name "Project" @@ -53,75 +93,235 @@ Feature: Space management Scenario: The space admin user changes the quota of the project space When user "Brian" changes the quota of the "Project" space to "20" owned by user "Alice" Then the HTTP status code should be "200" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | quota@@@total | 20 | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "quota" + ], + "properties": { + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "total": { + "type": "number", + "enum": [20] + } + } + } + } + } + """ Scenario: The user without space admin permissions tries to change the quota of the project space When user "Carol" tries to change the quota of the "Project" space to "20" owned by user "Alice" Then the HTTP status code should be "401" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | quota@@@total | 10 | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "quota" + ], + "properties": { + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "total": { + "type": "number", + "enum": [10] + } + } + } + } + } + """ Scenario: The space admin user tries to change the quota of the personal space When user "Brian" tries to change the quota of the "Alice Hansen" space to "20" owned by user "Alice" Then the HTTP status code should be "401" - And the user "Alice" should have a space called "Alice Hansen" with these key and value pairs: - | key | value | - | quota@@@total | 10 | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "quota" + ], + "properties": { + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "total": { + "type": "number", + "enum": [10] + } + } + } + } + } + """ Scenario: The user without space admin permissions tries to change the quota of the personal space When user "Carol" tries to change the quota of the "Alice Hansen" space to "20" owned by user "Alice" Then the HTTP status code should be "401" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | quota@@@total | 10 | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "quota" + ], + "properties": { + "quota": { + "type": "object", + "required": [ + "total" + ], + "properties": { + "total": { + "type": "number", + "enum": [10] + } + } + } + } + } + """ Scenario: The space admin user changes the name of the project space When user "Brian" changes the name of the "Project" space to "New Name" owned by user "Alice" Then the HTTP status code should be "200" - And the user "Alice" should have a space called "New Name" with these key and value pairs: - | key | value | - | name | New Name | + And for user "Alice" the JSON response should contain space called "New Name" and match + """ + { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["New Name"] + } + } + } + """ Scenario: The user without space admin permissions tries to change the name of the project space When user "Carol" tries to change the name of the "Project" space to "New Name" owned by user "Alice" Then the HTTP status code should be "403" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | name | Project | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project"] + } + } + } + """ Scenario: The space admin user changes the description of the project space When user "Brian" changes the description of the "Project" space to "New description" owned by user "Alice" Then the HTTP status code should be "200" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | description | New description | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "description" + ], + "properties": { + "description": { + "type": "string", + "enum": ["New description"] + } + } + } + """ Scenario: The user without space admin permissions tries to change the description of the project space Given user "Alice" has changed the description of the "Project" space to "old description" When user "Carol" tries to change the description of the "Project" space to "New description" owned by user "Alice" Then the HTTP status code should be "403" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | description | old description | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "description" + ], + "properties": { + "description": { + "type": "string", + "enum": ["old description"] + } + } + } + """ Scenario: The space admin user disables the project space When user "Brian" disables a space "Project" owned by user "Alice" Then the HTTP status code should be "204" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | name | Project | - | root@@@deleted@@@state | trashed | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "name", + "root" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project"] + }, + "root": { + "type": "object", + "required": [ + "deleted" + ], + "properties": { + "deleted": { + "type": "object", + "required": [ + "state" + ], + "properties": { + "state": { + "type": "string", + "enum": ["trashed"] + } + } + } + } + } + } + } + """ Scenario: The user without space admin permissions tries to disable the project space @@ -149,10 +349,42 @@ Feature: Space management Given user "Alice" has disabled a space "Project" When user "Carol" tries to delete a space "Project" owned by user "Alice" Then the HTTP status code should be "403" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | name | Project | - | root@@@deleted@@@state | trashed | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "name", + "root" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project"] + }, + "root": { + "type": "object", + "required": [ + "deleted" + ], + "properties": { + "deleted": { + "type": "object", + "required": [ + "state" + ], + "properties": { + "state": { + "type": "string", + "enum": ["trashed"] + } + } + } + } + } + } + } + """ Scenario: The space admin user enables the project space @@ -165,7 +397,39 @@ Feature: Space management Given user "Alice" has disabled a space "Project" When user "Carol" tries to restore a disabled space "Project" owned by user "Alice" Then the HTTP status code should be "404" - And the user "Alice" should have a space called "Project" with these key and value pairs: - | key | value | - | name | Project | - | root@@@deleted@@@state | trashed | + And for user "Alice" the JSON response should contain space called "Project" and match + """ + { + "type": "object", + "required": [ + "name", + "root" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project"] + }, + "root": { + "type": "object", + "required": [ + "deleted" + ], + "properties": { + "deleted": { + "type": "object", + "required": [ + "state" + ], + "properties": { + "state": { + "type": "string", + "enum": ["trashed"] + } + } + } + } + } + } + } + """ diff --git a/tests/acceptance/features/apiSpaces/uploadSpaces.feature b/tests/acceptance/features/apiSpaces/uploadSpaces.feature index b328b7c2d4..d220f529d3 100644 --- a/tests/acceptance/features/apiSpaces/uploadSpaces.feature +++ b/tests/acceptance/features/apiSpaces/uploadSpaces.feature @@ -40,6 +40,34 @@ Feature: Upload files into a space Then the HTTP status code should be "" And for user "Brian" the space "Project Ceres" contain these entries: | test.txt | + And for user "Brian" the JSON response should contain space called "Project Ceres" and match + """ + { + "type": "object", + "required": [ + "name", + "quota" + ], + "properties": { + "name": { + "type": "string", + "enum": ["Project Ceres"] + }, + "quota": { + "type": "object", + "required": [ + "used" + ], + "properties": { + "used": { + "type": "number", + "enum": [] + } + } + } + } + } + """ And the user "Brian" should have a space called "Project Ceres" with these key and value pairs: | key | value | | name | Project Ceres | diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index b6a02f96e5..33bacf4408 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -1576,15 +1576,16 @@ class FeatureContext extends BehatVariablesContext { } /** - * @param PyStringNode $schemaString + * @param PyStringNode|string $schemaString * * @return mixed */ - private function getJSONSchema(PyStringNode $schemaString) { - $schemaRawString = $schemaString->getRaw(); - // substitute the inline codes or values - $schemaRawString = $this->substituteInLineCodes($schemaRawString); - $schema = json_decode($schemaRawString); + public function getJSONSchema($schemaString) { + if (\gettype($schemaString) !== 'string') { + $schemaString = $schemaString->getRaw(); + } + $schemaString = $this->substituteInLineCodes($schemaString); + $schema = \json_decode($schemaString); Assert::assertNotNull($schema, 'schema is not valid JSON'); return $schema; } @@ -1605,6 +1606,25 @@ class FeatureContext extends BehatVariablesContext { return null; } + /** + * @Then the ocs JSON data of the response should match + * + * @param PyStringNode $schemaString + * + * @return void + * + * @throws Exception + */ + public function theOcsDataOfTheResponseShouldMatch( + PyStringNode $schemaString + ): void { + $jsonResponse = $this->getJsonDecodedResponseBodyContent(); + JsonAssertions::assertJsonDocumentMatchesSchema( + $jsonResponse->ocs->data, + $this->getJSONSchema($schemaString) + ); + } + /** * @Then the JSON data of the response should match * @@ -1614,12 +1634,10 @@ class FeatureContext extends BehatVariablesContext { * * @throws Exception */ - public function theDataOfTheResponseShouldMatch( - PyStringNode $schemaString - ): void { - $jsonResponse = $this->getJsonDecodedResponseBodyContent(); + public function theDataOfTheResponseShouldMatch(PyStringNode $schemaString): void { + $responseBody = $this->getJsonDecodedResponseBodyContent(); JsonAssertions::assertJsonDocumentMatchesSchema( - $jsonResponse->ocs->data, + $responseBody, $this->getJSONSchema($schemaString) ); } @@ -3204,16 +3222,26 @@ class FeatureContext extends BehatVariablesContext { "parameter" => [] ], [ - "code" => "%user_id%", - "function" => - [$this, "getUserIdByUserName"], - "parameter" => [$userName] + "code" => "%group_id_pattern%", + "function" => [ + __NAMESPACE__ . '\TestHelpers\GraphHelper', + "getUUIDv4Regex" + ], + "parameter" => [] ], [ - "code" => "%group_id%", - "function" => - [$this, "getGroupIdByGroupName"], - "parameter" => [$group] + "code" => "%user_id%", + "function" => [ + $this, "getUserIdByUserName" + ], + "parameter" => [$userName] + ], + [ + "code" => "%group_id%", + "function" => [ + $this, "getGroupIdByGroupName" + ], + "parameter" => [$group] ] ]; if ($user !== null) { diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index f54ae8bc08..1ebbb46d46 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -24,8 +24,10 @@ declare(strict_types=1); use Behat\Behat\Context\Context; use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; use GuzzleHttp\Exception\GuzzleException; +use Helmich\JsonAssert\JsonAssertions; use Psr\Http\Message\ResponseInterface; use TestHelpers\HttpRequestHelper; use TestHelpers\WebDavHelper; @@ -402,7 +404,7 @@ class SpacesContext implements Context { */ public function getETag(string $user, string $spaceName, string $fileName): string { $fileData = $this->getFileData($user, $spaceName, $fileName)->getHeaders(); - return $fileData["Etag"][0]; + return \str_replace('"', '\"', $fileData["Etag"][0]); } /** @@ -1034,6 +1036,95 @@ class SpacesContext implements Context { $this->jsonRespondedShouldContain($spaceName, null, null, $grantedGroup, $table); } + /** + * @Then /^the JSON response should contain space called "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )(?:|(?:with description file|with space image) "([^"]*)" )and match$/ + * + * @param string $spaceName + * @param string|null $userName + * @param string|null $fileName + * @param PyStringNode $schemaString + * + * @return void + * @throws Exception + */ + public function theJsonDataFromLastResponseShouldMatch( + string $spaceName, + ?string $userName = null, + ?string $fileName = null, + PyStringNode $schemaString + ): void { + if (isset($this->featureContext->getJsonDecodedResponseBodyContent()->value)) { + $responseBody = $this->featureContext->getJsonDecodedResponseBodyContent()->value; + foreach ($responseBody as $value) { + if (isset($value->name) && $value->name === $spaceName) { + $responseBody = $value; + break; + } + } + } else { + $responseBody = $this->featureContext->getJsonDecodedResponseBodyContent(); + } + + // substitute the value here + $schemaString = $schemaString->getRaw(); + $schemaString = $this->featureContext->substituteInLineCodes( + $schemaString, + $this->featureContext->getCurrentUser(), + [], + [ + [ + "code" => "%space_id%", + "function" => + [$this, "getSpaceIdByNameFromResponse"], + "parameter" => [$spaceName] + ], + [ + "code" => "%file_id%", + "function" => + [$this, "getFileId"], + "parameter" => [$userName, $spaceName, $fileName] + ], + [ + "code" => "%eTag%", + "function" => + [$this, "getETag"], + "parameter" => [$userName, $spaceName, $fileName] + ], + ], + null, + $userName, + ); + JsonAssertions::assertJsonDocumentMatchesSchema( + $responseBody, + $this->featureContext->getJSONSchema($schemaString) + ); + } + + /** + * @Then /^for user "([^"]*)" the JSON response of space project should match$/ + * @Then /^for user "([^"]*)" the JSON response should contain space called "([^"]*)" and match$/ + * @Then /^for user "([^"]*)" the JSON response should contain space called "([^"]*)" (?:owned by|granted to) "([^"]*)" (?:with description file|with space image) "([^"]*)" and match$/ + + * @param string $user + * @param string $spaceName + * @param string|null $grantedUser + * @param string|null $fileName + * @param PyStringNode $schemaString + * + * @return void + * @throws Exception|GuzzleException + */ + public function forUserTheJSONDataOfTheResponseShouldMatch( + string $user, + ?string $spaceName = null, + ?string $grantedUser = null, + ?string $fileName = null, + PyStringNode $schemaString + ): void { + $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $this->theJsonDataFromLastResponseShouldMatch($spaceName, $grantedUser, $fileName, $schemaString); + } + /** * @Then /^the user "([^"]*)" should have a space called "([^"]*)" granted to "([^"]*)" with role "([^"]*)"$/ * diff --git a/tests/acceptance/features/coreApiCapabilities/capabilities.feature b/tests/acceptance/features/coreApiCapabilities/capabilities.feature index a6ddc751b1..f1afe49697 100644 --- a/tests/acceptance/features/coreApiCapabilities/capabilities.feature +++ b/tests/acceptance/features/coreApiCapabilities/capabilities.feature @@ -56,7 +56,7 @@ Feature: capabilities When the administrator retrieves the capabilities using the capabilities API Then the OCS status code should be "100" And the HTTP status code should be "200" - And the JSON data of the response should match + And the ocs JSON data of the response should match """ { "type": "object", @@ -95,7 +95,7 @@ Feature: capabilities When the administrator retrieves the capabilities using the capabilities API Then the OCS status code should be "100" And the HTTP status code should be "200" - And the JSON data of the response should match + And the ocs JSON data of the response should match """ { "type": "object", @@ -134,7 +134,7 @@ Feature: capabilities When the administrator retrieves the capabilities using the capabilities API Then the OCS status code should be "100" And the HTTP status code should be "200" - And the JSON data of the response should match + And the ocs JSON data of the response should match """ { "type": "object", @@ -173,7 +173,7 @@ Feature: capabilities When the administrator retrieves the capabilities using the capabilities API Then the OCS status code should be "100" And the HTTP status code should be "200" - And the JSON data of the response should match + And the ocs JSON data of the response should match """ { "type": "object", @@ -212,7 +212,7 @@ Feature: capabilities @smokeTest Scenario: getting default capabilities with admin user When the administrator retrieves the capabilities using the capabilities API - And the JSON data of the response should match + And the ocs JSON data of the response should match """ { "type": "object", diff --git a/tests/acceptance/features/coreApiCapabilities/capabilitiesWithNormalUser.feature b/tests/acceptance/features/coreApiCapabilities/capabilitiesWithNormalUser.feature index 82d7996ff0..3eedd135fe 100644 --- a/tests/acceptance/features/coreApiCapabilities/capabilitiesWithNormalUser.feature +++ b/tests/acceptance/features/coreApiCapabilities/capabilitiesWithNormalUser.feature @@ -12,7 +12,7 @@ Feature: default capabilities for normal user When user "Alice" retrieves the capabilities using the capabilities API Then the OCS status code should be "100" And the HTTP status code should be "200" - And the JSON data of the response should match + And the ocs JSON data of the response should match """ { "type": "object",