adding test for updating role of a share (#8329)

This commit is contained in:
nirajacharya2
2024-02-08 14:52:22 +05:45
committed by GitHub
parent 26eb1d6121
commit d87f5b0316
4 changed files with 207 additions and 95 deletions
@@ -243,7 +243,7 @@ class SharingNgContext implements Context {
$response = $this->featureContext->shareNgGetLastCreatedUserGroupShare();
$permissionID = json_decode($response->getBody()->getContents())->value[0]->id;
$this->featureContext->setResponse(
$this->updateShare(
$this->updateResourceShare(
$user,
$table,
$permissionID
@@ -251,6 +251,41 @@ class SharingNgContext implements Context {
);
}
/**
* @param string $user
* @param TableNode $body
* @param string $permissionID
*
* @return ResponseInterface
*/
public function updateResourceShare(string $user, TableNode $body, string $permissionID): ResponseInterface {
$bodyRows = $body->getRowsHash();
$space = $bodyRows['space'];
$resource = $bodyRows['resource'];
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];
$itemId = $this->spacesContext->getResourceId($user, $space, $resource);
$body = [];
if (\array_key_exists('permissionsRole', $bodyRows)) {
$body["roles"] = [GraphHelper::getPermissionsRoleIdByName($bodyRows['permissionsRole'])];
}
if (\array_key_exists('expirationDateTime', $bodyRows)) {
$body["expirationDateTime"] = $bodyRows['expirationDateTime'];
}
return GraphHelper::updateShare(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$spaceId,
$itemId,
\json_encode($body),
$permissionID
);
}
/**
* @When user :user sends the following share invitation with file-id :fileId using the Graph API:
*
@@ -308,7 +343,7 @@ class SharingNgContext implements Context {
*/
public function userUpdatesLastPublicLinkShareUsingTheGraphApiWith(string $user, TableNode $body):void {
$this->featureContext->setResponse(
$this->updateShare(
$this->updateLinkShare(
$user,
$body,
$this->featureContext->shareNgGetLastCreatedLinkShareID()
@@ -323,35 +358,23 @@ class SharingNgContext implements Context {
*
* @return ResponseInterface
*/
public function updateShare(string $user, TableNode $body, string $permissionID): ResponseInterface {
public function updateLinkShare(string $user, TableNode $body, string $permissionID): ResponseInterface {
$bodyRows = $body->getRowsHash();
$space = $bodyRows['space'];
$resource = $bodyRows['resource'];
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];
$itemId = $this->spacesContext->getResourceId($user, $space, $resource);
$body = [];
if (\array_key_exists('role', $bodyRows) && \array_key_exists('expirationDateTime', $bodyRows)) {
$body = [
"expirationDateTime" => $bodyRows['expirationDateTime'],
"link" => [
"type" => $bodyRows['permissionsRole']
]
];
} elseif (\array_key_exists('permissionsRole', $bodyRows)) {
$body = [
"link" => [
"type" => $bodyRows['permissionsRole']
]
];
} elseif (\array_key_exists('expirationDateTime', $bodyRows)) {
$body = [
"expirationDateTime" => $bodyRows['expirationDateTime']
];
} else {
throw new Error('Expiration date or role is missing to update for share link!');
if (\array_key_exists('permissionsRole', $bodyRows)) {
$body["link"]["type"] = $bodyRows['permissionsRole'];
}
return GraphHelper::updateLinkShare(
if (\array_key_exists('expirationDateTime', $bodyRows)) {
$body["expirationDateTime"] = $bodyRows['expirationDateTime'];
}
return GraphHelper::updateShare(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,