2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\Page;
|
|
|
|
|
use App\Services\CrmService;
|
|
|
|
|
use Database\Seeders\ContentSeeder;
|
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
use Illuminate\Support\Facades\View;
|
2026-10-02 12:14:48 +02:00
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
|
use Shared\ValueObjects\CrmHashcode;
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
describe('CustomerController', function () {
|
|
|
|
|
it('can access get /compte', function () {
|
|
|
|
|
// GIVEN
|
2026-10-02 12:14:48 +02:00
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
$this->seed(ContentSeeder::class);
|
|
|
|
|
View::share('PageList', Page::getCached()
|
|
|
|
|
->mapWithKeys(fn ($page) => [
|
|
|
|
|
$page->slug->value() => $page,
|
|
|
|
|
]));
|
|
|
|
|
Cache::flush();
|
|
|
|
|
$user = \Mockery::mock(Customer::class)->makePartial();
|
|
|
|
|
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
|
2026-10-02 12:14:48 +02:00
|
|
|
$user->hashcode = new CrmHashcode(Uuid::uuid4());
|
2026-06-14 21:32:07 +02:00
|
|
|
$user->shouldReceive('getAuthPassword')->andReturn('dummy');
|
|
|
|
|
$this->actingAs($user, 'frontend');
|
|
|
|
|
$crmMock = \Mockery::mock(CrmService::class)->makePartial();
|
|
|
|
|
$crmMock->shouldReceive('getCustomerFromHashCode')->andReturn(null);
|
|
|
|
|
App::instance(CrmService::class, $crmMock);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/compte');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can access get /compte/profil', function () {
|
|
|
|
|
// GIVEN
|
2026-10-02 12:14:48 +02:00
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
$this->seed(ContentSeeder::class);
|
|
|
|
|
View::share('PageList', Page::getCached()
|
|
|
|
|
->mapWithKeys(fn ($page) => [
|
|
|
|
|
$page->slug->value() => $page,
|
|
|
|
|
]));
|
|
|
|
|
Cache::flush();
|
|
|
|
|
$user = \Mockery::mock(Customer::class)->makePartial();
|
|
|
|
|
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
|
2026-10-02 12:14:48 +02:00
|
|
|
$user->hashcode = new CrmHashcode(Uuid::uuid4());
|
2026-06-14 21:32:07 +02:00
|
|
|
$user->shouldReceive('getAuthPassword')->andReturn('dummy');
|
|
|
|
|
$this->actingAs($user, 'frontend');
|
|
|
|
|
$crmMock = \Mockery::mock(CrmService::class)->makePartial();
|
|
|
|
|
$crmMock->shouldReceive('getCustomerFromHashCode')->andReturn(null);
|
|
|
|
|
App::instance(CrmService::class, $crmMock);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/compte/profil');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can access post /compte/profil', function () {
|
|
|
|
|
// GIVEN
|
2026-10-02 12:14:48 +02:00
|
|
|
/** @var \Tests\TestCase $this */
|
2026-06-14 21:32:07 +02:00
|
|
|
$this->seed(ContentSeeder::class);
|
|
|
|
|
View::share('PageList', Page::getCached()
|
|
|
|
|
->mapWithKeys(fn ($page) => [
|
|
|
|
|
$page->slug->value() => $page,
|
|
|
|
|
]));
|
|
|
|
|
Cache::flush();
|
|
|
|
|
$user = \Mockery::mock(Customer::class)->makePartial();
|
|
|
|
|
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
|
2026-10-02 12:14:48 +02:00
|
|
|
$user->hashcode = new CrmHashcode(Uuid::uuid4());
|
2026-06-14 21:32:07 +02:00
|
|
|
$user->shouldReceive('getAuthPassword')->andReturn('dummy');
|
|
|
|
|
$this->actingAs($user, 'frontend');
|
|
|
|
|
$crmMock = \Mockery::mock(CrmService::class)->makePartial();
|
|
|
|
|
$crmMock->shouldReceive('getCustomerFromHashCode')->andReturn(null);
|
|
|
|
|
App::instance(CrmService::class, $crmMock);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->post('/compte/profil', []);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertStatus(302);
|
|
|
|
|
});
|
|
|
|
|
});
|