2022-09-06 17:51:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Initialize;
|
|
|
|
|
|
|
|
use App\Initialize\Actions\InitializeAction;
|
2023-05-08 15:11:16 +02:00
|
|
|
use App\Setting\NamiSettings;
|
2022-09-06 17:51:18 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2023-05-08 15:11:16 +02:00
|
|
|
use Illuminate\Support\Facades\Queue;
|
2023-02-07 00:43:27 +01:00
|
|
|
use Tests\RequestFactories\InitializeRequestFactory;
|
2022-09-06 17:51:18 +02:00
|
|
|
use Tests\TestCase;
|
|
|
|
use Zoomyboy\LaravelNami\Authentication\Auth;
|
|
|
|
|
2023-02-07 00:43:27 +01:00
|
|
|
class InitializeActionTest extends TestCase
|
2022-09-06 17:51:18 +02:00
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2023-02-07 00:43:27 +01:00
|
|
|
public function testItCannotInitializeWhenNotLoggedIn(): void
|
|
|
|
{
|
|
|
|
InitializeAction::partialMock()->shouldReceive('handle')->never();
|
|
|
|
|
|
|
|
$response = $this->post('/initialize', $this->factory()->create());
|
|
|
|
|
|
|
|
$response->assertRedirect('/login');
|
|
|
|
}
|
|
|
|
|
2022-09-06 17:51:18 +02:00
|
|
|
public function testItValidatesSetupInfo(): void
|
|
|
|
{
|
|
|
|
$this->login();
|
|
|
|
|
2023-02-07 00:43:27 +01:00
|
|
|
$response = $this->post('/initialize', $this->factory()->invalid()->create());
|
2022-09-06 17:51:18 +02:00
|
|
|
|
|
|
|
$this->assertErrors(['password' => 'Passwort ist erforderlich.'], $response);
|
|
|
|
$this->assertErrors(['mglnr' => 'Mitgliedsnummer ist erforderlich.'], $response);
|
|
|
|
$this->assertErrors(['group_id' => 'Gruppierungsnr ist erforderlich.'], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItValidatesLogin(): void
|
|
|
|
{
|
|
|
|
$this->login();
|
|
|
|
|
2023-02-07 00:43:27 +01:00
|
|
|
$response = $this->post('/initialize', $this->factory()->withCredentials(12345, 'secret')->create());
|
2022-09-06 17:51:18 +02:00
|
|
|
|
|
|
|
$this->assertErrors(['nami' => 'NaMi Login fehlgeschlagen.'], $response);
|
|
|
|
}
|
|
|
|
|
2023-05-08 15:11:16 +02:00
|
|
|
public function testItSetsSettings(): void
|
2022-09-06 17:51:18 +02:00
|
|
|
{
|
2023-05-08 15:11:16 +02:00
|
|
|
Queue::fake();
|
|
|
|
Auth::success(100222, 'secret');
|
2022-09-06 17:51:18 +02:00
|
|
|
$this->login();
|
|
|
|
|
2023-05-08 15:11:16 +02:00
|
|
|
$response = $this->post('/initialize', $this->factory()->withCredentials(100222, 'secret')->withGroup(77)->withParams(['gruppierung1Id' => '66777'])->create());
|
2022-09-06 17:51:18 +02:00
|
|
|
|
2023-05-08 15:11:16 +02:00
|
|
|
$response->assertRedirect('/');
|
|
|
|
$settings = app(NamiSettings::class);
|
|
|
|
$this->assertEquals(100222, $settings->mglnr);
|
|
|
|
$this->assertEquals('secret', $settings->password);
|
|
|
|
$this->assertEquals(77, $settings->default_group_id);
|
|
|
|
$this->assertEquals('66777', $settings->search_params['gruppierung1Id']);
|
2022-09-06 17:51:18 +02:00
|
|
|
}
|
|
|
|
|
2023-02-07 00:43:27 +01:00
|
|
|
private function factory(): InitializeRequestFactory
|
2022-09-06 17:51:18 +02:00
|
|
|
{
|
2023-02-07 00:43:27 +01:00
|
|
|
return InitializeRequestFactory::new();
|
2022-09-06 17:51:18 +02:00
|
|
|
}
|
|
|
|
}
|