mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-05-03 16:24:55 +00:00
🔥 **Cleanup:** Removed BookCase and OrangePill models, factories, migrations, and related references. Added tests for new service and meetup creation flows. Updated PHPUnit settings and browser-specific configurations.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\Country;
|
||||
use Livewire\Livewire;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->country = Country::factory()->create(['code' => 'de']);
|
||||
});
|
||||
|
||||
it('creates a City with valid data', function () {
|
||||
actingAsUser();
|
||||
|
||||
Livewire::test('cities.create')
|
||||
->set('name', 'Berlin')
|
||||
->set('country_id', $this->country->id)
|
||||
->set('latitude', 52.52)
|
||||
->set('longitude', 13.405)
|
||||
->call('createCity')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(City::query()->where('name', 'Berlin')->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('rejects city creation without a name (country_id is preset by mount() from the route prefix)', function () {
|
||||
actingAsUser();
|
||||
|
||||
Livewire::test('cities.create')
|
||||
->call('createCity')
|
||||
->assertHasErrors(['name' => 'required']);
|
||||
});
|
||||
|
||||
it('rejects city creation when country_id is explicitly cleared', function () {
|
||||
actingAsUser();
|
||||
|
||||
Livewire::test('cities.create')
|
||||
->set('name', 'No Country City')
|
||||
->set('country_id', null)
|
||||
->set('latitude', 1)
|
||||
->set('longitude', 1)
|
||||
->call('createCity')
|
||||
->assertHasErrors(['country_id' => 'required']);
|
||||
});
|
||||
|
||||
it('rejects city creation with out-of-range latitude', function () {
|
||||
actingAsUser();
|
||||
|
||||
Livewire::test('cities.create')
|
||||
->set('name', 'Bad Lat')
|
||||
->set('country_id', $this->country->id)
|
||||
->set('latitude', 150)
|
||||
->set('longitude', 0)
|
||||
->call('createCity')
|
||||
->assertHasErrors(['latitude' => 'between']);
|
||||
});
|
||||
|
||||
it('rejects city creation with non-existent country', function () {
|
||||
actingAsUser();
|
||||
|
||||
Livewire::test('cities.create')
|
||||
->set('name', 'No Country')
|
||||
->set('country_id', 999999)
|
||||
->set('latitude', 0)
|
||||
->set('longitude', 0)
|
||||
->call('createCity')
|
||||
->assertHasErrors(['country_id' => 'exists']);
|
||||
});
|
||||
|
||||
it('updates an existing city', function () {
|
||||
$city = City::factory()->create(['name' => 'Old Name', 'country_id' => $this->country->id]);
|
||||
actingAsUser();
|
||||
|
||||
Livewire::test('cities.edit', ['city' => $city])
|
||||
->set('name', 'New Name')
|
||||
->set('country_id', $this->country->id)
|
||||
->set('latitude', 52.52)
|
||||
->set('longitude', 13.405)
|
||||
->call('updateCity')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($city->refresh()->name)->toBe('New Name');
|
||||
});
|
||||
Reference in New Issue
Block a user