Add tests for ticket validity and event date formatting
- Create TicketValiditySchemaTest to verify database schema for ticket validity. - Update CatalogModelsTest to include tests for event date attributes and selection options. - Introduce EventDateTextFormatterTest for formatting event dates in Spanish. - Refactor EventModelsTest to include validity time relationships. - Add SaleDetailResourceTest to ensure correct serialization of purchase items. - Enhance TicketTest with validity time checks and status management. - Implement ValidityTimeResourceTest to validate resource output for different validity types. - Add ValidityTimeTest to verify casting and validity checks for validity time types.
This commit is contained in:
34
app/Domains/Ticket/Resources/ValidityTimeResource.php
Normal file
34
app/Domains/Ticket/Resources/ValidityTimeResource.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Ticket\Resources;
|
||||
|
||||
use App\Domains\Ticket\Enums\ValidityTimeType;
|
||||
use App\Domains\Ticket\Models\ValidityTime;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin ValidityTime */
|
||||
class ValidityTimeResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$fields = match ($this->type) {
|
||||
ValidityTimeType::TimeWindow => [
|
||||
'start_time' => $this->start_time,
|
||||
'end_time' => $this->end_time,
|
||||
],
|
||||
ValidityTimeType::FixedWindow => [
|
||||
'fixed_starts_at' => $this->fixed_starts_at,
|
||||
'fixed_expires_at' => $this->fixed_expires_at,
|
||||
],
|
||||
};
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type->value,
|
||||
'is_valid' => $this->isValid(),
|
||||
...array_filter($fields, fn (mixed $value): bool => $value !== null),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user