'mr', 'first_name' => 'Vorname', 'last_name' => 'Nachname', 'address' => 'Alte Strasse 1', 'zipcode' => '10000', 'city' => 'Berlin', 'country_id' => $country->id, 'same_as_billing' => true, ], $accountData)); return User::forceCreate([ 'account_id' => $account->id, 'email' => $email, 'password' => bcrypt('secret'), 'lang' => 'de', ]); } function repairAboOrderUserAssignmentSeed(): array { makeShopEnv(); $oldUser = repairAboOrderUserAssignmentMakeUser('old@example.com', [ 'first_name' => 'Alter', 'last_name' => 'User', 'address' => 'Falsche Strasse 1', 'zipcode' => '11111', 'city' => 'Altstadt', ]); $targetUser = repairAboOrderUserAssignmentMakeUser('target@example.com', [ 'first_name' => 'Richtiger', 'last_name' => 'User', 'address' => 'Richtige Strasse 455', 'zipcode' => '45500', 'city' => 'Zielstadt', ]); $wrongShoppingUser = ShoppingUser::create([ 'auth_user_id' => $oldUser->id, 'billing_firstname' => 'Alter', 'billing_lastname' => 'User', 'billing_address' => 'Falsche Strasse 1', 'billing_zipcode' => '11111', 'billing_city' => 'Altstadt', 'billing_country_id' => Country::firstOrFail()->id, 'billing_email' => $oldUser->email, 'same_as_billing' => true, 'shipping_country_id' => Country::firstOrFail()->id, 'is_for' => 'me', 'is_from' => 'user_order', 'mode' => 'live', ]); $userAbo = UserAbo::create([ 'user_id' => $oldUser->id, 'shopping_user_id' => $wrongShoppingUser->id, 'is_for' => 'me', 'email' => $oldUser->email, 'payone_userid' => 900100, 'clearingtype' => 'cc', 'active' => true, 'status' => 2, 'abo_interval' => 5, 'next_date' => now()->addDays(3), ]); $order = ShoppingOrder::create([ 'shopping_user_id' => $wrongShoppingUser->id, 'auth_user_id' => $oldUser->id, 'country_id' => 1, 'language' => 'de', 'user_shop_id' => 1, 'payment_for' => 3, 'total' => 100, 'subtotal' => 90, 'shipping' => 10, 'shipping_net' => 8.4, 'subtotal_ws' => 98.4, 'tax' => 11.6, 'total_shipping' => 100, 'points' => 10, 'is_abo' => true, 'abo_interval' => 5, 'paid' => true, 'txaction' => 'paid', 'mode' => 'live', ]); UserAboOrder::create([ 'user_abo_id' => $userAbo->id, 'shopping_order_id' => $order->id, 'status' => 2, 'paid' => true, ]); UserSalesVolume::create([ 'user_id' => $oldUser->id, 'shopping_order_id' => $order->id, 'month' => now()->month, 'year' => now()->year, 'date' => now(), 'points' => 10, 'total_net' => 90, 'status_points' => 1, 'status' => 1, ]); return [$oldUser, $targetUser, $userAbo, $order, $wrongShoppingUser]; } it('zeigt die betroffene Abo-Bestellung im Trockenlauf ohne Aenderung', function () { [$oldUser, $targetUser, $userAbo, $order, $wrongShoppingUser] = repairAboOrderUserAssignmentSeed(); $exit = Artisan::call('abo:repair-order-user', [ '--abo' => (string) $userAbo->id, '--user' => (string) $targetUser->id, '--order' => (string) $order->id, '--old-user' => (string) $oldUser->id, '--no-documents' => true, ]); expect($exit)->toBe(0); expect($order->fresh()->auth_user_id)->toBe($oldUser->id); expect($order->fresh()->shopping_user_id)->toBe($wrongShoppingUser->id); }); it('korrigiert die letzte Abo-Bestellung auf den Ziel-User', function () { [$oldUser, $targetUser, $userAbo, $order, $wrongShoppingUser] = repairAboOrderUserAssignmentSeed(); $exit = Artisan::call('abo:repair-order-user', [ '--fix' => true, '--force' => true, '--abo' => (string) $userAbo->id, '--user' => (string) $targetUser->id, '--order' => (string) $order->id, '--old-user' => (string) $oldUser->id, '--no-documents' => true, ]); expect($exit)->toBe(0); $order->refresh(); $userAbo->refresh(); expect($userAbo->user_id)->toBe($targetUser->id) ->and($userAbo->email)->toBe($targetUser->email) ->and($order->auth_user_id)->toBe($targetUser->id) ->and($order->shopping_user_id)->not->toBe($wrongShoppingUser->id) ->and(UserSalesVolume::where('shopping_order_id', $order->id)->first()->user_id)->toBe($targetUser->id); $newShoppingUser = $order->shopping_user; expect($newShoppingUser->auth_user_id)->toBe($targetUser->id) ->and($newShoppingUser->billing_firstname)->toBe('Richtiger') ->and($newShoppingUser->billing_lastname)->toBe('User') ->and($newShoppingUser->billing_address)->toBe('Richtige Strasse 455') ->and($newShoppingUser->billing_email)->toBe($targetUser->email); });