[tests-only][full-ci]Added test to update role and expiration date for share link (v1beta1) (#8071)

* Added test to update role and expiration date for share link

Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com>

* Review address

---------

Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com>
This commit is contained in:
Sagar Gurung
2024-01-02 16:53:47 +05:45
committed by GitHub
parent a3a9757c48
commit 6e9b599195
5 changed files with 321 additions and 20 deletions
@@ -75,6 +75,11 @@ trait Sharing {
*/
private array $createdPublicShares = [];
/**
* @var array
*/
private array $shareNgCreatedLinkShares = [];
/**
* @return string
*/
@@ -98,6 +103,22 @@ trait Sharing {
$this->createdPublicShares[] = $shareData;
}
/**
* @param ResponseInterface $response
*
* @return void
*/
public function shareNgAddToCreatedLinkShares(ResponseInterface $response): void {
$this->shareNgCreatedLinkShares[] = $response;
}
/**
* @return ResponseInterface|null
*/
public function shareNgGetLastCreatedLinkShare():?ResponseInterface {
return \end($this->shareNgCreatedLinkShares);
}
/**
* @param string $sharer
* @param SimpleXMLElement $shareData
@@ -152,6 +173,17 @@ trait Sharing {
return "/apps/files_sharing/api/v$this->sharingApiVersion/shares$postfix";
}
/**
* @return string
*/
public function shareNgGetLastCreatedLinkShareID(): string {
$lastResponse = $this->shareNgGetLastCreatedLinkShare();
if (!isset($this->getJsonDecodedResponse($lastResponse)['id'])) {
throw new Error('Response did not contain share id ' . $this->getJsonDecodedResponse($lastResponse)['id'] . ' for the created public link');
}
return $this->getJsonDecodedResponse($lastResponse)['id'];
}
/**
* Split given permissions string each separated with "," into array of strings
*
@@ -22,6 +22,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\GraphHelper;
use Behat\Gherkin\Node\TableNode;
@@ -52,6 +53,48 @@ class SharingNgContext implements Context {
$this->spacesContext = $environment->getContext('SpacesContext');
}
/**
* @param string $user
* @param TableNode|null $body
*
* @return ResponseInterface
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function createLinkShare(string $user, TableNode $body): ResponseInterface {
$bodyRows = $body->getRowsHash();
$space = $bodyRows['space'];
$resourceType = $bodyRows['resourceType'];
$resource = $bodyRows['resource'];
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];
if ($resourceType === 'folder') {
$itemId = $this->spacesContext->getResourceId($user, $space, $resource);
} else {
$itemId = $this->spacesContext->getFileId($user, $space, $resource);
}
$bodyRows['displayName'] = $bodyRows['displayName'] ?? null;
$bodyRows['expirationDateTime'] = $bodyRows['expirationDateTime'] ?? null;
$bodyRows['password'] = $bodyRows['password'] ?? null;
$body = [
'type' => $bodyRows['role'],
'displayName' => $bodyRows['displayName'],
'expirationDateTime' => $bodyRows['expirationDateTime'],
'password' => $this->featureContext->getActualPassword($bodyRows['password'])
];
return GraphHelper::createLinkShare(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$spaceId,
$itemId,
\json_encode($body)
);
}
/**
* @When /^user "([^"]*)" gets permissions list for (folder|file) "([^"]*)" of the space "([^"]*)" using the Graph API$/
*
@@ -132,14 +175,42 @@ class SharingNgContext implements Context {
* @param TableNode|null $body
*
* @return void
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function userCreatesAPublicLinkShareWithSettings(string $user, TableNode $body):void {
$response = $this->createLinkShare($user, $body);
$this->featureContext->setResponse($response);
}
/**
* @Given /^user "([^"]*)" has created the following link share:$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function userHasCreatedTheFollowingLinkShare(string $user, TableNode $body): void {
$response = $this->createLinkShare($user, $body);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Failed while creating public share link!", $response);
$this->featureContext->shareNgAddToCreatedLinkShares($response);
}
/**
* @When /^user "([^"]*)" updates the last public link share using the Graph API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function userUpdatesLastPublicLinkShareUsingTheGraphApiWith(string $user, TableNode $body):void {
$bodyRows = $body->getRowsHash();
$space = $bodyRows['space'];
$resourceType = $bodyRows['resourceType'];
$resource = $bodyRows['resource'];
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];
if ($resourceType === 'folder') {
$itemId = $this->spacesContext->getResourceId($user, $space, $resource);
@@ -147,25 +218,37 @@ class SharingNgContext implements Context {
$itemId = $this->spacesContext->getFileId($user, $space, $resource);
}
$bodyRows['displayName'] = $bodyRows['displayName'] ?? null;
$bodyRows['expirationDateTime'] = $bodyRows['expirationDateTime'] ?? null;
$bodyRows['password'] = $bodyRows['password'] ?? null;
$body = [
'type' => $bodyRows['role'],
'displayName' => $bodyRows['displayName'],
'expirationDateTime' => $bodyRows['expirationDateTime'],
'password' => $this->featureContext->getActualPassword($bodyRows['password'])
];
if (\array_key_exists('role', $bodyRows) && \array_key_exists('expirationDateTime', $bodyRows)) {
$body = [
"expirationDateTime" => $bodyRows['expirationDateTime'],
"link" => [
"type" => $bodyRows['role']
]
];
} elseif (\array_key_exists('role', $bodyRows)) {
$body = [
"link" => [
"type" => $bodyRows['role']
]
];
} 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!');
}
$this->featureContext->setResponse(
GraphHelper::createLinkShare(
GraphHelper::updateLinkShare(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$spaceId,
$itemId,
\json_encode($body)
\json_encode($body),
$this->featureContext->shareNgGetLastCreatedLinkShareID()
)
);
}