create([ 'email' => uniqid('sup_', true).'@test.example', 'password' => bcrypt('password'), ]); $user->forceFill([ 'admin' => $adminLevel, 'confirmed' => true, 'active' => true, 'wizard' => 100, 'blocked' => false, ])->save(); return $user->fresh(); } function supplierOrderCountry(): Country { return Country::query()->firstOrCreate( ['code' => 'DE'], [ 'phone' => '00', 'en' => 'Germany', 'de' => 'Deutschland', 'es' => 'Germany', 'fr' => 'Germany', 'it' => 'Germany', 'ru' => 'Germany', 'active' => true, ] ); } test('supplier form shows order fields and active delivery time templates', function () { supplierOrderCountry(); DeliveryTime::query()->create(['label' => '3–5 Werktage', 'active' => true, 'pos' => 0]); DeliveryTime::query()->create(['label' => 'Inaktiv-Vorlage', 'active' => false, 'pos' => 1]); $this->actingAs(supplierOrderUser(7), 'user'); $this->get(route('admin.inventory.suppliers.create')) ->assertSuccessful() ->assertSee('order_method') ->assertSee('delivery_time') ->assertSee('3–5 Werktage') ->assertDontSee('Inaktiv-Vorlage'); }); test('supplier can be stored with email order method', function () { $country = supplierOrderCountry(); $this->actingAs(supplierOrderUser(7), 'user'); $this->post(route('admin.inventory.suppliers.store'), [ 'name' => 'Mail-Lieferant', 'country_id' => (string) $country->id, 'active' => '1', 'order_method' => 'email', 'order_email' => 'bestellung@example.test', 'delivery_time' => '3–5 Werktage', 'delivery_time_days' => '5', ])->assertRedirect(route('admin.inventory.suppliers.index')); $supplier = Supplier::query()->where('name', 'Mail-Lieferant')->firstOrFail(); expect($supplier->order_method)->toBe('email') ->and($supplier->order_email)->toBe('bestellung@example.test') ->and($supplier->delivery_time)->toBe('3–5 Werktage') ->and($supplier->delivery_time_days)->toBe(5); }); test('supplier delivery time days must be an integer', function () { $country = supplierOrderCountry(); $this->actingAs(supplierOrderUser(7), 'user'); $this->post(route('admin.inventory.suppliers.store'), [ 'name' => 'Falsche-Tage', 'country_id' => (string) $country->id, 'active' => '1', 'delivery_time_days' => 'viele', ])->assertSessionHasErrors('delivery_time_days'); }); test('supplier form exposes delivery time template days for autofill', function () { supplierOrderCountry(); DeliveryTime::query()->create(['label' => '3–5 Werktage', 'days' => 5, 'active' => true, 'pos' => 0]); $this->actingAs(supplierOrderUser(7), 'user'); $this->get(route('admin.inventory.suppliers.create')) ->assertSuccessful() ->assertSee('data-days="5"', false) ->assertSee('delivery_time_days'); }); test('supplier can be stored with online shop order method', function () { $country = supplierOrderCountry(); $this->actingAs(supplierOrderUser(7), 'user'); $this->post(route('admin.inventory.suppliers.store'), [ 'name' => 'Shop-Lieferant', 'country_id' => (string) $country->id, 'active' => '1', 'order_method' => 'online_shop', 'order_url' => 'https://shop.example.test/order?id=5&ref=abc', ])->assertRedirect(route('admin.inventory.suppliers.index')); $supplier = Supplier::query()->where('name', 'Shop-Lieferant')->firstOrFail(); expect($supplier->order_method)->toBe('online_shop') ->and($supplier->order_url)->toBe('https://shop.example.test/order?id=5&ref=abc'); }); test('supplier order fields can be updated', function () { $country = supplierOrderCountry(); $supplier = Supplier::query()->create([ 'name' => 'Update-Lieferant', 'country_id' => $country->id, 'active' => true, 'order_method' => 'email', 'order_email' => 'alt@example.test', ]); $this->actingAs(supplierOrderUser(7), 'user'); $this->put(route('admin.inventory.suppliers.update', $supplier), [ 'name' => 'Update-Lieferant', 'country_id' => (string) $country->id, 'active' => '1', 'order_method' => 'online_shop', 'order_url' => 'https://neu.example.test', 'delivery_time' => '1–2 Wochen', ])->assertRedirect(route('admin.inventory.suppliers.index')); $supplier->refresh(); expect($supplier->order_method)->toBe('online_shop') ->and($supplier->order_url)->toBe('https://neu.example.test') ->and($supplier->delivery_time)->toBe('1–2 Wochen'); }); test('supplier order method rejects invalid value', function () { $country = supplierOrderCountry(); $this->actingAs(supplierOrderUser(7), 'user'); $this->post(route('admin.inventory.suppliers.store'), [ 'name' => 'Falscher-Bestellweg', 'country_id' => (string) $country->id, 'active' => '1', 'order_method' => 'fax', ])->assertSessionHasErrors('order_method'); }); test('supplier order email must be valid email', function () { $country = supplierOrderCountry(); $this->actingAs(supplierOrderUser(7), 'user'); $this->post(route('admin.inventory.suppliers.store'), [ 'name' => 'Falsche-Mail', 'country_id' => (string) $country->id, 'active' => '1', 'order_method' => 'email', 'order_email' => 'keine-mail', ])->assertSessionHasErrors('order_email'); });