Skip to content

Commit 96d78a4

Browse files
committed
test: use created id while updating the setting
Signed-off-by: Saw-jan <saw.jan.grg3e@gmail.com>
1 parent 817bd01 commit 96d78a4

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

tests/acceptance/bootstrap/SettingsContext.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
class SettingsContext implements Context {
2828
private FeatureContext $featureContext;
2929
private string $settingsUrl = '/api/v0/settings/';
30+
private string $autoAcceptSharesSettingId = '';
3031

3132
/**
3233
* This will run before EVERY scenario.
@@ -487,27 +488,37 @@ public function userSwitchesTheSystemLanguageUsingTheSettingsApi(string $user, s
487488
* @throws Exception
488489
*/
489490
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",
500498
],
499+
"boolValue" => $status,
501500
],
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);
504507

505-
return SettingsHelper::updateSettings(
508+
$response = SettingsHelper::updateSettings(
506509
$this->featureContext->getBaseUrl(),
507510
$user,
508511
$this->featureContext->getPasswordForUser($user),
509512
$body,
510513
);
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;
511522
}
512523

513524
/**

tests/acceptance/features/apiSettings/settings.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Feature: settings api
6868

6969
@issue-11335
7070
Scenario: enable auto-sync-shares after disabling it
71+
Given user "Alice" has uploaded file with content "lorem epsum" to "textfile.txt"
7172
And user "Brian" has disabled the auto-sync share
7273
When user "Brian" enables the auto-sync share using the settings API
7374
Then the HTTP status code should be "201"

0 commit comments

Comments
 (0)