Files
Toiminnanohjaus/tests/Feature/Modules/Shared/CompanyDetailsTest.php
petriandClaude Sonnet 5.5 7c605014c7 Set the calendar's daily capacity in the company details
The task calendar's daily maximum moves from the hidden setting
jobs.daily_capacity_hours to shared.daily_capacity_hours, edited by the
admin on the company details page. An empty field means 7.5 hours.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-25 11:00:35 +02:00

129 lines
4.4 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Jobs\Application\Services\TaskPlanner;
use App\Modules\Shared\Application\UseCases\CompanyDetailsStore;
use App\Modules\Shared\Application\UseCases\DailyCapacity;
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('saves the calendar daily capacity, 7.5 hours when empty', function () {
$this->actingAs(User::factory()->admin()->create());
$capacity = app(DailyCapacity::class);
Livewire::test('shared::company')
->assertSet('daily_capacity_hours', '')
->set('name', 'Mediatalo Oy')
->set('business_id', '0737546-2')
->set('daily_capacity_hours', '6,5')
->call('save')
->assertHasNoErrors();
expect($capacity->minutes())->toBe(390)
->and(app(TaskPlanner::class)->capacityMinutes())->toBe(390);
Livewire::test('shared::company')
->assertSet('daily_capacity_hours', '6,5')
->set('daily_capacity_hours', '')
->call('save')
->assertHasNoErrors();
expect($capacity->minutes())->toBe(450);
});
it('rejects an invalid daily capacity without saving anything', function () {
$this->actingAs(User::factory()->admin()->create());
Livewire::test('shared::company')
->set('name', 'Mediatalo Oy')
->set('business_id', '0737546-2')
->set('daily_capacity_hours', '25')
->call('save')
->assertHasErrors(['daily_capacity_hours' => [__('company.errors.daily_capacity_hours')]]);
expect(app(CompanyDetailsStore::class)->get())->toBeNull()
->and(app(DailyCapacity::class)->hours())->toBeNull();
});
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')]]);
});