51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\App\Http\Controllers\Fo;
|
|
|
|
use App\Models\Page;
|
|
use App\Services\CrmService;
|
|
use Database\Seeders\ContentSeeder;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\View;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('NewsletterController', function () {
|
|
it('can access get /unsubscribe with valid hashcode', function () {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
$crmMock = $this->mock(CrmService::class);
|
|
$crmMock->shouldReceive('unsubscribeCustomer')->andReturn(true);
|
|
$this->seed(ContentSeeder::class);
|
|
View::share('PageList', Page::getCached()
|
|
->mapWithKeys(fn ($page) => [
|
|
$page->slug->value() => $page,
|
|
]));
|
|
Cache::flush();
|
|
$hashcode = Uuid::uuid4()->toString();
|
|
|
|
// WHEN
|
|
$response = $this->get('/unsubscribe?hashcode=' . $hashcode);
|
|
|
|
// 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);
|
|
});
|
|
});
|