Skip to content

Commit

Permalink
Fix tests (see 533b913)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubka committed Apr 14, 2023
1 parent 9f45358 commit 3413d31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
38 changes: 19 additions & 19 deletions tests/Api/v1/Controllers/Auth/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function test_allPreferences_returns_preferences_with_default_values()
public function test_allPreferences_returns_preferences_with_user_values()
{
$userPrefs = [
'showTokenAsDot' => true,
'showOtpAsDot' => true,
'closeOtpOnCopy' => true,
'copyOtpOnDisplay' => true,
'useBasicQrcodeReader' => true,
Expand All @@ -103,7 +103,7 @@ public function test_allPreferences_returns_preferences_with_user_values()
'lang' => 'fr',
];

$this->user['preferences->showTokenAsDot'] = $userPrefs['showTokenAsDot'];
$this->user['preferences->showOtpAsDot'] = $userPrefs['showOtpAsDot'];
$this->user['preferences->closeOtpOnCopy'] = $userPrefs['closeOtpOnCopy'];
$this->user['preferences->copyOtpOnDisplay'] = $userPrefs['copyOtpOnDisplay'];
$this->user['preferences->useBasicQrcodeReader'] = $userPrefs['useBasicQrcodeReader'];
Expand Down Expand Up @@ -146,11 +146,11 @@ public function test_showPreference_returns_preference_with_default_value()
$this->user = User::factory()->create();

$response = $this->actingAs($this->user, 'api-guard')
->json('GET', '/api/v1/user/preferences/showTokenAsDot')
->json('GET', '/api/v1/user/preferences/showOtpAsDot')
->assertOk()
->assertExactJson([
'key' => 'showTokenAsDot',
'value' => config('2fauth.preferences.showTokenAsDot'),
'key' => 'showOtpAsDot',
'value' => config('2fauth.preferences.showOtpAsDot'),
]);
}

Expand All @@ -159,15 +159,15 @@ public function test_showPreference_returns_preference_with_default_value()
*/
public function test_showPreference_returns_preference_with_custom_value()
{
$showTokenAsDot = ! config('2fauth.preferences.showTokenAsDot');
$this->user['preferences->showTokenAsDot'] = $showTokenAsDot;
$showOtpAsDot = ! config('2fauth.preferences.showOtpAsDot');
$this->user['preferences->showOtpAsDot'] = $showOtpAsDot;
$this->user->save();

$response = $this->actingAs($this->user, 'api-guard')
->json('GET', '/api/v1/user/preferences/showTokenAsDot')
->json('GET', '/api/v1/user/preferences/showOtpAsDot')
->assertJsonFragment([
'key' => 'showTokenAsDot',
'value' => $showTokenAsDot,
'key' => 'showOtpAsDot',
'value' => $showOtpAsDot,
]);
}

Expand All @@ -191,17 +191,17 @@ public function test_setPreference_returns_updated_preference()
*/
$this->user = User::factory()->create();

$showTokenAsDot = ! config('2fauth.preferences.showTokenAsDot');
$showOtpAsDot = ! config('2fauth.preferences.showOtpAsDot');

$response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/user/preferences/showTokenAsDot', [
'key' => 'showTokenAsDot',
'value' => $showTokenAsDot,
->json('PUT', '/api/v1/user/preferences/showOtpAsDot', [
'key' => 'showOtpAsDot',
'value' => $showOtpAsDot,
])
->assertCreated()
->assertExactJson([
'key' => 'showTokenAsDot',
'value' => $showTokenAsDot,
'key' => 'showOtpAsDot',
'value' => $showOtpAsDot,
]);
}

Expand All @@ -212,7 +212,7 @@ public function test_setPreference_for_missing_preference_returns_not_found()
{
$response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/user/preferences/unknown', [
'key' => 'showTokenAsDot',
'key' => 'showOtpAsDot',
'value' => true,
])
->assertNotFound();
Expand All @@ -224,8 +224,8 @@ public function test_setPreference_for_missing_preference_returns_not_found()
public function test_setPreference_with_invalid_data_returns_validation_error()
{
$response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/user/preferences/showTokenAsDot', [
'key' => 'showTokenAsDot',
->json('PUT', '/api/v1/user/preferences/showOtpAsDot', [
'key' => 'showOtpAsDot',
'value' => null,
])
->assertStatus(422);
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Http/SystemControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function test_infos_returns_user_preferences_when_signed_in()
->assertOk()
->assertJsonStructure([
'user_preferences' => [
'showTokenAsDot',
'showOtpAsDot',
'closeOtpOnCopy',
'copyOtpOnDisplay',
'useBasicQrcodeReader',
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Services/SettingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,20 @@ public function test_del_remove_setting_from_db_and_cache()
public function test_isEdited_returns_true()
{
DB::table('options')->insert(
[self::KEY => 'showTokenAsDot', self::VALUE => strval(self::SETTING_VALUE_TRUE_TRANSFORMED)]
[self::KEY => 'showOtpAsDot', self::VALUE => strval(self::SETTING_VALUE_TRUE_TRANSFORMED)]
);

$this->assertTrue(Settings::isEdited('showTokenAsDot'));
$this->assertTrue(Settings::isEdited('showOtpAsDot'));
}

/**
* @test
*/
public function test_isEdited_returns_false()
{
DB::table('options')->where(self::KEY, 'showTokenAsDot')->delete();
DB::table('options')->where(self::KEY, 'showOtpAsDot')->delete();

$this->assertFalse(Settings::isEdited('showTokenAsDot'));
$this->assertFalse(Settings::isEdited('showOtpAsDot'));
}

/**
Expand Down

0 comments on commit 3413d31

Please sign in to comment.