119 lines
3.3 KiB
PHP
119 lines
3.3 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\Services\SyS\PayoneCallbackTestbench;
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Carbon::setTestNow(Carbon::parse('2026-06-10 12:00:00'));
|
|
});
|
|
|
|
afterEach(function () {
|
|
Carbon::setTestNow();
|
|
});
|
|
|
|
it('setzt next_date auf heute und entfernt heutige UserAboOrders (Vorbereitung Cron)', function () {
|
|
$country = Country::create([
|
|
'code' => 'DE',
|
|
'phone' => '49',
|
|
'en' => 'Germany',
|
|
'de' => 'Deutschland',
|
|
'es' => 'x',
|
|
'fr' => 'x',
|
|
'it' => 'x',
|
|
'ru' => 'x',
|
|
]);
|
|
|
|
$shipping = Shipping::create(['name' => 'Std', 'active' => true]);
|
|
$shippingCountry = ShippingCountry::create([
|
|
'shipping_id' => $shipping->id,
|
|
'country_id' => $country->id,
|
|
]);
|
|
|
|
$shopOwner = User::forceCreate([
|
|
'email' => 'so-'.uniqid('', true).'@example.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
]);
|
|
|
|
$userShop = UserShop::create([
|
|
'user_id' => $shopOwner->id,
|
|
'name' => 'B'.substr(uniqid('', true), 0, 6),
|
|
'slug' => 'b-'.uniqid(),
|
|
'active' => true,
|
|
]);
|
|
|
|
$consultant = User::forceCreate([
|
|
'email' => 'co-'.uniqid('', true).'@example.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
]);
|
|
|
|
$customer = User::forceCreate([
|
|
'email' => 'cu-'.uniqid('', true).'@example.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
]);
|
|
|
|
$shoppingUser = ShoppingUser::create([
|
|
'auth_user_id' => $customer->id,
|
|
'member_id' => $consultant->id,
|
|
'billing_country_id' => $country->id,
|
|
'shipping_country_id' => $country->id,
|
|
'billing_email' => 'c@example.com',
|
|
]);
|
|
|
|
$userAbo = UserAbo::create([
|
|
'user_id' => null,
|
|
'member_id' => $consultant->id,
|
|
'shopping_user_id' => $shoppingUser->id,
|
|
'is_for' => 'ot',
|
|
'email' => 'abo@example.com',
|
|
'payone_userid' => 999002,
|
|
'clearingtype' => 'cc',
|
|
'active' => true,
|
|
'status' => 2,
|
|
'abo_interval' => 1,
|
|
'next_date' => '2026-12-01',
|
|
]);
|
|
|
|
$order = ShoppingOrder::create([
|
|
'shopping_user_id' => $shoppingUser->id,
|
|
'auth_user_id' => $customer->id,
|
|
'country_id' => $shippingCountry->id,
|
|
'user_shop_id' => $userShop->id,
|
|
'payment_for' => 6,
|
|
'points' => 10,
|
|
'paid' => true,
|
|
'mode' => 'test',
|
|
'total' => 50,
|
|
'subtotal' => 50,
|
|
]);
|
|
|
|
UserAboOrder::create([
|
|
'user_abo_id' => $userAbo->id,
|
|
'shopping_order_id' => $order->id,
|
|
'status' => 1,
|
|
'paid' => true,
|
|
]);
|
|
|
|
expect(UserAboOrder::where('user_abo_id', $userAbo->id)->count())->toBe(1);
|
|
|
|
PayoneCallbackTestbench::prepareUserAboForCronRun($userAbo->fresh());
|
|
|
|
$userAbo->refresh();
|
|
|
|
expect(Carbon::parse($userAbo->next_date)->format('Y-m-d'))->toBe('2026-06-10')
|
|
->and(UserAboOrder::where('user_abo_id', $userAbo->id)->count())->toBe(0);
|
|
});
|