[tests-only][full-ci]Add tests for share invite on drives root (#8850)

* add tests for root share invite

* add more tests scenarios
This commit is contained in:
Amrita
2024-04-26 08:41:26 +02:00
committed by GitHub
parent 634680ee8f
commit edd3ac2ad0
3 changed files with 971 additions and 25 deletions
+83 -22
View File
@@ -1673,6 +1673,48 @@ class GraphHelper {
}
}
/**
* @param array $shareeIds
* @param array $shareTypes
* @param string|null $permissionsRole
* @param string|null $permissionsAction
* @param string|null $expireDate
*
* @return array
* @throws \Exception
*/
public static function createShareInviteBody(
array $shareeIds,
array $shareTypes,
?string $permissionsRole,
?string $permissionsAction,
?string $expireDate
): array {
$body = [];
foreach ($shareeIds as $index => $shareeId) {
$shareType = $shareTypes[$index];
$body['recipients'][] = [
"@libre.graph.recipient.type" => $shareType,
"objectId" => $shareeId
];
}
if ($permissionsRole !== null) {
$roleId = self::getPermissionsRoleIdByName($permissionsRole);
$body['roles'] = [$roleId];
}
if ($permissionsAction !== null) {
$body['@libre.graph.permissions.actions'] = ['libre.graph/driveItem/' . $permissionsAction];
}
if ($expireDate !== null) {
$body['expirationDateTime'] = $expireDate;
}
return $body;
}
/**
* @param string $baseUrl
* @param string $xRequestId
@@ -1704,28 +1746,7 @@ class GraphHelper {
?string $expireDate
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite");
$body = [];
foreach ($shareeIds as $index => $shareeId) {
$shareType = $shareTypes[$index];
$body['recipients'][] = [
"@libre.graph.recipient.type" => $shareType,
"objectId" => $shareeId
];
}
if ($permissionsRole !== null) {
$roleId = self::getPermissionsRoleIdByName($permissionsRole);
$body['roles'] = [$roleId];
}
if ($permissionsAction !== null) {
$body['@libre.graph.permissions.actions'] = ['libre.graph/driveItem/' . $permissionsAction];
}
if ($expireDate !== null) {
$body['expirationDateTime'] = $expireDate;
}
$body = self::createShareInviteBody($shareeIds, $shareTypes, $permissionsRole, $permissionsAction, $expireDate);
return HttpRequestHelper::post(
$url,
@@ -2040,4 +2061,44 @@ class GraphHelper {
self::getRequestHeaders()
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $spaceId
* @param array $shareeIds
* @param array $shareTypes
* @param string|null $permissionsRole
* @param string|null $permissionsAction
* @param string|null $expireDate
*
* @return ResponseInterface
* @throws \Exception|GuzzleException
*/
public static function sendSharingInvitationForDrive(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $spaceId,
array $shareeIds,
array $shareTypes,
?string $permissionsRole,
?string $permissionsAction,
?string $expireDate
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/root/invite");
$body = self::createShareInviteBody($shareeIds, $shareTypes, $permissionsRole, $permissionsAction, $expireDate);
return HttpRequestHelper::post(
$url,
$xRequestId,
$user,
$password,
self::getRequestHeaders(),
\json_encode($body)
);
}
}