- Prevents local DB data loss when running 'php artisan test' - ViconApiConfigTest uses updateOrCreate to avoid unique constraint - Delete + Cache::flush for 'not configured' test case
61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Containers\VikonIntegration\Tests\Feature;
|
|
|
|
use App\Containers\User\Models\User;
|
|
use App\Ship\Tests\TestCase;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
class UpdatePartTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
private function createUser(): User
|
|
{
|
|
return User::withoutEvents(fn () => User::create([
|
|
'name' => 'Test User',
|
|
'slug' => 'test-user',
|
|
'email' => 'test-user-' . uniqid() . '@example.com',
|
|
'password' => bcrypt('password'),
|
|
]));
|
|
}
|
|
|
|
public function test_update_part_requires_authentication(): void
|
|
{
|
|
$response = $this->postJson('/dashboard/vikon-updates/update-part', [
|
|
'module_id' => 1,
|
|
'part' => 'common',
|
|
]);
|
|
|
|
$response->assertStatus(401);
|
|
}
|
|
|
|
public function test_update_part_validates_module_id(): void
|
|
{
|
|
$user = $this->createUser();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->postJson('/dashboard/vikon-updates/update-part', [
|
|
'module_id' => 999,
|
|
'part' => 'common',
|
|
]);
|
|
|
|
$response->assertStatus(422);
|
|
$response->assertJsonValidationErrors('module_id');
|
|
}
|
|
|
|
public function test_update_part_validates_part(): void
|
|
{
|
|
$user = $this->createUser();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->postJson('/dashboard/vikon-updates/update-part', [
|
|
'module_id' => 1,
|
|
'part' => '',
|
|
]);
|
|
|
|
$response->assertStatus(422);
|
|
$response->assertJsonValidationErrors('part');
|
|
}
|
|
}
|