diff --git a/tests/acceptance/features/apiSharingNg/sharedWithMe.feature b/tests/acceptance/features/apiSharingNg/sharedWithMe.feature index 27cedc87b..7aa05959e 100755 --- a/tests/acceptance/features/apiSharingNg/sharedWithMe.feature +++ b/tests/acceptance/features/apiSharingNg/sharedWithMe.feature @@ -20,7 +20,7 @@ Feature: an user gets the resources shared to them | sharee | Brian | | shareType | user | | permissionsRole | | - When user "Brian" lists the shares shared with him after clearing user cache using the Graph API + When user "Brian" lists the shares shared with him using the Graph API Then the HTTP status code should be "200" And the JSON data of the response should match """ diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index c98c22f04..e3a0f0e55 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -167,6 +167,39 @@ class FeatureContext extends BehatVariablesContext { private array $lastHttpStatusCodesArray = []; private array $lastOCSStatusCodesArray = []; + /** + * Store for auto-sync settings for users + */ + private array $autoSyncSettings = []; + + /** + * @param string $user + * + * @return bool + */ + public function getUserAutoSyncSetting(string $user): bool { + if (\array_key_exists($user, $this->autoSyncSettings)) { + return $this->autoSyncSettings[$user]; + } + // auto-sync is enabled by default + return true; + } + + /** + * @param string $user + * @param bool $value + * + * @return void + */ + public function rememberUserAutoSyncSetting(string $user, bool $value): void { + $this->autoSyncSettings[$user] = $value; + } + + /** + * this is set true for db conversion tests + */ + private bool $dbConversion = false; + public const SHARES_SPACE_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668'; private bool $useSharingNG = false; diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index ba681a4b9..8b371f790 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2503,14 +2503,38 @@ class GraphContext implements Context { } $credentials = $this->getAdminOrUserCredentials($user); - $this->featureContext->setResponse( - GraphHelper::getSharesSharedWithMe( + + // Sometimes listing shares might not return the updated shares list + // so try again until @client.synchronize is true for the max. number of retries (i.e. 10) + // and do not retry when the share is expected to be not synced + $tryAgain = false; + $retried = 0; + do { + $response = GraphHelper::getSharesSharedWithMe( $this->featureContext->getBaseUrl(), $this->featureContext->getStepLineRef(), $credentials['username'], $credentials['password'] - ) - ); + ); + + $jsonObj = $this->featureContext->getJsonDecodedResponseBodyContent($response); + + foreach ($jsonObj->value as $share) { + $autoSync = $this->featureContext->getUserAutoSyncSetting($credentials['username']); + $tryAgain = !$share->{'@client.synchronize'} && $autoSync && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly(); + + if ($tryAgain) { + $retried += 1; + echo "auto-sync share for user '$user' is enabled\n"; + echo "but share '$share->name' was not auto-synced, retrying ($retried)...\n"; + // wait 500ms and try again + \usleep(500 * 1000); + break; + } + } + } while ($tryAgain); + + $this->featureContext->setResponse($response); $this->featureContext->pushToLastStatusCodesArrays(); } diff --git a/tests/acceptance/features/bootstrap/SettingsContext.php b/tests/acceptance/features/bootstrap/SettingsContext.php index a66288a6e..b5739178d 100644 --- a/tests/acceptance/features/bootstrap/SettingsContext.php +++ b/tests/acceptance/features/bootstrap/SettingsContext.php @@ -541,5 +541,6 @@ class SettingsContext implements Context { "Expected response status code should be 201", $response ); + $this->featureContext->rememberUserAutoSyncSetting($user, false); } }