CI / Build Plugin Zip (pull_request) Has been skipped
CI / Tests (PHP 8.2) (pull_request) Successful in 45s
CI / PHPStan (pull_request) Successful in 2m48s
CI / Tests (PHP 8.1) (pull_request) Successful in 41s
CI / No Debug Code (pull_request) Failing after 2s
CI / Coding Standards (pull_request) Successful in 52s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m36s
Availability windows were stored and served as a single bookable row, so a 9:00 AM-4:00 PM window showed to students as one giant slot and booking it consumed the whole day; past and multi-day windows also leaked into the booking page as nonsense entries. - Split windows into consecutive lesson-length slots on save (REST and admin form); each chunk is independently bookable and weekly recurrence creates a series per chunk so "reserve this time weekly" holds the same hour each week - Reject windows spanning multiple days or shorter than the lesson length (400 invalid_window) - Never return slots whose start has passed from GET /availability - Migrate pre-split rows: Plugin::boot re-runs the Installer on version change and AvailabilityRepository::splitOversizedWindows() rewrites unbooked same-day oversized windows in place - Display all times in 12-hour AM/PM form (booking page, wp-admin lists, editor previews) - Add a List | Week view toggle to the student booking page and the instructor availability page, with previous/next-week navigation honouring the site's start_of_week option (new WeekCalendar helper) Co-Authored-By: Claude Fable 5 <[email protected]>
116 lines
4.0 KiB
PHP
116 lines
4.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Availability;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use Mockery;
|
|
use Unsupervised\Schedular\Availability\AvailabilityEndpoint;
|
|
use Unsupervised\Schedular\Availability\AvailabilityRepository;
|
|
use Unsupervised\Schedular\Availability\AvailabilitySlot;
|
|
use Unsupervised\Schedular\Offering\OfferingRepository;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class AvailabilityEndpointTest extends TestCase
|
|
{
|
|
private AvailabilityRepository $repository;
|
|
private OfferingRepository $offerings;
|
|
private AvailabilityEndpoint $endpoint;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Functions\when('absint')->alias(static fn ($v): int => abs((int) $v));
|
|
Functions\when('get_current_user_id')->justReturn(5);
|
|
|
|
$this->repository = Mockery::mock(AvailabilityRepository::class);
|
|
$this->offerings = Mockery::mock(OfferingRepository::class);
|
|
$this->endpoint = new AvailabilityEndpoint($this->repository, $this->offerings);
|
|
}
|
|
|
|
public function testCreateRejectsWindowSpanningMultipleDays(): void
|
|
{
|
|
$this->repository->shouldNotReceive('createFromWindow');
|
|
|
|
$request = new \WP_REST_Request([
|
|
'start_dt' => '2026-06-01 19:52:00',
|
|
'end_dt' => '2026-06-30 19:52:00',
|
|
'duration_minutes' => 60,
|
|
]);
|
|
|
|
$result = $this->endpoint->create($request);
|
|
|
|
self::assertInstanceOf(\WP_Error::class, $result);
|
|
self::assertSame('invalid_window', $result->get_error_code());
|
|
}
|
|
|
|
public function testCreateRejectsWindowShorterThanLessonLength(): void
|
|
{
|
|
$this->repository->shouldNotReceive('createFromWindow');
|
|
|
|
$request = new \WP_REST_Request([
|
|
'start_dt' => '2026-07-06 09:00:00',
|
|
'end_dt' => '2026-07-06 09:30:00',
|
|
'duration_minutes' => 60,
|
|
]);
|
|
|
|
$result = $this->endpoint->create($request);
|
|
|
|
self::assertInstanceOf(\WP_Error::class, $result);
|
|
self::assertSame('invalid_window', $result->get_error_code());
|
|
}
|
|
|
|
public function testCreateStoresWindowAsLessonLengthSlots(): void
|
|
{
|
|
$this->repository->shouldReceive('createFromWindow')
|
|
->once()
|
|
->with(
|
|
Mockery::on(static function (AvailabilitySlot $window): bool {
|
|
return $window->instructorId === 5
|
|
&& $window->startDt === '2026-07-06 09:00:00'
|
|
&& $window->endDt === '2026-07-06 16:00:00'
|
|
&& $window->durationMinutes === 60;
|
|
}),
|
|
false,
|
|
1
|
|
)
|
|
->andReturn([1, 2, 3, 4, 5, 6, 7]);
|
|
|
|
$request = new \WP_REST_Request([
|
|
'start_dt' => '2026-07-06 09:00:00',
|
|
'end_dt' => '2026-07-06 16:00:00',
|
|
'duration_minutes' => 60,
|
|
'recurrence' => 'single',
|
|
'weeks' => 1,
|
|
]);
|
|
|
|
$result = $this->endpoint->create($request);
|
|
|
|
self::assertInstanceOf(\WP_REST_Response::class, $result);
|
|
self::assertSame(201, $result->get_status());
|
|
self::assertSame(['ids' => [1, 2, 3, 4, 5, 6, 7]], $result->get_data());
|
|
}
|
|
|
|
public function testCreateWeeklyPassesRecurrenceThrough(): void
|
|
{
|
|
$this->repository->shouldReceive('createFromWindow')
|
|
->once()
|
|
->with(Mockery::type(AvailabilitySlot::class), true, 4)
|
|
->andReturn([1, 2, 3, 4]);
|
|
|
|
$request = new \WP_REST_Request([
|
|
'start_dt' => '2026-07-06 09:00:00',
|
|
'end_dt' => '2026-07-06 10:00:00',
|
|
'duration_minutes' => 60,
|
|
'recurrence' => 'weekly',
|
|
'weeks' => 4,
|
|
]);
|
|
|
|
$result = $this->endpoint->create($request);
|
|
|
|
self::assertInstanceOf(\WP_REST_Response::class, $result);
|
|
self::assertSame(['ids' => [1, 2, 3, 4]], $result->get_data());
|
|
}
|
|
}
|