70 lines
2.7 KiB
PHP
70 lines
2.7 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
use App\Models\Classe;
|
|||
|
|
use App\Models\Cours;
|
|||
|
|
use App\Models\Eleve;
|
|||
|
|
use App\Models\Lab;
|
|||
|
|
use App\Services\Recherche\IndexRecherche;
|
|||
|
|
use Illuminate\Support\Facades\Http;
|
|||
|
|
|
|||
|
|
test('la recherche affiche un message d’indisponibilité tant qu’Elasticsearch n’est pas configuré', function () {
|
|||
|
|
$eleve = Eleve::factory()->create();
|
|||
|
|
|
|||
|
|
eleve($this, $eleve)->get(route('recherche', ['q' => 'routage']))
|
|||
|
|
->assertOk()
|
|||
|
|
->assertSee('pas disponible');
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test('un prof et un élève peuvent tous les deux utiliser la recherche', function () {
|
|||
|
|
$eleve = Eleve::factory()->create();
|
|||
|
|
eleve($this, $eleve)->get(route('recherche'))->assertOk();
|
|||
|
|
|
|||
|
|
$classe = Classe::factory()->create();
|
|||
|
|
commeProf($this, $classe->prof)->get(route('recherche'))->assertOk();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test('un résultat de type cours renvoie vers la page du cours, avec l’extrait surligné', function () {
|
|||
|
|
config(['elasticsearch.hote' => '127.0.0.1']);
|
|||
|
|
Cours::create(['identifiant' => '08-deux-lan-routeur', 'titre' => 'Deux LAN et un routeur', 'contenu_markdown' => 'Le routage statique...']);
|
|||
|
|
|
|||
|
|
Http::fake([
|
|||
|
|
'*/_search' => Http::response([
|
|||
|
|
'hits' => ['hits' => [
|
|||
|
|
[
|
|||
|
|
'_source' => ['type' => 'cours', 'identifiant' => '08-deux-lan-routeur', 'titre' => 'Deux LAN et un routeur', 'contenu' => 'Le routage statique...'],
|
|||
|
|
'highlight' => ['contenu' => ['Le <em>routage</em> statique...']],
|
|||
|
|
],
|
|||
|
|
]],
|
|||
|
|
]),
|
|||
|
|
]);
|
|||
|
|
|
|||
|
|
$eleve = Eleve::factory()->create();
|
|||
|
|
|
|||
|
|
eleve($this, $eleve)->get(route('recherche', ['q' => 'routage']))
|
|||
|
|
->assertOk()
|
|||
|
|
->assertSee('Deux LAN et un routeur')
|
|||
|
|
->assertSee(route('mes-cours.show', '08-deux-lan-routeur'), false)
|
|||
|
|
->assertSee('<em>routage</em>', false);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test('reconstruire l’index envoie un document par lab et par cours', function () {
|
|||
|
|
config(['elasticsearch.hote' => '127.0.0.1']);
|
|||
|
|
Http::fake();
|
|||
|
|
Lab::factory()->create(['identifiant' => 'lab-test', 'titre' => 'Lab de test', 'competences' => ['routage']]);
|
|||
|
|
Cours::create(['identifiant' => 'cours-test', 'titre' => 'Cours de test', 'contenu_markdown' => '# Titre']);
|
|||
|
|
|
|||
|
|
IndexRecherche::reconstruire();
|
|||
|
|
|
|||
|
|
Http::assertSent(fn ($r) => $r->method() === 'DELETE' && str_ends_with($r->url(), '/paillasse_catalogue'));
|
|||
|
|
Http::assertSent(fn ($r) => $r->method() === 'PUT' && str_ends_with($r->url(), '/_doc/lab-lab-test'));
|
|||
|
|
Http::assertSent(fn ($r) => $r->method() === 'PUT' && str_ends_with($r->url(), '/_doc/cours-cours-test'));
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test('sans Elasticsearch configuré, reconstruire l’index ne fait aucun appel réseau', function () {
|
|||
|
|
Http::fake();
|
|||
|
|
|
|||
|
|
IndexRecherche::reconstruire();
|
|||
|
|
|
|||
|
|
Http::assertNothingSent();
|
|||
|
|
});
|