- Jobs get a budget / quoted amount (cents, VAT 0). Only users who may see quotes see and edit it on the job form and page, and only they see its changes in the history. Others' saves keep the stored amount: the server decides whether the amount is set, not the browser. - Jobs record when they were done: set when a job first reaches a status that locks its hours, kept through the billing statuses, cleared when management opens the lock. The billing export will use it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
94 lines
3.7 KiB
PHP
94 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
|
use App\Modules\Users\Domain\Enums\MoneyPermission;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->job = CustomerJobModel::factory()->quoted(450000)->create(['name' => 'Messuvideo', 'status' => JobStatus::Order]);
|
|
});
|
|
|
|
it('lets management set the quoted amount and see it with its history', function () {
|
|
$this->actingAs(User::factory()->management()->create());
|
|
|
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
|
->assertSet('form.quoted_amount', '4500,00')
|
|
->set('form.quoted_amount', '5200,50')
|
|
->call('save')
|
|
->assertHasNoErrors();
|
|
|
|
expect($this->job->refresh()->quoted_amount_cents)->toBe(520050);
|
|
|
|
$this->get(route('jobs.show', $this->job->id))
|
|
->assertSee('Budjetti / tarjoussumma')
|
|
->assertSee("5\u{00A0}200,50\u{00A0}€", false)
|
|
->assertSee("4\u{00A0}500,00\u{00A0}€", false);
|
|
});
|
|
|
|
it('rejects an invalid quoted amount with a Finnish field error', function () {
|
|
$this->actingAs(User::factory()->management()->create());
|
|
|
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
|
->set('form.quoted_amount', '12,345')
|
|
->call('save')
|
|
->assertHasErrors(['form.quoted_amount' => [__('jobs.errors.invalid_amount')]]);
|
|
});
|
|
|
|
it('hides the quoted amount from employees without the quotes permission and keeps it when they save', function () {
|
|
$this->actingAs(User::factory()->management()->create());
|
|
Livewire::test('jobs::form', ['job' => $this->job->id])->set('form.quoted_amount', '5000')->call('save');
|
|
|
|
$this->actingAs(User::factory()->employee()->create());
|
|
|
|
$this->get(route('jobs.show', $this->job->id))
|
|
->assertOk()
|
|
->assertDontSee('Budjetti / tarjoussumma')
|
|
->assertDontSee("5\u{00A0}000,00\u{00A0}€", false);
|
|
|
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
|
->assertSet('form.quoted_amount', '')
|
|
->assertDontSee('Budjetti / tarjoussumma')
|
|
->set('form.quoted_amount', '1')
|
|
->set('form.name', 'Messuvideo 2')
|
|
->call('save')
|
|
->assertHasNoErrors();
|
|
|
|
expect($this->job->refresh()->quoted_amount_cents)->toBe(500000)
|
|
->and($this->job->name)->toBe('Messuvideo 2');
|
|
});
|
|
|
|
it('shows the quoted amount to an employee with the quotes permission', function () {
|
|
$this->actingAs(User::factory()->employee()->withMoneyPermissions(MoneyPermission::Quotes)->create());
|
|
|
|
$this->get(route('jobs.show', $this->job->id))->assertSee("4\u{00A0}500,00\u{00A0}€", false);
|
|
|
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
|
->set('form.quoted_amount', '')
|
|
->call('save')
|
|
->assertHasNoErrors();
|
|
|
|
expect($this->job->refresh()->quoted_amount_cents)->toBeNull();
|
|
});
|
|
|
|
it('records when a job is done and clears it when management opens the lock', function () {
|
|
$this->actingAs(User::factory()->management()->create());
|
|
|
|
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'done');
|
|
$completedAt = $this->job->refresh()->completed_at;
|
|
|
|
expect($completedAt)->not->toBeNull();
|
|
|
|
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'invoiced');
|
|
expect($this->job->refresh()->completed_at?->equalTo($completedAt))->toBeTrue();
|
|
|
|
$this->get(route('jobs.show', $this->job->id))->assertSee('Valmistunut');
|
|
|
|
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'in_production');
|
|
expect($this->job->refresh()->completed_at)->toBeNull();
|
|
});
|