mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-18 19:06:45 +02:00
Add settings unit tests
This commit is contained in:
parent
64376b137e
commit
b2c620b5d3
77
tests/Unit/SettingTest.php
Normal file
77
tests/Unit/SettingTest.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SettingTest extends TestCase
|
||||
{
|
||||
/** @var \App\User */
|
||||
protected $user;
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = factory(User::class)->create();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test Settings storage via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testSettingsStorage()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('POST', '/api/settings', [
|
||||
'setting_1' => 'value_1',
|
||||
'setting_2' => 'value_2',
|
||||
])
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
'message' => __('settings.forms.setting_saved'),
|
||||
'settings' => [
|
||||
'setting_1' => 'value_1',
|
||||
'setting_2' => 'value_2',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test Settings list fetching via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testSettingsIndexListing()
|
||||
{
|
||||
option(['setting_1' => 'value_1']);
|
||||
option(['setting_2' => 'value_2']);
|
||||
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('GET', '/api/settings')
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
'settings' => [
|
||||
[
|
||||
'id' => '1',
|
||||
'key' => 'setting_1',
|
||||
'value' => 'value_1'
|
||||
],
|
||||
[
|
||||
'id' => '2',
|
||||
'key' => 'setting_2',
|
||||
'value' => 'value_2'
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user