manager = User::factory()->management()->create(); $this->actingAs($this->manager); $this->travelTo(now()->setDate(2026, 11, 20)->setTime(12, 0)); $this->maintenance = CustomerJobModel::factory()->create([ 'name' => 'Somen ylläpito', 'customer_id' => CustomerModel::factory()->company()->create(['name' => 'Kahvila Oy'])->id, 'status' => JobStatus::InProduction, 'payment_basis' => 'monthly_fee', 'monthly_fee_cents' => 39000, 'starts_on' => '2026-09-10', ]); }); /** * Creates a billing material whose billing month is the given month, with the monthly fee jobs on it. */ function createMonthlyMaterial(string $period): void { Livewire::test('billing::index')->call('openDraftNow'); $exportId = (int) BillingExportModel::query()->where('status', ExportStatus::Draft)->value('id'); Livewire::test('billing::export', ['export' => $exportId]) ->call('savePeriod', $period) ->call('finalize') ->assertSet('errorMessage', ''); } it('lists the billed months with their billing material and the months still to bill', function () { createMonthlyMaterial('2026-10'); $this->travelTo(now()->setDate(2026, 12, 5)); Livewire::test('billing::job-months', ['job' => $this->maintenance->id]) ->assertSeeInOrder(['Laskutetut kuukaudet (2)', '9/2026', 'Aineisto 1', '390,00', '10/2026', 'Aineisto 1', 'Laskutettu yhteensä 780,00']) ->assertSeeInOrder(['Laskuttamatta kuukauteen 12/2026 mennessä', '11/2026', '12/2026']); }); it('shows a job with every month billed and one with none billed', function () { Livewire::test('billing::job-months', ['job' => $this->maintenance->id]) ->assertSee('Mitään kuukautta ei ole vielä laskutettu.') ->assertSeeInOrder(['9/2026', '10/2026', '11/2026']); createMonthlyMaterial('2026-11'); Livewire::test('billing::job-months', ['job' => $this->maintenance->id]) ->assertSee('Kaikki kuukaudet tähän kuukauteen asti on laskutettu.'); }); it('links a monthly fee job to its billed periods for management only', function () { $hourly = CustomerJobModel::factory()->create(['payment_basis' => 'hourly']); $link = route('billing.job-months', $this->maintenance->id); $this->get(route('jobs.show', $this->maintenance))->assertSee($link, false)->assertSee('Laskutetut kaudet'); $this->get(route('jobs.show', $hourly))->assertDontSee('Laskutetut kaudet'); $this->actingAs(User::factory()->employee()->create()); $this->get(route('jobs.show', $this->maintenance))->assertOk()->assertDontSee($link, false); $this->get($link)->assertForbidden(); }); it('has no billed periods page for a job that is not billed by a monthly fee', function () { $hourly = CustomerJobModel::factory()->create(['payment_basis' => 'hourly']); $this->get(route('billing.job-months', $hourly))->assertNotFound(); $this->get(route('billing.job-months', 999999))->assertNotFound(); });