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

92 lines
2.9 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\Ajax;
use App\Http\Middleware\CustomerIsEmployed;
use App\Http\Middleware\EnsureCustomerEmailIsVerified;
use App\Models\Customer;
2026-06-14 21:32:07 +02:00
use App\Models\Page;
use App\Models\Shop;
2026-06-14 21:32:07 +02:00
use Database\Seeders\ContentSeeder;
use Domain\Models\ValueObjects\Email;
2026-06-14 21:32:07 +02:00
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\View;
use Shared\Helpers\UuidHelper;
use Shared\ValueObjects\CrmHashcode;
2026-06-14 21:32:07 +02:00
describe('PickupController', function (): void {
it('redirects unauthenticated guest requesting pickup timeslots to login', function (): void {
/** @var \Tests\TestCase $this */
2026-06-14 21:32:07 +02:00
// GIVEN
$this->seed(ContentSeeder::class);
View::share('PageList', Page::getCached()
->mapWithKeys(fn ($page) => [
$page->slug->value() => $page,
]));
Cache::flush();
// WHEN
$response = $this->get('/ajax/shops/1/pickup-timeslots');
// THEN
$response->assertRedirectToRoute('fo.auth.connexion');
});
it('returns 404 for unknown shop when authenticated active employee requests pickup timeslots', function (): void {
/** @var \Tests\TestCase $this */
// GIVEN
$this->seed(ContentSeeder::class);
View::share('PageList', Page::getCached()
->mapWithKeys(fn ($page) => [
$page->slug->value() => $page,
]));
Cache::flush();
$customer = new Customer();
$customer->email = new Email('employee@example.com');
$customer->hashcode = new CrmHashcode(UuidHelper::v4());
$customer->save();
$this->actingAs($customer, 'frontend');
$this->withoutMiddleware([
EnsureCustomerEmailIsVerified::class,
CustomerIsEmployed::class,
]);
// WHEN
$response = $this->get('/ajax/shops/99999/pickup-timeslots');
2026-06-14 21:32:07 +02:00
// THEN
$response->assertStatus(404);
});
it('returns pickup timeslots for an existing shop when authenticated active employee', function (): void {
/** @var \Tests\TestCase $this */
// GIVEN
$this->seed(ContentSeeder::class);
View::share('PageList', Page::getCached()
->mapWithKeys(fn ($page) => [
$page->slug->value() => $page,
]));
Cache::flush();
$shop = Shop::factory()->create();
$customer = new Customer();
$customer->email = new Email('employee2@example.com');
$customer->hashcode = new CrmHashcode(UuidHelper::v4());
$customer->save();
$this->actingAs($customer, 'frontend');
$this->withoutMiddleware([
EnsureCustomerEmailIsVerified::class,
CustomerIsEmployed::class,
]);
// WHEN
$response = $this->get(route('ajax.shops.pickup-timeslots', $shop));
// THEN
$response->assertStatus(200);
});
2026-06-14 21:32:07 +02:00
});