120 lines
3.4 KiB
PHP
120 lines
3.4 KiB
PHP
<?php
|
|
|
|
use App\Models\Country;
|
|
use App\Models\Incentive;
|
|
use App\Models\IncentiveNewAbo;
|
|
use App\Models\IncentiveParticipant;
|
|
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\Incentive\IncentiveTracker;
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Carbon::setTestNow(Carbon::parse('2026-05-15 10:00:00'));
|
|
});
|
|
|
|
afterEach(function () {
|
|
Carbon::setTestNow();
|
|
});
|
|
|
|
it('trackAboActivated erfasst Berater-Eigenabo (is_for me) wie ein Kundenabo', function () {
|
|
$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]);
|
|
|
|
$consultant = User::forceCreate([
|
|
'email' => 'co-'.uniqid('', true).'@example.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
]);
|
|
|
|
$userShop = UserShop::create([
|
|
'user_id' => $consultant->id,
|
|
'name' => 'TS'.substr(uniqid('', true), 0, 6),
|
|
'slug' => 'ts-'.uniqid(),
|
|
'active' => true,
|
|
]);
|
|
|
|
$shoppingUser = ShoppingUser::create([
|
|
'auth_user_id' => $consultant->id,
|
|
'member_id' => $consultant->id,
|
|
'billing_country_id' => $country->id,
|
|
'shipping_country_id' => $country->id,
|
|
'billing_email' => 'me-'.uniqid('', true).'@example.com',
|
|
'is_from' => 'wizard',
|
|
]);
|
|
|
|
$userAbo = UserAbo::create([
|
|
'user_id' => $consultant->id,
|
|
'member_id' => null,
|
|
'shopping_user_id' => $shoppingUser->id,
|
|
'is_for' => 'me',
|
|
'email' => $shoppingUser->billing_email,
|
|
'payone_userid' => 999002,
|
|
'clearingtype' => 'cc',
|
|
'active' => true,
|
|
'status' => 2,
|
|
'abo_interval' => 1,
|
|
]);
|
|
|
|
$incentive = Incentive::factory()->create([
|
|
'qualification_start' => '2026-04-01',
|
|
'qualification_end' => '2026-07-31',
|
|
'calculation_end' => '2026-08-31',
|
|
'status' => 1,
|
|
]);
|
|
|
|
$participant = IncentiveParticipant::factory()->create([
|
|
'incentive_id' => $incentive->id,
|
|
'user_id' => $consultant->id,
|
|
]);
|
|
|
|
$shoppingOrder = ShoppingOrder::create([
|
|
'shopping_user_id' => $shoppingUser->id,
|
|
'auth_user_id' => $consultant->id,
|
|
'country_id' => $shippingCountry->id,
|
|
'user_shop_id' => $userShop->id,
|
|
'payment_for' => 6,
|
|
'points' => 50,
|
|
'is_abo' => true,
|
|
'paid' => true,
|
|
'txaction' => 'paid',
|
|
'mode' => 'test',
|
|
'total' => 100,
|
|
'subtotal' => 90,
|
|
]);
|
|
|
|
UserAboOrder::create([
|
|
'user_abo_id' => $userAbo->id,
|
|
'shopping_order_id' => $shoppingOrder->id,
|
|
'status' => 2,
|
|
'paid' => true,
|
|
]);
|
|
|
|
IncentiveTracker::trackAboActivated($shoppingOrder->fresh());
|
|
|
|
expect(
|
|
IncentiveNewAbo::where('participant_id', $participant->id)
|
|
->where('user_abo_id', $userAbo->id)
|
|
->exists()
|
|
)->toBeTrue();
|
|
});
|