101 lines
No EOL
2.9 KiB
PHP
101 lines
No EOL
2.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Http\Controllers\Api\V1;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class SettingsControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_index_returns_current_settings(): void
|
|
{
|
|
$response = $this->getJson('/api/v1/settings');
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonStructure([
|
|
'success',
|
|
'data' => [
|
|
'article_processing_enabled',
|
|
'publishing_approvals_enabled',
|
|
],
|
|
'message'
|
|
])
|
|
->assertJson([
|
|
'success' => true,
|
|
'message' => 'Settings retrieved successfully.'
|
|
]);
|
|
}
|
|
|
|
public function test_update_modifies_article_processing_setting(): void
|
|
{
|
|
$response = $this->putJson('/api/v1/settings', [
|
|
'article_processing_enabled' => false,
|
|
]);
|
|
|
|
$response->assertStatus(200)
|
|
->assertJson([
|
|
'success' => true,
|
|
'message' => 'Settings updated successfully.',
|
|
'data' => [
|
|
'article_processing_enabled' => false,
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function test_update_modifies_publishing_approvals_setting(): void
|
|
{
|
|
$response = $this->putJson('/api/v1/settings', [
|
|
'enable_publishing_approvals' => true,
|
|
]);
|
|
|
|
$response->assertStatus(200)
|
|
->assertJson([
|
|
'success' => true,
|
|
'message' => 'Settings updated successfully.',
|
|
'data' => [
|
|
'publishing_approvals_enabled' => true,
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function test_update_validates_boolean_values(): void
|
|
{
|
|
$response = $this->putJson('/api/v1/settings', [
|
|
'article_processing_enabled' => 'not-a-boolean',
|
|
'enable_publishing_approvals' => 'also-not-boolean',
|
|
]);
|
|
|
|
$response->assertStatus(422)
|
|
->assertJsonValidationErrors([
|
|
'article_processing_enabled',
|
|
'enable_publishing_approvals'
|
|
]);
|
|
}
|
|
|
|
public function test_update_accepts_partial_updates(): void
|
|
{
|
|
// Update only one setting
|
|
$response = $this->putJson('/api/v1/settings', [
|
|
'article_processing_enabled' => true,
|
|
]);
|
|
|
|
$response->assertStatus(200)
|
|
->assertJson([
|
|
'success' => true,
|
|
'data' => [
|
|
'article_processing_enabled' => true,
|
|
]
|
|
]);
|
|
|
|
// Should still have structure for both settings
|
|
$response->assertJsonStructure([
|
|
'data' => [
|
|
'article_processing_enabled',
|
|
'publishing_approvals_enabled',
|
|
]
|
|
]);
|
|
}
|
|
} |