From 3476f27c59e75d735cff3bb002e04e6437b76f01 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Mon, 24 Jun 2024 18:02:40 +0545 Subject: [PATCH] test: add step to wait until shares are synced --- .../features/bootstrap/SharingNgContext.php | 60 +++++++++++++++++++ .../moveReceivedShare.feature | 1 + 2 files changed, 61 insertions(+) diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index f1268ec76..b1ecee7c2 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -26,6 +26,7 @@ use Psr\Http\Message\ResponseInterface; use TestHelpers\GraphHelper; use TestHelpers\OcisHelper; use TestHelpers\WebDavHelper; +use TestHelpers\HttpRequestHelper; use Behat\Gherkin\Node\TableNode; use PHPUnit\Framework\Assert; @@ -1240,6 +1241,65 @@ class SharingNgContext implements Context { $this->featureContext->setResponse($response); } + /** + * @param string $user + * @param string $resource + * + * @return void + * @throws GuzzleException + */ + public function isShareSynced(string $user, string $resource): bool { + $resource = \trim($resource, '/'); + $response = GraphHelper::getSharesSharedWithMe( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user) + ); + + $shares = $this->featureContext->getJsonDecodedResponse($response)["value"]; + $syncStatus = false; + foreach ($shares as $share) { + if ($share["name"] === $resource) { + $syncStatus = $share["@client.synchronize"]; + break; + } + } + return $syncStatus === true; + } + + /** + * @Then /^user "([^"]*)" has a share "([^"]*)" synced$/ + * + * @param string $user + * @param string $resource + * + * @return void + * @throws GuzzleException + */ + public function userHasShareSynced(string $user, string $resource): void { + $shareSynced = false; + + // Sharing is async so it might take some time for the share to be available + $retried = 0; + do { + $shareSynced = $this->isShareSynced($user, $resource); + + $tryAgain = !$shareSynced && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly(); + if ($tryAgain) { + $retried += 1; + echo "[INFO] Wait for shares to be available..."; + // wait 500ms and try again + \usleep(500 * 1000); + } + } while ($tryAgain); + + Assert::assertTrue( + $shareSynced, + "Share '$resource' is expected to be synced but not" + ); + } + /** * @Then /^user "([^"]*)" should have sync (enabled|disabled) for share "([^"]*)"$/ * diff --git a/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature b/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature index 21bd5d8fc..af64b596e 100644 --- a/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature +++ b/tests/acceptance/features/coreApiShareManagementToShares/moveReceivedShare.feature @@ -180,6 +180,7 @@ Feature: sharing | sharee | grp1 | | shareType | group | | permissionsRole | Viewer | + And user "Carol" has a share "/TMP" synced When user "Carol" moves folder "/Shares/TMP" to "/Shares/new" using the WebDAV API And the administrator deletes user "Carol" using the provisioning API Then the HTTP status code of responses on each endpoint should be "201, 204" respectively