54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Tests\Feature;
|
||
|
|
|
||
|
|
use App\Models\Investigation;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
class SearchTest extends TestCase
|
||
|
|
{
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_finds_accessible_investigation_by_name(): void
|
||
|
|
{
|
||
|
|
$user = User::factory()->create();
|
||
|
|
$mine = Investigation::factory()->for($user, 'owner')->create(['name' => 'Operation Nightingale']);
|
||
|
|
$other = Investigation::factory()->create(['name' => 'Operation Nightowl']);
|
||
|
|
|
||
|
|
$response = $this->actingAs($user)->get(route('search.index', ['q' => 'Nightingale']));
|
||
|
|
|
||
|
|
$response->assertOk();
|
||
|
|
$response->assertSee('Operation Nightingale');
|
||
|
|
$response->assertDontSee('Operation Nightowl');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_finds_target_by_value_only_within_accessible_investigations(): void
|
||
|
|
{
|
||
|
|
$user = User::factory()->create();
|
||
|
|
$mine = Investigation::factory()->for($user, 'owner')->create();
|
||
|
|
$mine->targets()->create(['type' => 'username', 'value' => 'unique_search_handle', 'created_by' => $user->id]);
|
||
|
|
|
||
|
|
$stranger = User::factory()->create();
|
||
|
|
$notMine = Investigation::factory()->for($stranger, 'owner')->create();
|
||
|
|
$notMine->targets()->create(['type' => 'username', 'value' => 'unique_search_handle_2', 'created_by' => $stranger->id]);
|
||
|
|
|
||
|
|
$response = $this->actingAs($user)->get(route('search.index', ['q' => 'unique_search_handle']));
|
||
|
|
|
||
|
|
$response->assertOk();
|
||
|
|
$response->assertSee('unique_search_handle', false);
|
||
|
|
$response->assertDontSee('unique_search_handle_2');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_empty_query_shows_no_results_section(): void
|
||
|
|
{
|
||
|
|
$user = User::factory()->create();
|
||
|
|
|
||
|
|
$response = $this->actingAs($user)->get(route('search.index'));
|
||
|
|
|
||
|
|
$response->assertOk();
|
||
|
|
$response->assertDontSee(__('Investigations') . ' (');
|
||
|
|
}
|
||
|
|
}
|