101 lines
3.6 KiB
PHP
101 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Tenant;
|
|
|
|
use App\Domains\Attachable\Enums\AttachmentType;
|
|
use App\Domains\Attachable\Models\Attachment;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
class TenantRefundConfigurationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_refund_configuration_has_database_defaults_and_is_exposed_by_the_api(): void
|
|
{
|
|
$tenant = $this->createTenant('refund-defaults');
|
|
|
|
$this->assertFalse($tenant->allow_ticket_total_refund);
|
|
$this->assertFalse($tenant->allow_ticket_partial_refund);
|
|
$this->assertSame('0.00', $tenant->ticket_partial_refund_percentage);
|
|
|
|
$this->getJson("/api/tenants/{$tenant->codigo}")
|
|
->assertOk()
|
|
->assertJsonPath('data.allow_ticket_total_refund', false)
|
|
->assertJsonPath('data.allow_ticket_partial_refund', false)
|
|
->assertJsonPath('data.ticket_partial_refund_percentage', '0.00');
|
|
}
|
|
|
|
public function test_refund_configuration_can_be_updated_and_validates_its_precision(): void
|
|
{
|
|
$tenant = $this->createTenant('refund-update');
|
|
|
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
|
'allow_ticket_total_refund' => true,
|
|
'allow_ticket_partial_refund' => true,
|
|
'ticket_partial_refund_percentage' => 25.50,
|
|
])
|
|
->assertOk()
|
|
->assertJsonPath('data.allow_ticket_total_refund', true)
|
|
->assertJsonPath('data.allow_ticket_partial_refund', true)
|
|
->assertJsonPath('data.ticket_partial_refund_percentage', '25.50');
|
|
|
|
$this->assertDatabaseHas('tenants', [
|
|
'id' => $tenant->id,
|
|
'allow_ticket_total_refund' => true,
|
|
'allow_ticket_partial_refund' => true,
|
|
'ticket_partial_refund_percentage' => 25.50,
|
|
]);
|
|
|
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
|
'ticket_partial_refund_percentage' => 100,
|
|
])->assertUnprocessable()
|
|
->assertJsonValidationErrors('ticket_partial_refund_percentage');
|
|
|
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
|
'ticket_partial_refund_percentage' => 12.345,
|
|
])->assertUnprocessable()
|
|
->assertJsonValidationErrors('ticket_partial_refund_percentage');
|
|
}
|
|
|
|
private function createTenant(string $code): Tenant
|
|
{
|
|
$attachmentIds = collect(['header', 'footer'])->map(function (string $name): int {
|
|
$key = (string) Str::uuid();
|
|
|
|
return Attachment::query()->create([
|
|
'key' => $key,
|
|
'path' => "tenants/{$key}.png",
|
|
'filename' => "{$name}.png",
|
|
'type' => AttachmentType::Image,
|
|
'mime_type' => 'image/png',
|
|
])->id;
|
|
});
|
|
|
|
$clientId = DB::table('clients')->insertGetId([
|
|
'code' => $code,
|
|
'name' => Str::headline($code),
|
|
]);
|
|
|
|
$tenantId = DB::table('tenants')->insertGetId([
|
|
'client_id' => $clientId,
|
|
'codigo' => $code,
|
|
'nombre' => Str::headline($code),
|
|
'dominio' => "{$code}.test",
|
|
'primary_color' => '#000000',
|
|
'secondary_color' => '#000000',
|
|
'danger_color' => '#000000',
|
|
'success_color' => '#000000',
|
|
'header_bg_color' => '#ffffff',
|
|
'footer_bg_color' => '#ffffff',
|
|
'header_logo_id' => $attachmentIds[0],
|
|
'footer_logo_id' => $attachmentIds[1],
|
|
]);
|
|
|
|
return Tenant::query()->findOrFail($tenantId);
|
|
}
|
|
}
|