10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
152
tests/Feature/RepairMissingAboFromOrdersTest.php
Normal file
152
tests/Feature/RepairMissingAboFromOrdersTest.php
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @see \App\Console\Commands\RepairMissingAboFromOrders
|
||||
*/
|
||||
|
||||
use App\Models\Country;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Models\Shipping;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
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 Illuminate\Support\Facades\Artisan;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
|
||||
function repairMissingAboSeedOrder(): ShoppingOrder
|
||||
{
|
||||
$country = Country::create([
|
||||
'code' => 'DE',
|
||||
'phone' => '49',
|
||||
'en' => 'Germany',
|
||||
'de' => 'Deutschland',
|
||||
'es' => 'Alemania',
|
||||
'fr' => 'Allemagne',
|
||||
'it' => 'Germania',
|
||||
'ru' => 'Германия',
|
||||
]);
|
||||
|
||||
$shipping = Shipping::create([
|
||||
'name' => 'Standard',
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$shippingCountry = ShippingCountry::create([
|
||||
'shipping_id' => $shipping->id,
|
||||
'country_id' => $country->id,
|
||||
]);
|
||||
|
||||
$shopOwner = User::forceCreate([
|
||||
'email' => 'shop-owner-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
$userShop = UserShop::create([
|
||||
'user_id' => $shopOwner->id,
|
||||
'name' => 'TS'.substr(uniqid('', true), 0, 8),
|
||||
'slug' => 'ts-'.uniqid(),
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$consultant = User::forceCreate([
|
||||
'email' => 'consultant-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
$customer = User::forceCreate([
|
||||
'email' => 'customer-'.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' => 'cust-'.uniqid('', true).'@example.com',
|
||||
'is_for' => 'ot',
|
||||
]);
|
||||
|
||||
$shoppingOrder = ShoppingOrder::create([
|
||||
'shopping_user_id' => $shoppingUser->id,
|
||||
'auth_user_id' => $customer->id,
|
||||
'member_id' => $consultant->id,
|
||||
'country_id' => $shippingCountry->id,
|
||||
'user_shop_id' => $userShop->id,
|
||||
'payment_for' => 6,
|
||||
'points' => 10,
|
||||
'is_abo' => true,
|
||||
'abo_interval' => 15,
|
||||
'paid' => true,
|
||||
'txaction' => 'paid',
|
||||
'mode' => 'test',
|
||||
'total' => 100,
|
||||
'subtotal' => 90,
|
||||
]);
|
||||
|
||||
$shoppingPayment = ShoppingPayment::create([
|
||||
'shopping_order_id' => $shoppingOrder->id,
|
||||
'reference' => 'ref-'.uniqid(),
|
||||
'amount' => 10000,
|
||||
'currency' => 'EUR',
|
||||
'clearingtype' => 'cc',
|
||||
'abo_interval' => 15,
|
||||
'mode' => 'test',
|
||||
]);
|
||||
|
||||
PaymentTransaction::create([
|
||||
'shopping_payment_id' => $shoppingPayment->id,
|
||||
'request' => 'transaction',
|
||||
'txid' => 123456,
|
||||
'userid' => 987654,
|
||||
'status' => 'PAYONE',
|
||||
'txaction' => 'paid',
|
||||
'mode' => 'test',
|
||||
]);
|
||||
|
||||
return $shoppingOrder;
|
||||
}
|
||||
|
||||
it('zeigt fehlende Abo-Verknuepfung im Trockenlauf ohne Aenderung', function () {
|
||||
$order = repairMissingAboSeedOrder();
|
||||
|
||||
expect(UserAbo::count())->toBe(0);
|
||||
|
||||
$exit = Artisan::call('abo:repair-missing', [
|
||||
'--order' => (string) $order->id,
|
||||
'--mode' => 'test',
|
||||
]);
|
||||
|
||||
expect($exit)->toBe(0);
|
||||
expect(UserAbo::count())->toBe(0);
|
||||
});
|
||||
|
||||
it('repariert fehlende UserAbo-Verknuepfung mit --fix --force', function () {
|
||||
$order = repairMissingAboSeedOrder();
|
||||
|
||||
expect(UserAboOrder::where('shopping_order_id', $order->id)->exists())->toBeFalse();
|
||||
|
||||
$exit = Artisan::call('abo:repair-missing', [
|
||||
'--fix' => true,
|
||||
'--force' => true,
|
||||
'--order' => (string) $order->id,
|
||||
'--mode' => 'test',
|
||||
]);
|
||||
|
||||
expect($exit)->toBe(0);
|
||||
|
||||
$order->refresh();
|
||||
expect($order->getUserAbo())->not->toBeNull();
|
||||
expect($order->getUserAbo()->status)->toBe(2);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue