seed([RoleSeeder::class, SamplePsgcSeeder::class, SampleDropOffPointsSeeder::class]); } public function test_scan_without_trip_assigns_team_id() { $scanner = User::factory()->create(['role' => User::ROLE_SCANNER, 'status' => 'active']); $team = CollectionTeam::create([ 'tenant_id' => 1, 'name' => 'Test Team', 'scanner_id' => $scanner->id, 'status' => CollectionTeam::STATUS_ACTIVE, ]); $dop = DropOffPoint::first(); $batch = app(BatchGenerator::class)->generate(1, QrCodeBatch::PURPOSE_FREE); $code = $batch->codes->first(); $code->forceFill([ 'assigned_to_household_id' => \App\Models\Household::factory()->create(['barangay_id' => $dop->barangay_id])->id, 'status' => 'active', ])->save(); Sanctum::actingAs($scanner); $response = $this->postJson('/api/v1/scanner/scan', [ 'serial' => $code->serial, 'drop_off_point_id' => $dop->id, 'lat' => $dop->coordinates->latitude, 'lng' => $dop->coordinates->longitude, 'weight_kg' => 5, ]); $response->assertOk(); $this->assertDatabaseHas('collection_logs', [ 'qr_code_id' => $code->id, 'team_id' => $team->id, 'trip_id' => null, ]); } }