Skip to content

Commit

Permalink
fix: test disable setting
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Dec 15, 2023
1 parent 91dc52e commit 0d50e58
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Listeners/SaveUserPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function handle(Saving $event)
if ($blocksPd !== null) {
$actor->assertPermission($actor->id === $user->id);

$user->blocks_byobu_pd = (bool) ($blocksPd || $user->blocks_byobu_pd);
$user->blocks_byobu_pd = (bool) $blocksPd;
}
}
}
30 changes: 30 additions & 0 deletions tests/integration/api/UserPrivacyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function setUp(): void
$this->prepareDatabase([
'users' => [
$this->normalUser(),
['id' => 3, 'username' => 'normal2', 'email' => '[email protected]', 'password' => 'too-obscure', 'blocks_byobu_pd' => true]
],
]);
}
Expand Down Expand Up @@ -59,4 +60,33 @@ public function user_can_set_block_pd_setting()

$this->assertTrue($json['data']['attributes']['blocksPd']);
}

/**
* @test
*/
public function user_can_disable_block_pd_setting()
{
$response = $this->send(
$this->request(
'PATCH',
'/api/users/3',
[
'authenticatedAs' => 3,
'json' => [
'data' => [
'attributes' => [
'blocksPd' => false,
],
],
],
]
)
);

$this->assertEquals(200, $response->getStatusCode());

$json = json_decode($response->getBody()->getContents(), true);

$this->assertFalse($json['data']['attributes']['blocksPd']);
}
}

0 comments on commit 0d50e58

Please sign in to comment.