10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Country;
|
||||
use App\Models\Incentive;
|
||||
use App\Models\IncentiveNewPartner;
|
||||
use App\Models\IncentiveParticipant;
|
||||
use App\Models\Product;
|
||||
use App\Models\Shipping;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserShop;
|
||||
use App\Services\Incentive\IncentiveTracker;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Carbon::setTestNow(Carbon::parse('2026-05-15 12:00:00'));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
Carbon::setTestNow();
|
||||
});
|
||||
|
||||
function createWizardRegistrationOrderWithProducts(User $registrant, User $shopOwner, array $products): ShoppingOrder
|
||||
{
|
||||
$country = Country::create([
|
||||
'code' => 'DE',
|
||||
'phone' => '49',
|
||||
'en' => 'Germany',
|
||||
'de' => 'Deutschland',
|
||||
'es' => 'Alemania',
|
||||
'fr' => 'Allemagne',
|
||||
'it' => 'Germania',
|
||||
'ru' => 'Германия',
|
||||
]);
|
||||
|
||||
$shipping = Shipping::create(['name' => 'S', 'active' => true]);
|
||||
$shippingCountry = ShippingCountry::create(['shipping_id' => $shipping->id, 'country_id' => $country->id]);
|
||||
|
||||
$userShop = UserShop::create([
|
||||
'user_id' => $shopOwner->id,
|
||||
'name' => 'T'.substr(uniqid('', true), 0, 6),
|
||||
'slug' => 't-'.uniqid(),
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$shoppingUser = ShoppingUser::create([
|
||||
'auth_user_id' => $registrant->id,
|
||||
'member_id' => $shopOwner->id,
|
||||
'billing_country_id' => $country->id,
|
||||
'shipping_country_id' => $country->id,
|
||||
'billing_email' => 'su-'.uniqid('', true).'@example.com',
|
||||
'is_from' => 'wizard',
|
||||
]);
|
||||
|
||||
$order = ShoppingOrder::create([
|
||||
'shopping_user_id' => $shoppingUser->id,
|
||||
'auth_user_id' => $registrant->id,
|
||||
'country_id' => $shippingCountry->id,
|
||||
'user_shop_id' => $userShop->id,
|
||||
'payment_for' => 1,
|
||||
'paid' => true,
|
||||
'txaction' => 'paid',
|
||||
'mode' => 'test',
|
||||
'total' => 100,
|
||||
'subtotal' => 90,
|
||||
]);
|
||||
|
||||
foreach ($products as $product) {
|
||||
ShoppingOrderItem::create([
|
||||
'shopping_order_id' => $order->id,
|
||||
'product_id' => $product->id,
|
||||
'qty' => 1,
|
||||
'price' => 50,
|
||||
]);
|
||||
}
|
||||
|
||||
return $order->fresh(['shopping_order_items.product']);
|
||||
}
|
||||
|
||||
function createProductForTest(bool $membershipOnly): Product
|
||||
{
|
||||
$id = DB::table('products')->insertGetId([
|
||||
'name' => 'P '.uniqid(),
|
||||
'title' => 'T',
|
||||
'is_membership_only' => $membershipOnly,
|
||||
'active' => true,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return Product::query()->findOrFail($id);
|
||||
}
|
||||
|
||||
it('trackNewPartner legt keinen Neupartner an bei reiner Mitgliedschaft ohne Starterpaket', function () {
|
||||
$sponsor = User::forceCreate([
|
||||
'email' => 'sp-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
$newPartner = User::forceCreate([
|
||||
'email' => 'np-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
'm_sponsor' => $sponsor->id,
|
||||
]);
|
||||
|
||||
$membershipProduct = createProductForTest(membershipOnly: true);
|
||||
|
||||
$order = createWizardRegistrationOrderWithProducts($newPartner, $sponsor, [$membershipProduct]);
|
||||
|
||||
expect($order->qualifiesForIncentiveTrackedPartner())->toBeFalse();
|
||||
|
||||
$incentive = Incentive::factory()->create([
|
||||
'qualification_start' => '2026-04-01',
|
||||
'qualification_end' => '2026-07-31',
|
||||
'calculation_end' => '2026-08-31',
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $sponsor->id,
|
||||
]);
|
||||
|
||||
IncentiveTracker::trackNewPartner($order);
|
||||
|
||||
expect(
|
||||
IncentiveNewPartner::where('user_id', $newPartner->id)->exists()
|
||||
)->toBeFalse();
|
||||
});
|
||||
|
||||
it('trackNewPartner legt Neupartner an wenn Registrierung ein Starterpaket enthält', function () {
|
||||
$sponsor = User::forceCreate([
|
||||
'email' => 'sp-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
$newPartner = User::forceCreate([
|
||||
'email' => 'np-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
'm_sponsor' => $sponsor->id,
|
||||
]);
|
||||
|
||||
$starterProduct = createProductForTest(membershipOnly: false);
|
||||
|
||||
$order = createWizardRegistrationOrderWithProducts($newPartner, $sponsor, [$starterProduct]);
|
||||
|
||||
expect($order->qualifiesForIncentiveTrackedPartner())->toBeTrue();
|
||||
|
||||
$incentive = Incentive::factory()->create([
|
||||
'qualification_start' => '2026-04-01',
|
||||
'qualification_end' => '2026-07-31',
|
||||
'calculation_end' => '2026-08-31',
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $sponsor->id,
|
||||
]);
|
||||
|
||||
IncentiveTracker::trackNewPartner($order);
|
||||
|
||||
expect(
|
||||
IncentiveNewPartner::where('user_id', $newPartner->id)->exists()
|
||||
)->toBeTrue();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue