asApiUser()->get('/api/leads'); $records = json_decode($response->getContent()); $this->assertTrue(count($records->data[0]->data) > 0); } public function test_user_can_load_single_lead() { $leadId = 1; $response = $this->asApiUser()->get("/api/leads/get/$leadId"); $record = json_decode($response->getContent()); $this->assertTrue($record->data->first_name != null); } public function test_user_can_create_single_lead() { $data = [ 'first_name' => 'Test', 'last_name' => 'Test' ]; $response = $this->asApiUser()->post("/api/leads/create", $data); $record = json_decode($response->getContent()); $this->assertTrue($record->data->first_name != null); } public function test_user_can_update_single_lead() { $leadId = 1; $response = $this->asApiUser()->get("/api/leads/get/$leadId"); $record = json_decode($response->getContent()); $this->assertTrue($record->data->first_name != null); $object = $record->data; $object->first_name = "Mike"; $response = $this->asApiUser()->post("api/leads/update/$leadId", [ 'first_name' => 'Mike', 'last_name' => 'Zoltant' ]); $record = json_decode($response->getContent()); $this->assertTrue($record->data->first_name == 'Mike'); } public function test_user_can_delete_single_lead() { $leadId = rand(0, 30); $data = [ 'force_delete' => 1 ]; $response = $this->asApiUser()->delete("api/leads/delete/$leadId", $data); $record = json_decode($response->getContent()); $this->assertTrue($record->status); } public function test_select_all_matching_leads_returns_filtered_ids() { $this->withoutMiddleware(\App\Http\Middleware\VerifyCsrfToken::class); // The endpoint belongs to the web listing: it needs a logged in user // with the browse permission and the current company in the session. $user = \Modules\Platform\User\Entities\User::query() ->orderBy('id') ->get() ->first(function ($user) { return $user->hasPermissionTo('leads.browse'); }); if (!$user) { $this->markTestSkipped("No user with 'leads.browse' permission found."); } Auth::login($user); $company = \Modules\Platform\Companies\Entities\Company::find($user->company_id); $response = $this->withSession(['currentCompany' => $company]) ->post('/leads/leads/selection-ids', [ 'rules' => '', 'search' => ['value' => '', 'regex' => false], 'columns' => [], ]); $this->assertSame(200, $response->getStatusCode()); $payload = json_decode($response->getContent(), true); $this->assertSame('success', $payload['type'] ?? null); $this->assertIsArray($payload['ids'] ?? null); } }