create([ 'email' => uniqid('sales_', true).'@test.example', 'password' => bcrypt('password'), ]); $user->forceFill([ 'admin' => $adminLevel, 'confirmed' => true, 'active' => true, 'wizard' => 100, 'blocked' => false, ])->save(); return $user->fresh(); } function salesMakeOrder(array $overrides = []): ShoppingOrder { $country = Country::query()->forceCreate([ 'code' => 'DE', 'en' => 'Germany', 'de' => 'Deutschland', 'es' => 'Alemania', 'fr' => 'Allemagne', 'it' => 'Germania', 'ru' => 'Germanija', ]); $shipping = Shipping::query()->forceCreate(['name' => 'Standard']); $shippingCountry = ShippingCountry::query()->forceCreate([ 'shipping_id' => $shipping->id, 'country_id' => $country->id, ]); $shoppingUser = ShoppingUser::query()->forceCreate([ 'billing_country_id' => $country->id, 'shipping_country_id' => $country->id, 'billing_firstname' => 'Test', 'billing_lastname' => 'Kunde', ]); return ShoppingOrder::query()->forceCreate(array_merge([ 'shopping_user_id' => $shoppingUser->id, 'auth_user_id' => salesMakeAdmin(0)->id, 'country_id' => $shippingCountry->id, 'shipped' => 0, ], $overrides)); } test('versand-status versendet setzt shipped_at', function () { $admin = salesMakeAdmin(); $order = salesMakeOrder(); $response = $this->actingAs($admin)->post(route('admin_sales_store'), [ 'id' => $order->id, 'action' => 'store_shipped', 'shipped' => 2, ]); $response->assertRedirect(); $order->refresh(); expect($order->shipped)->toBe(2) ->and($order->shipped_at)->not->toBeNull(); }); test('zuruecksetzen auf offen entfernt shipped_at', function () { $admin = salesMakeAdmin(); $order = salesMakeOrder(['shipped' => 2, 'shipped_at' => now()]); $this->actingAs($admin)->post(route('admin_sales_store'), [ 'id' => $order->id, 'action' => 'store_shipped', 'shipped' => 0, ])->assertRedirect(); $order->refresh(); expect($order->shipped)->toBe(0) ->and($order->shipped_at)->toBeNull(); }); test('ungueltiger versand-status wird abgelehnt', function () { $admin = salesMakeAdmin(); $order = salesMakeOrder(); $response = $this->actingAs($admin)->from(route('admin_sales'))->post(route('admin_sales_store'), [ 'id' => $order->id, 'action' => 'store_shipped', 'shipped' => 99, ]); $response->assertSessionHasErrors('shipped'); expect($order->fresh()->shipped)->toBe(0); }); test('unbekannte action wird abgelehnt', function () { $admin = salesMakeAdmin(); $order = salesMakeOrder(); $this->actingAs($admin)->post(route('admin_sales_store'), [ 'id' => $order->id, 'action' => 'delete_everything', ])->assertSessionHasErrors('action'); }); test('nicht-admin wird umgeleitet und aendert nichts', function () { $user = salesMakeAdmin(1); $order = salesMakeOrder(); $this->actingAs($user)->post(route('admin_sales_store'), [ 'id' => $order->id, 'action' => 'store_shipped', 'shipped' => 2, ])->assertRedirect('/home'); expect($order->fresh()->shipped)->toBe(0); }); test('fehlende id ergibt 404', function () { $admin = salesMakeAdmin(); $this->actingAs($admin)->post(route('admin_sales_store'), [ 'action' => 'store_shipped', 'shipped' => 2, ])->assertNotFound(); });