171 lines
5.1 KiB
PHP
171 lines
5.1 KiB
PHP
<?php
|
|
|
|
use App\Models\Country;
|
|
use App\Models\Shipping;
|
|
use App\Models\ShippingCountry;
|
|
use App\Models\ShoppingOrder;
|
|
use App\Models\ShoppingUser;
|
|
use App\Models\UserAbo;
|
|
use App\Models\UserAboOrder;
|
|
use App\Models\UserShop;
|
|
use App\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
function createPaypalHoldAbo(array $overrides = []): array
|
|
{
|
|
$country = Country::firstOrCreate(['code' => 'DE'], [
|
|
'phone' => '49',
|
|
'en' => 'Germany',
|
|
'de' => 'Deutschland',
|
|
'es' => 'Alemania',
|
|
'fr' => 'Allemagne',
|
|
'it' => 'Germania',
|
|
'ru' => 'Германия',
|
|
]);
|
|
|
|
Shipping::firstOrCreate(['name' => 'Standard'], ['active' => true]);
|
|
$shipping = Shipping::where('name', 'Standard')->first();
|
|
|
|
ShippingCountry::firstOrCreate([
|
|
'shipping_id' => $shipping->id,
|
|
'country_id' => $country->id,
|
|
]);
|
|
|
|
$shopOwner = User::forceCreate([
|
|
'email' => 'shop-owner-'.uniqid('', true).'@test.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
]);
|
|
|
|
$uniqueSuffix = uniqid('', true);
|
|
$userShop = UserShop::create([
|
|
'user_id' => $shopOwner->id,
|
|
'name' => 'TS'.$uniqueSuffix,
|
|
'slug' => 'ts-'.$uniqueSuffix,
|
|
'active' => true,
|
|
]);
|
|
|
|
$consultant = User::forceCreate([
|
|
'email' => 'berater-'.uniqid('', true).'@test.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
]);
|
|
|
|
$shoppingUser = ShoppingUser::create([
|
|
'auth_user_id' => $consultant->id,
|
|
'member_id' => $consultant->id,
|
|
'billing_country_id' => $country->id,
|
|
'shipping_country_id' => $country->id,
|
|
'billing_email' => 'abo-'.uniqid().'@test.com',
|
|
'is_for' => 'me',
|
|
'is_from' => 'user_order',
|
|
]);
|
|
|
|
$referenceOrder = ShoppingOrder::create([
|
|
'shopping_user_id' => $shoppingUser->id,
|
|
'auth_user_id' => $consultant->id,
|
|
'member_id' => $consultant->id,
|
|
'country_id' => $country->id,
|
|
'user_shop_id' => $userShop->id,
|
|
'payment_for' => 3,
|
|
'points' => 10,
|
|
'is_abo' => true,
|
|
'paid' => true,
|
|
'txaction' => 'paid',
|
|
'mode' => 'test',
|
|
'total' => 100,
|
|
'subtotal' => 90,
|
|
'total_shipping' => 105,
|
|
]);
|
|
|
|
$aboData = array_merge([
|
|
'user_id' => $consultant->id,
|
|
'member_id' => $consultant->id,
|
|
'shopping_user_id' => $shoppingUser->id,
|
|
'is_for' => 'me',
|
|
'email' => $shoppingUser->billing_email,
|
|
'payone_userid' => rand(100000, 999999),
|
|
'clearingtype' => 'wlt',
|
|
'wallettype' => 'PPE',
|
|
'active' => true,
|
|
'status' => 3,
|
|
'abo_interval' => 5,
|
|
'start_date' => '2026-01-05',
|
|
'last_date' => '2026-04-05',
|
|
'next_date' => '2026-04-05',
|
|
], $overrides);
|
|
|
|
$userAbo = UserAbo::create($aboData);
|
|
|
|
UserAboOrder::create([
|
|
'user_abo_id' => $userAbo->id,
|
|
'shopping_order_id' => $referenceOrder->id,
|
|
'status' => 3,
|
|
'paid' => false,
|
|
]);
|
|
|
|
return [
|
|
'userAbo' => $userAbo,
|
|
'consultant' => $consultant,
|
|
'shoppingUser' => $shoppingUser,
|
|
'referenceOrder' => $referenceOrder,
|
|
'country' => $country,
|
|
'userShop' => $userShop,
|
|
];
|
|
}
|
|
|
|
it('findet nur PayPal-Abos mit Status 3 und next_date 2026-04-05 im Dry-Run', function () {
|
|
createPaypalHoldAbo();
|
|
|
|
createPaypalHoldAbo(['clearingtype' => 'cc', 'wallettype' => null]);
|
|
createPaypalHoldAbo(['status' => 2]);
|
|
createPaypalHoldAbo(['next_date' => '2026-05-05']);
|
|
|
|
$this->artisan('abo:retry-failed-paypal', ['--dry-run' => true])
|
|
->assertSuccessful()
|
|
->expectsOutputToContain('Betroffene Abos: 1');
|
|
});
|
|
|
|
it('meldet wenn keine betroffenen Abos vorhanden sind', function () {
|
|
$this->artisan('abo:retry-failed-paypal', ['--dry-run' => true])
|
|
->assertSuccessful()
|
|
->expectsOutputToContain('Keine betroffenen PayPal-Abos');
|
|
});
|
|
|
|
it('überspringt Abos die heute bereits bezahlt wurden', function () {
|
|
$data = createPaypalHoldAbo();
|
|
$abo = $data['userAbo'];
|
|
|
|
UserAboOrder::create([
|
|
'user_abo_id' => $abo->id,
|
|
'shopping_order_id' => $data['referenceOrder']->id,
|
|
'status' => 1,
|
|
'paid' => true,
|
|
]);
|
|
|
|
$this->artisan('abo:retry-failed-paypal', ['--abo-id' => $abo->id])
|
|
->assertSuccessful()
|
|
->expectsOutputToContain('Bereits heute bezahlt');
|
|
});
|
|
|
|
it('zeigt korrekte Zusammenfassung im Dry-Run', function () {
|
|
createPaypalHoldAbo();
|
|
createPaypalHoldAbo();
|
|
createPaypalHoldAbo();
|
|
|
|
$this->artisan('abo:retry-failed-paypal', ['--dry-run' => true])
|
|
->assertSuccessful()
|
|
->expectsOutputToContain('Betroffene Abos: 3');
|
|
});
|
|
|
|
it('filtert korrekt nach einzelner Abo-ID', function () {
|
|
$first = createPaypalHoldAbo();
|
|
createPaypalHoldAbo();
|
|
|
|
$this->artisan('abo:retry-failed-paypal', ['--dry-run' => true, '--abo-id' => $first['userAbo']->id])
|
|
->assertSuccessful()
|
|
->expectsOutputToContain('Betroffene Abos: 1');
|
|
});
|