Skip to content

Commit

Permalink
Added test for sending share invitation to user with permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
grgprarup committed Dec 21, 2023
1 parent e76f2ea commit 4cdc44b
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,7 @@ public static function getRoleIdByName(
* @param string $shareeId
* @param string $shareType
* @param string|null $role
* @param string|null $permission
*
* @return ResponseInterface
* @throws \JsonException
Expand All @@ -1594,7 +1595,8 @@ public static function sendSharingInvitation(
string $itemId,
string $shareeId,
string $shareType,
?string $role
?string $role,
?string $permission
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite");
$body = [];
Expand All @@ -1609,6 +1611,10 @@ public static function sendSharingInvitation(
$body['roles'] = [$roleId];
}

if ($permission !== null) {
$body['@libre.graph.permissions.actions'] = ['libre.graph/driveItem/' . $permission];
}

return HttpRequestHelper::post(
$url,
$xRequestId,
Expand Down
190 changes: 190 additions & 0 deletions tests/acceptance/features/apiSharingNg/shareInvitations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,193 @@ Feature: Send a sharing invitations
| Co Owner | folder | FolderToShare |
| Uploader | folder | FolderToShare |
| Manager | folder | FolderToShare |


Scenario Outline: send share invitation for file to user with different permissions
Given user "Alice" has uploaded file with content "to share" to "textfile1.txt"
When user "Alice" sends the following share invitation using the Graph API:
| resourceType | file |
| resource | textfile1.txt |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permission | <permission> |
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",
"items": {
"type": "object",
"required": [
"id",
"@libre.graph.permissions.actions",
"grantedToV2"
],
"properties": {
"id": {
"type": "string",
"pattern": "^%share_id_pattern%$"
},
"@libre.graph.permissions.actions": {
"type": "array",
"items": {
"type": "string",
"pattern": "^libre\\.graph\\/driveItem\\/<permission>$"
}
},
"grantedToV2": {
"type": "object",
"required": [
"user"
],
"properties": {
"user": {
"type": "object",
"required": [
"id",
"displayName"
],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"displayName": {
"type": "string",
"enum": [
"Brian Murphy"
]
}
}
}
}
}
}
}
}
}
}
"""
Examples:
| permission |
| permissions/read |
| children/create |
| upload/create |
| path/read |
| quota/read |
| content/read |
| permissions/read |
| children/read |
| versions/read |
| deleted/read |
| basic/read |
| path/update |
| versions/update |
| deleted/update |
| permissions/update |
| standard/delete |
| permissions/delete |
| deleted/delete |
| permissions/deny |


Scenario Outline: send share invitation for folder to user with different permissions
Given user "Alice" has created folder "FolderToShare"
When user "Alice" sends the following share invitation using the Graph API:
| resourceType | folder |
| resource | FolderToShare |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permission | <permission> |
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",
"items": {
"type": "object",
"required": [
"id",
"@libre.graph.permissions.actions",
"grantedToV2"
],
"properties": {
"id": {
"type": "string",
"pattern": "^%share_id_pattern%$"
},
"@libre.graph.permissions.actions": {
"type": "array",
"items": {
"type": "string",
"pattern": "^libre\\.graph\\/driveItem\\/<permission>$"
}
},
"grantedToV2": {
"type": "object",
"required": [
"user"
],
"properties": {
"user": {
"type": "object",
"required": [
"id",
"displayName"
],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"displayName": {
"type": "string",
"enum": [
"Brian Murphy"
]
}
}
}
}
}
}
}
}
}
}
"""
Examples:
| permission |
| permissions/read |
| children/create |
| upload/create |
| path/read |
| quota/read |
| content/read |
| permissions/read |
| children/read |
| versions/read |
| deleted/read |
| basic/read |
| path/update |
| versions/update |
| deleted/update |
| permissions/update |
| standard/delete |
| permissions/delete |
| deleted/delete |
| permissions/deny |
6 changes: 5 additions & 1 deletion tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public function userSendsTheFollowingShareInvitationUsingTheGraphApi(string $use
? $this->featureContext->getAttributeOfCreatedUser($rows['sharee'], 'id')
: $this->featureContext->getAttributeOfCreatedGroup($rows['sharee'], 'id');

$role = $rows['role'] ?? null;
$permission = $rows['permission'] ?? null;

$this->featureContext->setResponse(
GraphHelper::sendSharingInvitation(
$this->featureContext->getBaseUrl(),
Expand All @@ -114,7 +117,8 @@ public function userSendsTheFollowingShareInvitationUsingTheGraphApi(string $use
$itemId,
$shareeId,
$rows['shareType'],
$rows['role']
$role,
$permission
)
);
}
Expand Down

0 comments on commit 4cdc44b

Please sign in to comment.