Carbon::setTestNow()); /** * Berater mit Eigenabo, das schon vor dem Qualifikationsstart lief. * * @return array{0: User, 1: UserAbo} */ function includeAbosConsultant(): array { $country = Country::firstOrCreate(['code' => 'DE'], [ 'phone' => '49', 'en' => 'Germany', 'de' => 'Deutschland', 'es' => 'Alemania', 'fr' => 'Allemagne', 'it' => 'Germania', 'ru' => 'Германия', ]); $consultant = User::forceCreate([ 'email' => 'inc-abos-'.uniqid('', true).'@example.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' => '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' => 999003, 'clearingtype' => 'cc', 'active' => true, 'status' => 2, 'abo_interval' => 1, ]); $userAbo->forceFill(['created_at' => '2026-06-15 12:00:00'])->save(); return [$consultant, $userAbo]; } function includeAbosIncentive(bool $includeAbos): Incentive { return Incentive::factory()->create([ 'qualification_start' => '2026-10-01', 'qualification_end' => '2027-01-31', 'calculation_end' => '2027-01-31', 'status' => 1, 'points_partner_onetime' => 1, 'points_abo_onetime' => 0, 'min_direct_partners' => 0, 'min_customer_abos' => 0, 'include_sales_points' => false, 'include_abos' => $includeAbos, ]); } it('erfasst bei ausgeschaltetem Schalter keine Abos', function () { [$consultant] = includeAbosConsultant(); $incentive = includeAbosIncentive(false); $participant = IncentiveParticipant::factory()->create([ 'incentive_id' => $incentive->id, 'user_id' => $consultant->id, ]); Artisan::call('incentive:calculate', ['incentive_id' => (string) $incentive->id]); expect(IncentiveNewAbo::where('participant_id', $participant->id)->exists())->toBeFalse(); Artisan::call('incentive:calculate', ['incentive_id' => (string) $incentive->id, '--force' => true]); expect(IncentiveNewAbo::where('participant_id', $participant->id)->exists())->toBeFalse() ->and($participant->fresh()->qualified_abos)->toBe(0) ->and($incentive->usesAbos())->toBeFalse(); }); it('erfasst das Eigenabo weiterhin, solange der Schalter an ist', function () { [$consultant, $userAbo] = includeAbosConsultant(); $incentive = includeAbosIncentive(true); $participant = IncentiveParticipant::factory()->create([ 'incentive_id' => $incentive->id, 'user_id' => $consultant->id, ]); Artisan::call('incentive:calculate', ['incentive_id' => (string) $incentive->id]); expect(IncentiveNewAbo::where('participant_id', $participant->id)->where('user_abo_id', $userAbo->id)->exists()) ->toBeTrue(); }); it('raeumt bereits erfasste Abos beim naechsten Lauf ab, wenn der Schalter aus ist', function () { [$consultant, $userAbo] = includeAbosConsultant(); $incentive = includeAbosIncentive(true); $participant = IncentiveParticipant::factory()->create([ 'incentive_id' => $incentive->id, 'user_id' => $consultant->id, ]); Artisan::call('incentive:calculate', ['incentive_id' => (string) $incentive->id]); expect($participant->fresh()->qualified_abos)->toBe(1); $incentive->update(['include_abos' => false]); Artisan::call('incentive:calculate', ['incentive_id' => (string) $incentive->id]); expect(IncentiveNewAbo::where('participant_id', $participant->id)->exists())->toBeFalse() ->and(IncentivePointsLog::where('participant_id', $participant->id)->where('type', 'abo')->exists())->toBeFalse() ->and($participant->fresh()->qualified_abos)->toBe(0); });