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); } }