ldc-cocotte/tests/Feature/App/Http/Controllers/Fo/NewsletterControllerTest.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 Shared\Helpers\UuidHelper;
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 = UuidHelper::v4()->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);
});
});