refactor(ticket): simplify tenant validation and update command documentation
This commit is contained in:
@@ -122,10 +122,6 @@ class LoadTestTicketDatasetService
|
|||||||
int $scannerCount,
|
int $scannerCount,
|
||||||
int $ownerCount,
|
int $ownerCount,
|
||||||
): void {
|
): void {
|
||||||
if (! str_starts_with($tenantCode, 'loadtest-')) {
|
|
||||||
throw new InvalidArgumentException('El tenant debe comenzar con `loadtest-`.');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ([
|
foreach ([
|
||||||
'tickets' => [$ticketCount, 100_000],
|
'tickets' => [$ticketCount, 100_000],
|
||||||
'scanners' => [$scannerCount, 10_000],
|
'scanners' => [$scannerCount, 10_000],
|
||||||
@@ -189,7 +185,7 @@ class LoadTestTicketDatasetService
|
|||||||
private function scanners(Tenant $tenant, CatalogItem $catalogItem, int $count): Collection
|
private function scanners(Tenant $tenant, CatalogItem $catalogItem, int $count): Collection
|
||||||
{
|
{
|
||||||
return Collection::times($count, function (int $number) use ($tenant, $catalogItem): User {
|
return Collection::times($count, function (int $number) use ($tenant, $catalogItem): User {
|
||||||
$scanner = User::withTrashed()->updateOrCreate(
|
$scanner = User::query()->updateOrCreate(
|
||||||
['email' => $this->email($tenant, 'scanner', $number)],
|
['email' => $this->email($tenant, 'scanner', $number)],
|
||||||
[
|
[
|
||||||
'nombre_apellido' => "Load test scanner {$number}",
|
'nombre_apellido' => "Load test scanner {$number}",
|
||||||
@@ -198,8 +194,6 @@ class LoadTestTicketDatasetService
|
|||||||
'tenant_codigo' => $tenant->codigo,
|
'tenant_codigo' => $tenant->codigo,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
$scanner->restore();
|
|
||||||
|
|
||||||
if ($tenant->requiresScannerCategoryValidation()) {
|
if ($tenant->requiresScannerCategoryValidation()) {
|
||||||
$scanner->scanCategories()->syncWithoutDetaching([$catalogItem->category_id]);
|
$scanner->scanCategories()->syncWithoutDetaching([$catalogItem->category_id]);
|
||||||
}
|
}
|
||||||
@@ -212,7 +206,7 @@ class LoadTestTicketDatasetService
|
|||||||
private function owners(Tenant $tenant, int $count): Collection
|
private function owners(Tenant $tenant, int $count): Collection
|
||||||
{
|
{
|
||||||
return Collection::times($count, function (int $number) use ($tenant): User {
|
return Collection::times($count, function (int $number) use ($tenant): User {
|
||||||
$owner = User::withTrashed()->updateOrCreate(
|
$owner = User::query()->updateOrCreate(
|
||||||
['email' => $this->email($tenant, 'owner', $number)],
|
['email' => $this->email($tenant, 'owner', $number)],
|
||||||
[
|
[
|
||||||
'nombre_apellido' => "Load test owner {$number}",
|
'nombre_apellido' => "Load test owner {$number}",
|
||||||
@@ -221,7 +215,6 @@ class LoadTestTicketDatasetService
|
|||||||
'tenant_codigo' => $tenant->codigo,
|
'tenant_codigo' => $tenant->codigo,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
$owner->restore();
|
|
||||||
|
|
||||||
return $owner;
|
return $owner;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ php artisan load-test:tickets:prepare loadtest-evento \
|
|||||||
--run=evento-001
|
--run=evento-001
|
||||||
```
|
```
|
||||||
|
|
||||||
El tenant debe existir, ser exclusivo para carga y comenzar con `loadtest-`. Si no se indica
|
El tenant debe existir y se recomienda que sea exclusivo para carga. Si no se indica `--catalog-item`,
|
||||||
`--catalog-item`, se usa el primer producto estándar del tenant con tickets habilitados. `--variant`
|
se usa el primer producto estándar del tenant con tickets habilitados. `--variant`
|
||||||
es opcional; al indicarlo, su configuración de vigencia debe estar activa y ser resoluble. Sin variante,
|
es opcional; al indicarlo, su configuración de vigencia debe estar activa y ser resoluble. Sin variante,
|
||||||
los tickets tienen vigencia irrestricta.
|
los tickets tienen vigencia irrestricta.
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ Schedule::command('reservations:expire')
|
|||||||
|
|
||||||
Artisan::command(
|
Artisan::command(
|
||||||
'load-test:tickets:prepare
|
'load-test:tickets:prepare
|
||||||
{tenant : Código de un tenant dedicado con prefijo loadtest-}
|
{tenant : Código del tenant que recibirá los datos de carga}
|
||||||
{--tickets=1000 : Cantidad de tickets válidos}
|
{--tickets=1000 : Cantidad de tickets válidos}
|
||||||
{--scanners=10 : Cantidad de identidades scanner}
|
{--scanners=10 : Cantidad de identidades scanner}
|
||||||
{--owners=100 : Cantidad de propietarios de tickets}
|
{--owners=100 : Cantidad de propietarios de tickets}
|
||||||
|
|||||||
@@ -8,32 +8,23 @@ use App\Domains\Catalog\Models\Category;
|
|||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use App\Domains\Tenant\Models\WebsiteType;
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
use App\Domains\Ticket\Services\LoadTestTicketDatasetService;
|
|
||||||
use Database\Seeders\AuthorizationSeeder;
|
use Database\Seeders\AuthorizationSeeder;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use InvalidArgumentException;
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class PrepareLoadTestTicketsCommandTest extends TestCase
|
class PrepareLoadTestTicketsCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
public function test_it_rejects_a_tenant_that_is_not_dedicated_to_load_testing(): void
|
|
||||||
{
|
|
||||||
$this->expectException(InvalidArgumentException::class);
|
|
||||||
$this->expectExceptionMessage('loadtest-');
|
|
||||||
|
|
||||||
app(LoadTestTicketDatasetService::class)->prepare('production', 1, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_generates_a_postman_dataset_that_can_scan_the_tickets(): void
|
public function test_it_generates_a_postman_dataset_that_can_scan_the_tickets(): void
|
||||||
{
|
{
|
||||||
Storage::fake('local');
|
Storage::fake('local');
|
||||||
$this->seed(AuthorizationSeeder::class);
|
$this->seed(AuthorizationSeeder::class);
|
||||||
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||||
$tenant = $this->createTenant('loadtest-acme');
|
$tenant = $this->createTenant('acme');
|
||||||
$category = Category::query()->create([
|
$category = Category::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'nombre' => 'Entradas de carga',
|
'nombre' => 'Entradas de carga',
|
||||||
@@ -48,7 +39,7 @@ class PrepareLoadTestTicketsCommandTest extends TestCase
|
|||||||
'has_tickets' => true,
|
'has_tickets' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->artisan('load-test:tickets:prepare', [
|
$exitCode = Artisan::call('load-test:tickets:prepare', [
|
||||||
'tenant' => $tenant->codigo,
|
'tenant' => $tenant->codigo,
|
||||||
'--tickets' => 4,
|
'--tickets' => 4,
|
||||||
'--scanners' => 2,
|
'--scanners' => 2,
|
||||||
@@ -56,7 +47,9 @@ class PrepareLoadTestTicketsCommandTest extends TestCase
|
|||||||
'--catalog-item' => $catalogItem->id,
|
'--catalog-item' => $catalogItem->id,
|
||||||
'--run' => 'test-run',
|
'--run' => 'test-run',
|
||||||
'--output' => 'load-tests/test-run.postman.json',
|
'--output' => 'load-tests/test-run.postman.json',
|
||||||
])->assertSuccessful();
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $exitCode, Artisan::output());
|
||||||
|
|
||||||
Storage::disk('local')->assertExists('load-tests/test-run.postman.json');
|
Storage::disk('local')->assertExists('load-tests/test-run.postman.json');
|
||||||
$rows = json_decode(
|
$rows = json_decode(
|
||||||
|
|||||||
Reference in New Issue
Block a user