|
2 | 2 |
|
3 | 3 | use Binafy\LaravelUserMonitoring\Models\ActionMonitoring; |
4 | 4 | use Binafy\LaravelUserMonitoring\Utills\ActionType; |
| 5 | +use Binafy\LaravelUserMonitoring\Utills\UserUtils; |
5 | 6 | use Illuminate\Foundation\Testing\RefreshDatabase; |
| 7 | +use Illuminate\Support\Facades\DB; |
6 | 8 | use Tests\SetUp\Models\Product; |
7 | 9 | use function Pest\Laravel\{assertDatabaseCount, assertDatabaseHas}; |
8 | 10 |
|
|
248 | 250 | assertDatabaseCount(config('user-monitoring.action_monitoring.table'), 3); |
249 | 251 | assertDatabaseHas(config('user-monitoring.action_monitoring.table'), ['page' => url('/')]); |
250 | 252 | }); |
| 253 | + |
| 254 | +test('the getTypeColor method work as expected', function () { |
| 255 | + $defaultData = [ |
| 256 | + 'user_id' => null, |
| 257 | + 'table_name' => 'products', |
| 258 | + 'browser_name' => 'Chrome', |
| 259 | + 'platform' => 'Windows', |
| 260 | + 'device' => 'Macbook M4', |
| 261 | + 'ip' => '192.168.0.1', |
| 262 | + 'user_guard' => 'web', |
| 263 | + 'page' => 'https://github.com/milwad-dev', |
| 264 | + ]; |
| 265 | + $colors = [ |
| 266 | + ActionType::ACTION_READ => 'blue', |
| 267 | + ActionType::ACTION_STORE => 'green', |
| 268 | + ActionType::ACTION_UPDATE => 'purple', |
| 269 | + ActionType::ACTION_DELETE => 'red', |
| 270 | + ActionType::ACTION_RESTORED => 'yellow', |
| 271 | + ActionType::ACTION_REPLICATE => 'pink', |
| 272 | + ]; |
| 273 | + |
| 274 | + foreach (ActionType::$types as $type) { |
| 275 | + $actionMonitoring = ActionMonitoring::query()->create($defaultData + [ |
| 276 | + 'action_type' => $type |
| 277 | + ]); |
| 278 | + |
| 279 | + expect($actionMonitoring->getTypeColor())->toBe($colors[$type]); |
| 280 | + } |
| 281 | +}); |
0 commit comments