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

78 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Page;
use Database\Seeders\ContentSeeder;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\View;
describe('BasketController', function () {
it('can access post /ajax/basket/add', function () {
/** @var \Tests\TestCase $this */
// GIVEN
$this->seed(ContentSeeder::class);
View::share('PageList', Page::getCached()
->mapWithKeys(fn ($page) => [
$page->slug->value() => $page,
]));
Cache::flush();
// WHEN
$response = $this->post('/ajax/basket/add', []);
// THEN
$response->assertStatus(403);
});
it('can access post /ajax/basket/empty', function () {
/** @var \Tests\TestCase $this */
// GIVEN
$this->seed(ContentSeeder::class);
View::share('PageList', Page::getCached()
->mapWithKeys(fn ($page) => [
$page->slug->value() => $page,
]));
Cache::flush();
// WHEN
$response = $this->post('/ajax/basket/empty', []);
// THEN
$response->assertStatus(200);
});
it('can access get /ajax/basket/get', function () {
/** @var \Tests\TestCase $this */
// GIVEN
$this->seed(ContentSeeder::class);
View::share('PageList', Page::getCached()
->mapWithKeys(fn ($page) => [
$page->slug->value() => $page,
]));
Cache::flush();
// WHEN
$response = $this->get('/ajax/basket/get');
// THEN
$response->assertStatus(200);
});
it('can access post /ajax/basket/remove', function () {
/** @var \Tests\TestCase $this */
// GIVEN
$this->seed(ContentSeeder::class);
View::share('PageList', Page::getCached()
->mapWithKeys(fn ($page) => [
$page->slug->value() => $page,
]));
Cache::flush();
// WHEN
$response = $this->post('/ajax/basket/remove', []);
// THEN
$response->assertStatus(302);
});
});