feat(ticket): implement LoadTestTicketDatasetService for generating load test datasets
- Added LoadTestTicketDatasetService to prepare disposable scanner tickets and generate a Postman importable dataset.
- Introduced console command `load-test🎟️prepare` for executing the dataset preparation.
- Updated README documentation with usage instructions for the load test command.
- Enhanced Postman collection generation script to include new parameters.
- Created tests for the load test command to ensure proper functionality and validation.
This commit is contained in:
114
tests/Feature/Ticket/PrepareLoadTestTicketsCommandTest.php
Normal file
114
tests/Feature/Ticket/PrepareLoadTestTicketsCommandTest.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Ticket;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
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\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');
|
||||
$category = Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Entradas de carga',
|
||||
]);
|
||||
$catalogItem = CatalogItem::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'category_id' => $category->id,
|
||||
'slug' => 'entrada-load-test',
|
||||
'nombre' => 'Entrada load test',
|
||||
'descripcion' => 'Ticket descartable',
|
||||
'precio' => 100,
|
||||
'has_tickets' => true,
|
||||
]);
|
||||
|
||||
$this->artisan('load-test:tickets:prepare', [
|
||||
'tenant' => $tenant->codigo,
|
||||
'--tickets' => 4,
|
||||
'--scanners' => 2,
|
||||
'--owners' => 2,
|
||||
'--catalog-item' => $catalogItem->id,
|
||||
'--run' => 'test-run',
|
||||
'--output' => 'load-tests/test-run.postman.json',
|
||||
])->assertSuccessful();
|
||||
|
||||
Storage::disk('local')->assertExists('load-tests/test-run.postman.json');
|
||||
$rows = json_decode(
|
||||
Storage::disk('local')->get('load-tests/test-run.postman.json'),
|
||||
true,
|
||||
flags: JSON_THROW_ON_ERROR,
|
||||
);
|
||||
|
||||
$this->assertCount(4, $rows);
|
||||
$this->assertCount(4, collect($rows)->pluck('ticket_uuid')->unique());
|
||||
$this->assertCount(2, collect($rows)->pluck('scanner_token')->unique());
|
||||
$this->assertSame([200], collect($rows)->pluck('expected_status')->unique()->values()->all());
|
||||
$this->assertDatabaseCount('tickets', 4);
|
||||
$this->assertCount(2, Ticket::query()->distinct()->pluck('user_id'));
|
||||
$this->assertDatabaseCount('category_scanners', 2);
|
||||
|
||||
$first = $rows[0];
|
||||
$this->withToken($first['scanner_token'])
|
||||
->postJson("/api/v1/scanner/tickets/{$first['ticket_uuid']}/scan")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.ticket', $first['ticket_uuid']);
|
||||
|
||||
$this->assertNotNull(
|
||||
Ticket::query()->where('ticket', $first['ticket_uuid'])->firstOrFail()->used_at
|
||||
);
|
||||
}
|
||||
|
||||
private function createTenant(string $code): Tenant
|
||||
{
|
||||
$logo = Attachment::query()->create([
|
||||
'key' => (string) Str::uuid(),
|
||||
'path' => "tests/{$code}-logo.png",
|
||||
'filename' => "{$code}-logo.png",
|
||||
'type' => 'image',
|
||||
'mime_type' => 'image/png',
|
||||
'extension' => 'png',
|
||||
'size' => 1,
|
||||
]);
|
||||
|
||||
return Tenant::query()->create([
|
||||
'codigo' => $code,
|
||||
'nombre' => ucfirst($code),
|
||||
'dominio' => "{$code}.test",
|
||||
'primary_color' => '#ff7006',
|
||||
'secondary_color' => '#777777',
|
||||
'danger_color' => '#e04a4a',
|
||||
'success_color' => '#81bc73',
|
||||
'header_bg_color' => '#313131',
|
||||
'footer_bg_color' => '#313131',
|
||||
'header_logo_id' => $logo->id,
|
||||
'footer_logo_id' => $logo->id,
|
||||
'website_type_code' => 'onticket',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user