feat: 實作機台日誌核心功能與 IoT 高併發處理架構
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 36s

This commit is contained in:
2026-03-09 09:43:51 +08:00
parent 21e064ff91
commit c30c3a399d
53 changed files with 2300 additions and 2130 deletions

View File

@@ -0,0 +1,68 @@
<?php
namespace Tests\Feature\Api\V1;
use App\Jobs\Machine\ProcessMachineLog;
use App\Models\Machine\Machine;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class MachineLogTest extends TestCase
{
use RefreshDatabase;
/**
* 測試機台日誌 API 是否能正確接收並派發 Job
*/
public function test_machine_can_send_log_and_dispatch_job(): void
{
Queue::fake();
$machine = Machine::factory()->create();
$response = $this->postJson("/api/v1/machines/{$machine->id}/logs", [
'level' => 'info',
'message' => 'Test log message',
'context' => ['foo' => 'bar'],
]);
$response->assertStatus(202)
->assertJson([
'success' => true,
'message' => 'Log accepted. Processing asynchronously.',
]);
Queue::assertPushed(ProcessMachineLog::class, function ($job) use ($machine) {
return $job->getMachineId() === $machine->id;
});
}
/**
* 測試不存在的機台應回傳 404
*/
public function test_send_log_to_non_existent_machine_returns_404(): void
{
$response = $this->postJson("/api/v1/machines/999/logs", [
'level' => 'info',
'message' => 'Should fail',
]);
$response->assertStatus(404);
}
/**
* 測試屬性驗證失敗
*/
public function test_send_invalid_log_data_returns_422(): void
{
$machine = Machine::factory()->create();
$response = $this->postJson("/api/v1/machines/{$machine->id}/logs", [
'level' => 'invalid-level', // 不符合 in:info,warning,error
'message' => '', // 必填
]);
$response->assertStatus(422);
}
}

View File

@@ -2,7 +2,7 @@
namespace Tests\Feature\Auth;
use App\Models\User;
use App\Models\System\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

View File

@@ -2,7 +2,7 @@
namespace Tests\Feature\Auth;
use App\Models\User;
use App\Models\System\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;

View File

@@ -2,7 +2,7 @@
namespace Tests\Feature\Auth;
use App\Models\User;
use App\Models\System\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

View File

@@ -2,7 +2,7 @@
namespace Tests\Feature\Auth;
use App\Models\User;
use App\Models\System\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;

View File

@@ -2,7 +2,7 @@
namespace Tests\Feature\Auth;
use App\Models\User;
use App\Models\System\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;

View File

@@ -2,7 +2,7 @@
namespace Tests\Feature;
use App\Models\User;
use App\Models\System\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;