adrema/tests/Feature/Initialize/InitializeActionTest.php

61 lines
1.9 KiB
PHP
Raw Normal View History

2022-09-06 17:51:18 +02:00
<?php
namespace Tests\Feature\Initialize;
use App\Initialize\Actions\InitializeAction;
use Illuminate\Foundation\Testing\DatabaseTransactions;
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;
use Zoomyboy\LaravelNami\Fakes\GroupFake;
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);
}
public function testItValidatesGroupExistance(): void
{
$this->login();
Auth::success(12345, 'secret');
app(GroupFake::class)->fetches(null, []);
2023-02-07 00:43:27 +01:00
$response = $this->post('/initialize', $this->factory()->withCredentials(12345, 'secret')->withGroup(185)->create());
2022-09-06 17:51:18 +02:00
$this->assertErrors(['nami' => 'Gruppierung nicht gefunden.'], $response);
}
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
}
}