feature test su institution
This commit is contained in:
34
backend/database/factories/InstitutionFactory.php
Normal file
34
backend/database/factories/InstitutionFactory.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Institution;
|
||||
use App\Models\Lists\InstitutionCategory;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Institution>
|
||||
*/
|
||||
class InstitutionFactory extends Factory
|
||||
{
|
||||
protected $model = Institution::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'category_id' => InstitutionCategory::factory(),
|
||||
'name' => fake()->unique()->company(),
|
||||
'abbreviation' => strtoupper(fake()->unique()->lexify('?????')),
|
||||
'address' => fake()->streetAddress(),
|
||||
'city' => fake()->city(),
|
||||
'lat' => fake()->latitude(),
|
||||
'lon' => fake()->longitude(),
|
||||
'logo' => 'default.jpg',
|
||||
'color' => '#c5cae9',
|
||||
'is_storage_place' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
30
backend/database/factories/InstitutionLinkFactory.php
Normal file
30
backend/database/factories/InstitutionLinkFactory.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\InstitutionLinkType;
|
||||
use App\Models\Institution;
|
||||
use App\Models\InstitutionLink;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<InstitutionLink>
|
||||
*/
|
||||
class InstitutionLinkFactory extends Factory
|
||||
{
|
||||
protected $model = InstitutionLink::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'institution_id' => Institution::factory(),
|
||||
'url' => fake()->url(),
|
||||
'type' => InstitutionLinkType::Official,
|
||||
'label' => null,
|
||||
'sort_order' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Lists;
|
||||
|
||||
use App\Models\Lists\InstitutionCategory;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<InstitutionCategory>
|
||||
*/
|
||||
class InstitutionCategoryFactory extends Factory
|
||||
{
|
||||
protected $model = InstitutionCategory::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'value' => fake()->unique()->word(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('institution_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('value', 25)->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('institution_categories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('institutions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('category_id')
|
||||
->constrained('institution_categories')
|
||||
->cascadeOnUpdate()
|
||||
->restrictOnDelete();
|
||||
$table->string('name')->unique();
|
||||
$table->string('abbreviation', 5)->unique();
|
||||
$table->string('address');
|
||||
$table->string('city', 100)->index();
|
||||
$table->decimal('lat', 10, 6);
|
||||
$table->decimal('lon', 10, 6);
|
||||
$table->string('logo');
|
||||
$table->string('color', 50)->default('#c5cae9');
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->boolean('is_storage_place')->default(true);
|
||||
// Id del record nel DB legacy (v1): chiave di upsert per l'ETL e per
|
||||
// risolvere le FK delle tabelle dipendenti (es. artifact.owner).
|
||||
$table->unsignedBigInteger('legacy_id')->nullable()->unique();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('institutions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('institution_links', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('institution_id')
|
||||
->constrained()
|
||||
->cascadeOnDelete();
|
||||
$table->string('url', 2000);
|
||||
// Vincolato a App\Enums\InstitutionLinkType (cast + validazione lato app).
|
||||
$table->string('type', 30);
|
||||
$table->string('label', 100)->nullable();
|
||||
$table->unsignedSmallInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['institution_id', 'sort_order']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('institution_links');
|
||||
}
|
||||
};
|
||||
@@ -18,6 +18,7 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call([
|
||||
UserRoleSeeder::class,
|
||||
SystemUserSeeder::class,
|
||||
InstitutionCategorySeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
33
backend/database/seeders/InstitutionCategorySeeder.php
Normal file
33
backend/database/seeders/InstitutionCategorySeeder.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Lists\InstitutionCategory;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class InstitutionCategorySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Categorie di istituzione. Idempotente.
|
||||
*
|
||||
* Gli id sono FISSI e coincidono con il DB legacy (v1) così l'ETL mappa
|
||||
* institutions.category_id 1:1 senza tradurre. La categoria 1 ("uncategorized",
|
||||
* mai usata) e la 5 (inesistente nel legacy) sono volutamente assenti.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$categories = [
|
||||
2 => InstitutionCategory::LIBRARY,
|
||||
3 => InstitutionCategory::MUSEUM,
|
||||
4 => InstitutionCategory::PUBLIC_ADMINISTRATION,
|
||||
6 => InstitutionCategory::RESEARCH_INSTITUTE,
|
||||
];
|
||||
|
||||
foreach ($categories as $id => $value) {
|
||||
InstitutionCategory::updateOrCreate(
|
||||
['id' => $id],
|
||||
['value' => $value],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user