14-04-2026
This commit is contained in:
parent
f58c709945
commit
0f82fea88a
72 changed files with 7414 additions and 148 deletions
101
tests/Feature/PaymentDashboard/CheckoutFunnelTrackingTest.php
Normal file
101
tests/Feature/PaymentDashboard/CheckoutFunnelTrackingTest.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
use App\Models\CheckoutFunnelEvent;
|
||||
use App\Services\CheckoutFunnelTracker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('speichert ein checkout_visited Ereignis', function () {
|
||||
CheckoutFunnelTracker::visitedCheckout(consultantUserId: 42, metadata: ['is_from' => 'shopping']);
|
||||
|
||||
expect(CheckoutFunnelEvent::count())->toBe(1);
|
||||
|
||||
$event = CheckoutFunnelEvent::first();
|
||||
expect($event->event)->toBe('checkout_visited');
|
||||
expect($event->consultant_user_id)->toBe(42);
|
||||
expect($event->metadata)->toMatchArray(['is_from' => 'shopping']);
|
||||
});
|
||||
|
||||
it('speichert ein form_submitted Ereignis', function () {
|
||||
CheckoutFunnelTracker::submittedForm(
|
||||
shoppingUserId: 1,
|
||||
shoppingOrderId: 10,
|
||||
consultantUserId: 5,
|
||||
paymentMethod: 'elv',
|
||||
amountCents: 4990,
|
||||
);
|
||||
|
||||
$event = CheckoutFunnelEvent::first();
|
||||
expect($event->event)->toBe('form_submitted');
|
||||
expect($event->shopping_user_id)->toBe(1);
|
||||
expect($event->shopping_order_id)->toBe(10);
|
||||
expect($event->payment_method)->toBe('elv');
|
||||
expect($event->amount_cents)->toBe(4990);
|
||||
});
|
||||
|
||||
it('speichert ein payment_initiated Ereignis', function () {
|
||||
CheckoutFunnelTracker::initiatedPayment(
|
||||
shoppingUserId: 1,
|
||||
shoppingOrderId: 10,
|
||||
shoppingPaymentId: 20,
|
||||
consultantUserId: 5,
|
||||
paymentMethod: 'cc',
|
||||
amountCents: 9900,
|
||||
);
|
||||
|
||||
$event = CheckoutFunnelEvent::first();
|
||||
expect($event->event)->toBe('payment_initiated');
|
||||
expect($event->shopping_payment_id)->toBe(20);
|
||||
expect($event->amount_cents)->toBe(9900);
|
||||
});
|
||||
|
||||
it('speichert ein payment_returned Ereignis mit return_status', function () {
|
||||
CheckoutFunnelTracker::returnedFromPayment(
|
||||
shoppingPaymentId: 20,
|
||||
returnStatus: 'cancel',
|
||||
);
|
||||
|
||||
$event = CheckoutFunnelEvent::first();
|
||||
expect($event->event)->toBe('payment_returned');
|
||||
expect($event->return_status)->toBe('cancel');
|
||||
expect($event->shopping_payment_id)->toBe(20);
|
||||
});
|
||||
|
||||
it('speichert ein payment_confirmed Ereignis', function () {
|
||||
CheckoutFunnelTracker::confirmedPayment(
|
||||
shoppingPaymentId: 20,
|
||||
txaction: 'paid',
|
||||
);
|
||||
|
||||
$event = CheckoutFunnelEvent::first();
|
||||
expect($event->event)->toBe('payment_confirmed');
|
||||
expect($event->metadata)->toMatchArray(['txaction' => 'paid']);
|
||||
});
|
||||
|
||||
it('schluckt Exceptions und loggt nur eine Warnung', function () {
|
||||
// Ungültiges event-Enum — soll keinen Fehler werfen
|
||||
expect(fn () => CheckoutFunnelTracker::visitedCheckout())->not->toThrow(\Throwable::class);
|
||||
});
|
||||
|
||||
it('Funnel-View gibt korrekten View zurück', function () {
|
||||
$admin = \App\User::forceCreate([
|
||||
'email' => 'admin-funnel-'.uniqid().'@test.com',
|
||||
'password' => \Illuminate\Support\Facades\Hash::make('secret'),
|
||||
'admin' => 2,
|
||||
'lang' => 'de',
|
||||
]);
|
||||
$this->actingAs($admin);
|
||||
|
||||
CheckoutFunnelTracker::visitedCheckout();
|
||||
CheckoutFunnelTracker::submittedForm(1, 1, null, 'elv', 3990);
|
||||
|
||||
$controller = new \App\Http\Controllers\Admin\PaymentDashboardController;
|
||||
$response = $controller->funnel();
|
||||
|
||||
expect($response->getName())->toBe('admin.payment-dashboard.funnel');
|
||||
$data = $response->getData();
|
||||
expect($data)->toHaveKey('funnelSteps');
|
||||
expect($data['funnelSteps'][0]['count'])->toBe(1);
|
||||
expect($data['funnelSteps'][1]['count'])->toBe(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue