[full-ci][tests-only]Extend notification api tests (#6324)

* Add api tests for notification

* Address review
This commit is contained in:
Amrita
2023-05-24 12:56:43 +05:45
committed by GitHub
parent 3a93b44007
commit 53ee61ad87
6 changed files with 299 additions and 17 deletions
+52 -12
View File
@@ -3023,13 +3023,13 @@ trait Sharing {
public function userHasRemovedAllSharesFromTheFileNamed(string $user, string $fileName):void {
$user = $this->getActualUsername($user);
$this->removeAllSharesFromResource($user, $fileName);
$dataResponded = $this->getShares($user, $fileName);
$response = $this->getShares($user, $fileName);
Assert::assertEquals(
0,
\count($dataResponded),
\count($response),
__METHOD__
. " Expected all shares to be removed from '$fileName' but got '"
. \count($dataResponded)
. \count($response)
. "' shares still present"
);
}
@@ -3075,7 +3075,7 @@ trait Sharing {
*/
public function checkPublicShares(string $user, string $path, ?TableNode $TableNode):void {
$user = $this->getActualUsername($user);
$dataResponded = $this->getShares($user, $path);
$response = $this->getShares($user, $path);
$this->verifyTableNodeColumns($TableNode, ['path', 'permissions', 'name']);
if ($TableNode instanceof TableNode) {
@@ -3083,7 +3083,7 @@ trait Sharing {
foreach ($elementRows as $expectedElementsArray) {
$nameFound = false;
foreach ($dataResponded as $elementResponded) {
foreach ($response as $elementResponded) {
if ((string) $elementResponded->name[0] === $expectedElementsArray['name']) {
Assert::assertEquals(
$expectedElementsArray['path'],
@@ -3126,14 +3126,14 @@ trait Sharing {
public function checkPublicSharesAreEmpty(string $user, string $entry, string $path):void {
$user = $this->getActualUsername($user);
$this->asFileOrFolderShouldExist($user, $entry, $path);
$dataResponded = $this->getShares($user, $path);
$response = $this->getShares($user, $path);
//It shouldn't have public shares
Assert::assertEquals(
0,
\count($dataResponded),
\count($response),
__METHOD__
. " As '$user', '$path' was expected to have no shares, but got '"
. \count($dataResponded)
. \count($response)
. "' shares present"
);
}
@@ -3146,8 +3146,8 @@ trait Sharing {
* @return string|null
*/
public function getPublicShareIDByName(string $user, string $path, string $name):?string {
$dataResponded = $this->getShares($user, $path);
foreach ($dataResponded as $elementResponded) {
$response = $this->getShares($user, $path);
foreach ($response as $elementResponded) {
if ((string) $elementResponded->name[0] === $name) {
return (string) $elementResponded->id[0];
}
@@ -3236,9 +3236,9 @@ trait Sharing {
$user = $this->getActualUsername($user);
$offeredBy = $this->getActualUsername($offeredBy);
$dataResponded = $this->getAllSharesSharedWithUser($user);
$response = $this->getAllSharesSharedWithUser($user);
$shareId = null;
foreach ($dataResponded as $shareElement) {
foreach ($response as $shareElement) {
// SharingHelper::SHARE_STATES has the mapping between the words for share states
// like "accepted", "pending",... and the integer constants 0, 1,... that are in
// the "state" field of the share data.
@@ -3479,6 +3479,46 @@ trait Sharing {
);
}
/**
* @Given /^user "([^"]*)" has unshared (?:folder|file|entity) "([^"]*)" shared to "([^"]*)"$/
*
* @param string $sharer
* @param string $path
* @param string $sharee
*
* @return void
* @throws JsonException
*/
public function userHasUnsharedResourceSharedTo(string $sharer, string $path, string $sharee): void {
$sharer = $this->getActualUsername($sharer);
$sharee = $this->getActualUsername($sharee);
$response = $this->getShares($sharer, "$path&share_types=0");
$shareId = null;
foreach ($response as $shareElement) {
if ((string)$shareElement->share_with[0] === $sharee) {
$shareId = (string) $shareElement->id;
break;
}
}
Assert::assertNotNull(
$shareId,
__METHOD__ . " could not find share, offered by $sharer to $sharee"
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$sharer,
'DELETE',
'/apps/files_sharing/api/v' . $this->sharingApiVersion . '/shares/' . $shareId
);
$this->ocsContext->assertOCSResponseIndicatesSuccess(
'The ocs share response does not indicate success.',
);
$this->emptyLastHTTPStatusCodesArray();
$this->emptyLastOCSStatusCodesArray();
}
/**
* @Then the sharing API should report that no shares are shared with user :user
*