employee = User::factory()->create(['name' => 'Eero Työntekijä']); $this->actingAs($this->employee); $this->customer = CustomerModel::factory()->create(['name' => 'Mainos Oy']); $this->unit = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole(); }); it('opens a job with the required fields and the defaults, then clears the form', function () { $this->get(route('jobs.quick'))->assertOk()->assertSee('Pikavastaanotto'); Livewire::test('jobs::quick') ->assertSet('form.responsible_user_id', (string) $this->employee->id) ->call('selectCustomer', $this->customer->id) ->set('form.name', 'Kevätkampanja') ->set('form.description', 'Some-mainokset huhtikuulle.') ->set('form.service_unit_id', (string) $this->unit->id) ->set('form.status', 'prospect') ->call('save') ->assertHasNoErrors() ->assertSee('Asiakastyö '.now()->year.'-0001 Kevätkampanja luotu.') ->assertSee('Avaa työ '.now()->year.'-0001') ->assertSee('Täydennä tietoja') ->assertSet('form.name', '') ->assertSet('form.customer_id', '') ->assertSet('form.status', 'prospect') ->assertSet('form.responsible_user_id', (string) $this->employee->id); $job = CustomerJobModel::query()->sole(); expect($job->status->value)->toBe('prospect') ->and($job->priority->value)->toBe('normal') ->and($job->kind->value)->toBe('one_off') ->and($job->customer_id)->toBe($this->customer->id) ->and(DB::table('customer_job_service_unit')->where('customer_job_id', $job->id)->pluck('service_unit_id')->all())->toBe([$this->unit->id]) ->and(DB::table('customer_job_changes')->where('customer_job_id', $job->id)->value('field'))->toBe('created'); }); it('adds a new customer during intake', function () { Livewire::test('jobs::quick') ->set('customerSearch', 'Kahvila Kulma') ->call('createCustomer') ->assertSee('Asiakas Kahvila Kulma lisätty ja valittu.') ->set('form.name', 'Ruokalistan kuvaus') ->set('form.service_unit_id', (string) $this->unit->id) ->call('save') ->assertHasNoErrors(); expect(CustomerJobModel::query()->sole()->customer_id) ->toBe(CustomerModel::query()->where('name', 'Kahvila Kulma')->sole()->id); }); it('shows Finnish errors for missing fields and does not accept other statuses', function () { Livewire::test('jobs::quick') ->set('form.responsible_user_id', '') ->call('save') ->assertHasErrors(['form.customer_id', 'form.name', 'form.service_unit_id', 'form.responsible_user_id']) ->assertSee('Valitse asiakas tai lisää uusi.') ->assertSee('Valitse palveluyksikkö.'); Livewire::test('jobs::quick') ->call('selectCustomer', $this->customer->id) ->set('form.name', 'Työ') ->set('form.service_unit_id', (string) $this->unit->id) ->set('form.status', 'billed') ->call('save') ->assertHasErrors(['form.status']); expect(CustomerJobModel::query()->count())->toBe(0); }); it('keeps subcontractors out and shows the menu link only to those who may open jobs', function () { $this->get(route('jobs.index'))->assertSee('Pikavastaanotto'); $this->actingAs(User::factory()->subcontractor()->create()); $this->get(route('jobs.quick'))->assertForbidden(); $this->get(route('jobs.index'))->assertDontSee('Pikavastaanotto'); });