Files
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

42 lines
1.9 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
uses(RefreshDatabase::class);
it('makes the earlier assignee with most booked time the assignee and the others members', function () {
[$eero, $aino, $ville] = User::factory()->count(3)->create()->all();
$booked = TaskModel::factory()->create();
$unbooked = TaskModel::factory()->create();
// Roll back this migration and every one after it, so later migrations don't matter.
$steps = count(array_filter(
array_map('basename', glob(database_path('migrations/*.php'))),
fn (string $file): bool => $file >= '2026_11_24_163029_split_task_assignee_and_members.php',
));
$this->artisan('migrate:rollback', ['--step' => $steps])->assertSuccessful();
DB::table('task_assignees')->insert([
['task_id' => $booked->id, 'user_id' => $eero->id],
['task_id' => $booked->id, 'user_id' => $aino->id],
['task_id' => $unbooked->id, 'user_id' => $ville->id],
['task_id' => $unbooked->id, 'user_id' => $aino->id],
]);
DB::table('task_bookings')->insert([
['task_id' => $booked->id, 'user_id' => $eero->id, 'day' => '2026-12-07', 'minutes' => 60],
['task_id' => $booked->id, 'user_id' => $aino->id, 'day' => '2026-12-07', 'minutes' => 240],
]);
$this->artisan('migrate')->assertSuccessful();
expect($booked->refresh()->assignee_user_id)->toBe($aino->id)
->and($unbooked->refresh()->assignee_user_id)->toBe(min($aino->id, $ville->id))
->and(DB::table('task_members')->where('task_id', $booked->id)->pluck('user_id')->all())->toBe([$eero->id])
->and(DB::table('task_members')->where('task_id', $unbooked->id)->pluck('user_id')->all())->toBe([max($aino->id, $ville->id)])
->and(DB::table('task_bookings')->pluck('user_id')->all())->toBe([$aino->id]);
});