Skip to content

Commit d790d87

Browse files
committed
test: store setting id per user
Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>
1 parent 9cd6885 commit d790d87

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

tests/acceptance/TestHelpers/GraphHelper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,6 @@ public static function hideOrUnhideShare(
20092009
* @param string $user
20102010
* @param string $password
20112011
* @param string $itemId
2012-
* @param string $shareSpaceId
20132012
*
20142013
* @return ResponseInterface
20152014
* @throws GuzzleException
@@ -2019,14 +2018,13 @@ public static function enableShareSync(
20192018
string $user,
20202019
string $password,
20212020
string $itemId,
2022-
string $shareSpaceId,
20232021
): ResponseInterface {
20242022
$body = [
20252023
"remoteItem" => [
20262024
"id" => $itemId,
20272025
],
20282026
];
2029-
$url = self::getBetaFullUrl($baseUrl, "drives/$shareSpaceId/root/children");
2027+
$url = self::getBetaFullUrl($baseUrl, "drives/" . GraphHelper::SHARES_SPACE_ID . "/root/children");
20302028
return HttpRequestHelper::post(
20312029
$url,
20322030
$user,

tests/acceptance/bootstrap/SettingsContext.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
*/
2727
class SettingsContext implements Context {
2828
private FeatureContext $featureContext;
29-
private string $settingsUrl = '/api/v0/settings/';
30-
private string $autoAcceptSharesSettingId = '';
29+
private array $autoAcceptSharesSettingIds = [];
3130

3231
/**
3332
* This will run before EVERY scenario.
@@ -46,6 +45,29 @@ public function before(BeforeScenarioScope $scope): void {
4645
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
4746
}
4847

48+
/**
49+
* @param string $user
50+
*
51+
* @return string
52+
*/
53+
public function getAutoAcceptShareSettingId(string $user): string {
54+
if (!empty($this->autoAcceptSharesSettingIds) && \array_key_exists($user, $this->autoAcceptSharesSettingIds)) {
55+
return $this->autoAcceptSharesSettingIds[$user];
56+
57+
}
58+
return '';
59+
}
60+
61+
/**
62+
* @param string $user
63+
* @param string $id
64+
*
65+
* @return void
66+
*/
67+
public function setAutoAcceptShareSettingId(string $user, string $id): void {
68+
$this->autoAcceptSharesSettingIds[$user] = $id;
69+
}
70+
4971
/**
5072
* @param string $user
5173
*
@@ -499,9 +521,10 @@ public function toggleAutoAcceptSharesSetting(string $user, bool $status): Respo
499521
"boolValue" => $status,
500522
],
501523
];
502-
if ($this->autoAcceptSharesSettingId) {
524+
$autoAcceptSharesSettingId = $this->getAutoAcceptShareSettingId($user);
525+
if ($autoAcceptSharesSettingId) {
503526
// use existing id if available
504-
$body["value"]["id"] = $this->autoAcceptSharesSettingId;
527+
$body["value"]["id"] = $autoAcceptSharesSettingId;
505528
}
506529
$body = json_encode($body, JSON_THROW_ON_ERROR);
507530

@@ -511,11 +534,11 @@ public function toggleAutoAcceptSharesSetting(string $user, bool $status): Respo
511534
$this->featureContext->getPasswordForUser($user),
512535
$body,
513536
);
514-
if (empty($this->autoAcceptSharesSettingId) && $response->getStatusCode() === 201) {
537+
if (!$autoAcceptSharesSettingId && $response->getStatusCode() === 201) {
515538
// save id for future use
516539
// updating the setting without id will create a new setting entry
517540
$data = $this->featureContext->getJsonDecodedResponseBodyContent($response);
518-
$this->autoAcceptSharesSettingId = $data->value->value->id;
541+
$this->setAutoAcceptShareSettingId($user, $data->value->value->id);
519542
}
520543
$response->getBody()->rewind();
521544
return $response;

tests/acceptance/bootstrap/SharingNgContext.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,13 +1512,11 @@ public function userEnablesSyncOfShareUsingTheGraphApi(
15121512
): void {
15131513
$share = ltrim($share, '/');
15141514
$itemId = $this->spacesContext->getResourceId($offeredBy, $space, $share);
1515-
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
15161515
$response = GraphHelper::enableShareSync(
15171516
$this->featureContext->getBaseUrl(),
15181517
$this->featureContext->getActualUsername($user),
15191518
$this->featureContext->getPasswordForUser($user),
15201519
$itemId,
1521-
$shareSpaceId,
15221520
);
15231521
$this->featureContext->setResponse($response);
15241522
}
@@ -1542,7 +1540,6 @@ public function userEnablesSyncOfFederatedShareUsingTheGraphApi(
15421540
$this->featureContext->getActualUsername($user),
15431541
$this->featureContext->getPasswordForUser($user),
15441542
$remoteItemId,
1545-
GraphHelper::SHARES_SPACE_ID,
15461543
);
15471544
$this->featureContext->setResponse($response);
15481545
}
@@ -1560,15 +1557,13 @@ public function userEnablesSyncOfFederatedShareUsingTheGraphApi(
15601557
* @throws Exception|GuzzleException
15611558
*/
15621559
public function userTriesToEnableShareSyncOfResourceUsingTheGraphApi(string $user, string $resource): void {
1563-
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
15641560
$itemId = ($resource === 'nonexistent') ? WebDavHelper::generateUUIDv4() : $resource;
15651561

15661562
$response = GraphHelper::enableShareSync(
15671563
$this->featureContext->getBaseUrl(),
15681564
$this->featureContext->getActualUsername($user),
15691565
$this->featureContext->getPasswordForUser($user),
15701566
$itemId,
1571-
$shareSpaceId,
15721567
);
15731568
$this->featureContext->setResponse($response);
15741569
}

0 commit comments

Comments
 (0)