seed(RolePermissionSeeder::class); $agent = User::factory()->create(['is_active' => true]); $agent->assignRole('agent'); $other = User::factory()->create(['is_active' => true]); $other->assignRole('agent'); $ownLead = $this->lead($agent, 'مشتری خودی', '09120000001'); $otherLead = $this->lead($other, 'مشتری دیگر', '09120000002'); $this->task($agent, 'کار خودم'); $this->task($other, 'کار کارشناس دیگر'); FollowUp::create(['lead_id' => $ownLead->id, 'user_id' => $agent->id, 'scheduled_at' => now()->addHour(), 'status' => 'pending', 'notes' => 'پیگیری خودم']); FollowUp::create(['lead_id' => $otherLead->id, 'user_id' => $other->id, 'scheduled_at' => now()->addHour(), 'status' => 'pending', 'notes' => 'پیگیری دیگر']); $from = now()->subDay()->toDateString(); $to = now()->addDay()->toDateString(); $this->actingAs($agent)->getJson("/api/calendar/events?from={$from}&to={$to}") ->assertOk() ->assertJsonCount(2, 'events') ->assertJsonFragment(['title' => 'کار خودم']) ->assertJsonFragment(['title' => 'پیگیری خودم']) ->assertJsonMissing(['title' => 'کار کارشناس دیگر']) ->assertJsonMissing(['title' => 'پیگیری دیگر']); $this->actingAs($agent)->getJson("/api/calendar/events?from={$from}&to={$to}&type=task") ->assertOk() ->assertJsonCount(1, 'events') ->assertJsonPath('events.0.type', 'task'); } private function lead(User $agent, string $company, string $phone): Lead { return Lead::create(['first_name' => 'تست', 'last_name' => 'تقویم', 'company' => $company, 'phone' => $phone, 'assigned_to' => $agent->id, 'is_unassigned' => false]); } private function task(User $agent, string $subject): Task { return Task::create([ 'subject' => $subject, 'assigned_to' => $agent->id, 'assigned_by' => $agent->id, 'created_by' => $agent->id, 'priority' => 'normal', 'status' => 'open', 'visibility' => 'private', 'due_at' => now()->addHour(), ]); } }