Преглед изворни кода

feat(tests): add test scripts for user type and permissions retrieval

alvesantos пре 1 недеља
родитељ
комит
119eb45ede
2 измењених фајлова са 47 додато и 0 уклоњено
  1. 29 0
      test_db.php
  2. 18 0
      test_permissions.php

+ 29 - 0
test_db.php

@@ -0,0 +1,29 @@
+<?php
+require __DIR__.'/vendor/autoload.php';
+$app = require_once __DIR__.'/bootstrap/app.php';
+$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
+$kernel->bootstrap();
+
+try {
+    $count = App\Models\UserType::count();
+    echo "DB is UP! \n";
+    
+    // Find Andreia
+    $andreia = App\Models\User::find(11);
+    if ($andreia) {
+        $unitId = $andreia->units()->value('units.id');
+        echo "Andreia Unit ID: " . $unitId . "\n";
+        
+        $roles = App\Models\UserType::where('unit_id', $unitId)->get();
+        echo "\nPerfis da unidade da Andreia:\n";
+        foreach($roles as $role) {
+            $permCount = App\Models\UserTypePermission::where('user_type_id', $role->id)->count();
+            echo "- {$role->label} (slug: {$role->slug}, is_system: {$role->is_system}) | Permissões: {$permCount}\n";
+        }
+    } else {
+        echo "Andreia nao encontrada.\n";
+    }
+
+} catch (\Exception $e) {
+    echo "DB_IS_DOWN: " . $e->getMessage() . "\n";
+}

+ 18 - 0
test_permissions.php

@@ -0,0 +1,18 @@
+<?php
+require __DIR__.'/vendor/autoload.php';
+$app = require_once __DIR__.'/bootstrap/app.php';
+$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
+$kernel->bootstrap();
+
+$u = App\Models\User::find(11);
+$unitId = $u->units()->value('units.id');
+$unitUser = App\Models\UnitUser::where('user_id', 11)->where('unit_id', $unitId)->first();
+$userType = App\Models\UserType::find($unitUser->user_type_id);
+
+echo "Andreia Unit: {$unitId}\n";
+echo "Andreia UserType ID: {$userType->id}\n";
+echo "Andreia UserType Label: {$userType->label}\n";
+echo "Andreia UserType System Key: {$userType->system_key}\n";
+
+$permissions = App\Models\UserTypePermission::where('user_type_id', $userType->id)->get();
+echo "Permissions count: " . $permissions->count() . "\n";