Files
Toiminnanohjaus/tests/Feature/Modules/Shared/CompanyDetailsTest.php
T
petriandClaude Sonnet 5.5 7d7b72989d Add an editable menu name and reserve billing material numbers on creation
- Company details get an optional "Valikon nimi", shown at the left of the
  main menu; it falls back to the application name when empty.
- A billing material gets its running number (billing_exports.number) only
  when it is created, so discarded drafts leave no gaps. Drafts have no
  number; existing created materials are numbered by the migration, and the
  CSV file name uses the number.
- TaskAssigneeMigrationTest rolls back from its own migration onward instead
  of assuming it is the last one.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-24 19:41:57 +02:00

89 lines
3.0 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Shared\Application\UseCases\CompanyDetailsStore;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
it('lets the admin save the company details', function () {
$this->actingAs(User::factory()->admin()->create());
Livewire::test('shared::company')
->set('name', 'Mediatalo Oy')
->set('business_id', '737546-2')
->set('address', "Kauppakatu 1\n40100 Jyväskylä")
->set('email', '[email protected]')
->call('save')
->assertHasNoErrors()
->assertSet('business_id', '0737546-2')
->assertSet('statusMessage', __('company.saved'));
$details = app(CompanyDetailsStore::class)->get();
expect($details->name)->toBe('Mediatalo Oy')
->and($details->email)->toBe('[email protected]')
->and($details->phone)->toBeNull()
->and($details->vatNumber())->toBe('FI07375462');
Livewire::test('shared::company')->assertSet('name', 'Mediatalo Oy');
});
it('rejects an invalid business ID and email address', function () {
$this->actingAs(User::factory()->admin()->create());
Livewire::test('shared::company')
->set('name', 'Mediatalo Oy')
->set('business_id', '1234567-8')
->call('save')
->assertHasErrors(['business_id' => [__('company.errors.business_id')]])
->set('business_id', '0737546-2')
->set('email', 'ei-osoite')
->call('save')
->assertHasErrors(['email' => [__('company.errors.email')]]);
expect(app(CompanyDetailsStore::class)->get())->toBeNull();
});
it('keeps everyone but the admin out', function () {
$this->actingAs(User::factory()->management()->create());
$this->get(route('settings.company'))->assertForbidden();
});
it('saves the menu name and shows it at the left of the main menu', function () {
$this->actingAs(User::factory()->admin()->create());
Livewire::test('shared::company')
->set('name', 'Mediatalo Oy')
->set('menu_name', ' Mediatalo Työt ')
->set('business_id', '0737546-2')
->call('save')
->assertHasNoErrors();
expect(app(CompanyDetailsStore::class)->menuName())->toBe('Mediatalo Työt');
Livewire::test('shared::company')->assertSet('menu_name', 'Mediatalo Työt');
$this->get(route('customers.index'))->assertSee('Mediatalo Työt');
});
it('falls back to the application name when the menu name is empty, even before other details are saved', function () {
$store = app(CompanyDetailsStore::class);
expect($store->get())->toBeNull()
->and($store->menuName())->toBe(config('app.name'));
});
it('rejects a menu name over 100 characters', function () {
$this->actingAs(User::factory()->admin()->create());
Livewire::test('shared::company')
->set('name', 'Mediatalo Oy')
->set('business_id', '0737546-2')
->set('menu_name', str_repeat('a', 101))
->call('save')
->assertHasErrors(['menu_name' => [__('company.errors.menu_name')]]);
});