ldc-cocotte/tests/Feature/App/Http/Controllers/Fo/NewsletterControllerTest.php

52 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace Tests\Feature\App\Http\Controllers\Fo;
2026-06-14 21:32:07 +02:00
use App\Models\Page;
use App\Services\CrmService;
2026-06-14 21:32:07 +02:00
use Database\Seeders\ContentSeeder;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\View;
use Shared\Helpers\UuidHelper;
2026-06-14 21:32:07 +02:00
describe('NewsletterController', function () {
it('can access get /unsubscribe with valid hashcode', function () {
2026-06-14 21:32:07 +02:00
// GIVEN
/** @var \Tests\TestCase $this */
$crmMock = $this->mock(CrmService::class);
$crmMock->shouldReceive('unsubscribeCustomer')->andReturn(true);
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();
$hashcode = UuidHelper::v4()->toString();
2026-06-14 21:32:07 +02:00
// WHEN
$response = $this->get('/unsubscribe?hashcode=' . $hashcode);
2026-06-14 21:32:07 +02:00
// THEN
$response->assertStatus(200);
});
it('redirects when hashcode is missing', function () {
// GIVEN
/** @var \Tests\TestCase $this */
$this->seed(ContentSeeder::class);
View::share('PageList', Page::getCached()
->mapWithKeys(fn ($page) => [
$page->slug->value() => $page,
]));
Cache::flush();
// WHEN
$response = $this->get('/unsubscribe');
// THEN
$response->assertStatus(302);
});
2026-06-14 21:32:07 +02:00
});