Fix tests (see 533b913)

This commit is contained in:
Bubka 2023-04-14 17:54:35 +02:00
parent 9f453582a3
commit 3413d31a3c
3 changed files with 24 additions and 24 deletions

View File

@ -83,7 +83,7 @@ public function test_allPreferences_returns_preferences_with_default_values()
public function test_allPreferences_returns_preferences_with_user_values() public function test_allPreferences_returns_preferences_with_user_values()
{ {
$userPrefs = [ $userPrefs = [
'showTokenAsDot' => true, 'showOtpAsDot' => true,
'closeOtpOnCopy' => true, 'closeOtpOnCopy' => true,
'copyOtpOnDisplay' => true, 'copyOtpOnDisplay' => true,
'useBasicQrcodeReader' => true, 'useBasicQrcodeReader' => true,
@ -103,7 +103,7 @@ public function test_allPreferences_returns_preferences_with_user_values()
'lang' => 'fr', 'lang' => 'fr',
]; ];
$this->user['preferences->showTokenAsDot'] = $userPrefs['showTokenAsDot']; $this->user['preferences->showOtpAsDot'] = $userPrefs['showOtpAsDot'];
$this->user['preferences->closeOtpOnCopy'] = $userPrefs['closeOtpOnCopy']; $this->user['preferences->closeOtpOnCopy'] = $userPrefs['closeOtpOnCopy'];
$this->user['preferences->copyOtpOnDisplay'] = $userPrefs['copyOtpOnDisplay']; $this->user['preferences->copyOtpOnDisplay'] = $userPrefs['copyOtpOnDisplay'];
$this->user['preferences->useBasicQrcodeReader'] = $userPrefs['useBasicQrcodeReader']; $this->user['preferences->useBasicQrcodeReader'] = $userPrefs['useBasicQrcodeReader'];
@ -146,11 +146,11 @@ public function test_showPreference_returns_preference_with_default_value()
$this->user = User::factory()->create(); $this->user = User::factory()->create();
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('GET', '/api/v1/user/preferences/showTokenAsDot') ->json('GET', '/api/v1/user/preferences/showOtpAsDot')
->assertOk() ->assertOk()
->assertExactJson([ ->assertExactJson([
'key' => 'showTokenAsDot', 'key' => 'showOtpAsDot',
'value' => config('2fauth.preferences.showTokenAsDot'), 'value' => config('2fauth.preferences.showOtpAsDot'),
]); ]);
} }
@ -159,15 +159,15 @@ public function test_showPreference_returns_preference_with_default_value()
*/ */
public function test_showPreference_returns_preference_with_custom_value() public function test_showPreference_returns_preference_with_custom_value()
{ {
$showTokenAsDot = ! config('2fauth.preferences.showTokenAsDot'); $showOtpAsDot = ! config('2fauth.preferences.showOtpAsDot');
$this->user['preferences->showTokenAsDot'] = $showTokenAsDot; $this->user['preferences->showOtpAsDot'] = $showOtpAsDot;
$this->user->save(); $this->user->save();
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('GET', '/api/v1/user/preferences/showTokenAsDot') ->json('GET', '/api/v1/user/preferences/showOtpAsDot')
->assertJsonFragment([ ->assertJsonFragment([
'key' => 'showTokenAsDot', 'key' => 'showOtpAsDot',
'value' => $showTokenAsDot, 'value' => $showOtpAsDot,
]); ]);
} }
@ -191,17 +191,17 @@ public function test_setPreference_returns_updated_preference()
*/ */
$this->user = User::factory()->create(); $this->user = User::factory()->create();
$showTokenAsDot = ! config('2fauth.preferences.showTokenAsDot'); $showOtpAsDot = ! config('2fauth.preferences.showOtpAsDot');
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/user/preferences/showTokenAsDot', [ ->json('PUT', '/api/v1/user/preferences/showOtpAsDot', [
'key' => 'showTokenAsDot', 'key' => 'showOtpAsDot',
'value' => $showTokenAsDot, 'value' => $showOtpAsDot,
]) ])
->assertCreated() ->assertCreated()
->assertExactJson([ ->assertExactJson([
'key' => 'showTokenAsDot', 'key' => 'showOtpAsDot',
'value' => $showTokenAsDot, 'value' => $showOtpAsDot,
]); ]);
} }
@ -212,7 +212,7 @@ public function test_setPreference_for_missing_preference_returns_not_found()
{ {
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/user/preferences/unknown', [ ->json('PUT', '/api/v1/user/preferences/unknown', [
'key' => 'showTokenAsDot', 'key' => 'showOtpAsDot',
'value' => true, 'value' => true,
]) ])
->assertNotFound(); ->assertNotFound();
@ -224,8 +224,8 @@ public function test_setPreference_for_missing_preference_returns_not_found()
public function test_setPreference_with_invalid_data_returns_validation_error() public function test_setPreference_with_invalid_data_returns_validation_error()
{ {
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('PUT', '/api/v1/user/preferences/showTokenAsDot', [ ->json('PUT', '/api/v1/user/preferences/showOtpAsDot', [
'key' => 'showTokenAsDot', 'key' => 'showOtpAsDot',
'value' => null, 'value' => null,
]) ])
->assertStatus(422); ->assertStatus(422);

View File

@ -69,7 +69,7 @@ public function test_infos_returns_user_preferences_when_signed_in()
->assertOk() ->assertOk()
->assertJsonStructure([ ->assertJsonStructure([
'user_preferences' => [ 'user_preferences' => [
'showTokenAsDot', 'showOtpAsDot',
'closeOtpOnCopy', 'closeOtpOnCopy',
'copyOtpOnDisplay', 'copyOtpOnDisplay',
'useBasicQrcodeReader', 'useBasicQrcodeReader',

View File

@ -349,10 +349,10 @@ public function test_del_remove_setting_from_db_and_cache()
public function test_isEdited_returns_true() public function test_isEdited_returns_true()
{ {
DB::table('options')->insert( 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'));
} }
/** /**
@ -360,9 +360,9 @@ public function test_isEdited_returns_true()
*/ */
public function test_isEdited_returns_false() 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'));
} }
/** /**