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