|
27 | 27 | class SettingsContext implements Context { |
28 | 28 | private FeatureContext $featureContext; |
29 | 29 | private string $settingsUrl = '/api/v0/settings/'; |
| 30 | + private string $autoAcceptSharesSettingId = ''; |
30 | 31 |
|
31 | 32 | /** |
32 | 33 | * This will run before EVERY scenario. |
@@ -487,27 +488,37 @@ public function userSwitchesTheSystemLanguageUsingTheSettingsApi(string $user, s |
487 | 488 | * @throws Exception |
488 | 489 | */ |
489 | 490 | public function toggleAutoAcceptSharesSetting(string $user, bool $status): ResponseInterface { |
490 | | - $body = json_encode( |
491 | | - [ |
492 | | - "value" => [ |
493 | | - "account_uuid" => "me", |
494 | | - "bundleId" => SettingsHelper::getBundleId(), |
495 | | - "settingId" => SettingsHelper::getSettingIdUsingEventName("Auto Accept Shares"), |
496 | | - "resource" => [ |
497 | | - "type" => "TYPE_USER", |
498 | | - ], |
499 | | - "boolValue" => $status, |
| 491 | + $body = [ |
| 492 | + "value" => [ |
| 493 | + "account_uuid" => "me", |
| 494 | + "bundleId" => SettingsHelper::getBundleId(), |
| 495 | + "settingId" => SettingsHelper::getSettingIdUsingEventName("Auto Accept Shares"), |
| 496 | + "resource" => [ |
| 497 | + "type" => "TYPE_USER", |
500 | 498 | ], |
| 499 | + "boolValue" => $status, |
501 | 500 | ], |
502 | | - JSON_THROW_ON_ERROR, |
503 | | - ); |
| 501 | + ]; |
| 502 | + if ($this->autoAcceptSharesSettingId) { |
| 503 | + // use existing id if available |
| 504 | + $body["value"]["id"] = $this->autoAcceptSharesSettingId; |
| 505 | + } |
| 506 | + $body = json_encode($body, JSON_THROW_ON_ERROR); |
504 | 507 |
|
505 | | - return SettingsHelper::updateSettings( |
| 508 | + $response = SettingsHelper::updateSettings( |
506 | 509 | $this->featureContext->getBaseUrl(), |
507 | 510 | $user, |
508 | 511 | $this->featureContext->getPasswordForUser($user), |
509 | 512 | $body, |
510 | 513 | ); |
| 514 | + if (empty($this->autoAcceptSharesSettingId) && $response->getStatusCode() === 201) { |
| 515 | + // save id for future use |
| 516 | + // updating the setting without id will create a new setting entry |
| 517 | + $data = $this->featureContext->getJsonDecodedResponseBodyContent($response); |
| 518 | + $this->autoAcceptSharesSettingId = $data->value->value->id; |
| 519 | + } |
| 520 | + $response->getBody()->rewind(); |
| 521 | + return $response; |
511 | 522 | } |
512 | 523 |
|
513 | 524 | /** |
|
0 commit comments