2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:26:35 +01:00
|
|
|
namespace Tests\Feature\App\Http\Controllers\Fo\Ajax;
|
|
|
|
|
|
2026-11-15 20:11:28 +01:00
|
|
|
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;
|
2026-11-15 20:11:28 +01:00
|
|
|
use App\Models\Shop;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Database\Seeders\ContentSeeder;
|
2026-11-15 20:11:28 +01:00
|
|
|
use Domain\Models\ValueObjects\Email;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
use Illuminate\Support\Facades\View;
|
2026-11-17 12:15:39 +01:00
|
|
|
use Shared\Helpers\UuidHelper;
|
2026-11-15 20:11:28 +01:00
|
|
|
use Shared\ValueObjects\CrmHashcode;
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-11-15 20:11:28 +01:00
|
|
|
describe('PickupController', function (): void {
|
|
|
|
|
it('redirects unauthenticated guest requesting pickup timeslots to login', function (): void {
|
2026-10-03 10:07:30 +02:00
|
|
|
/** @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');
|
|
|
|
|
|
2026-11-15 20:11:28 +01:00
|
|
|
// 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');
|
2026-11-17 12:15:39 +01:00
|
|
|
$customer->hashcode = new CrmHashcode(UuidHelper::v4());
|
2026-11-15 20:11:28 +01:00
|
|
|
$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);
|
|
|
|
|
});
|
2026-11-15 20:11:28 +01:00
|
|
|
|
|
|
|
|
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');
|
2026-11-17 12:15:39 +01:00
|
|
|
$customer->hashcode = new CrmHashcode(UuidHelper::v4());
|
2026-11-15 20:11:28 +01:00
|
|
|
$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
|
|
|
});
|