Files
unsupervised-scheduler/tests/Unit/Booking/LessonTest.php
T
thatguygriff 6d163e5d0e
CI / Coding Standards (pull_request) Successful in 1m51s
CI / PHPStan (pull_request) Successful in 2m17s
CI / Tests (PHP 8.1) (pull_request) Successful in 2m24s
CI / No Debug Code (pull_request) Successful in 2s
CI / Tests (PHP 8.2) (pull_request) Successful in 42s
CI / Tests (PHP 8.3) (pull_request) Successful in 47s
CI / Build Plugin Zip (pull_request) Has been skipped
Add lesson booking registration flow (offering, questions, policies)
Implements #3: students register for a private lesson by picking a slot,
answering the offering's intake questions, and accepting booking-scoped
policies. Payment is a clean seam for #7 (lessons land pending; payment_id
null; instructor confirms via PATCH /bookings/{id}/status).

- Schema: us_lessons += offering_id, recurrence, series_id, payment_id.
- Lesson: new fields + recurrence constants.
- BookingRepository::insertSeries() builds a weekly series sharing a
  series_id; AvailabilityRepository::findUnbookedInGroup() reserves a group.
- RegistrationGate (src/Registration/): validate + record intake answers and
  booking-scoped policy acceptances. Reused by group enrolment (#4).
- BookingEndpoint::book(): offering_id, recurrence, answers,
  accepted_policy_version_ids; single or weekly; records answers/acceptances
  (type lesson).
- GET /policies?scope=booking filter.
- Front-end booking.js: slot -> questions + policies -> submit.
- Wiring: RegistrationGate built in Plugin, passed via RestRegistrar.
- Test-only WP_Error stub in tests/bootstrap.php for gate testing.

Refs #3

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 11:25:30 -03:00

80 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Tests\Unit\Booking;
use Unsupervised\Schedular\Booking\Lesson;
use Unsupervised\Schedular\Tests\Unit\TestCase;
class LessonTest extends TestCase
{
public function testStatusConstants(): void
{
self::assertSame('pending', Lesson::STATUS_PENDING);
self::assertSame('confirmed', Lesson::STATUS_CONFIRMED);
self::assertSame('cancelled', Lesson::STATUS_CANCELLED);
}
public function testValidStatusesContainsAllThree(): void
{
self::assertContains(Lesson::STATUS_PENDING, Lesson::VALID_STATUSES);
self::assertContains(Lesson::STATUS_CONFIRMED, Lesson::VALID_STATUSES);
self::assertContains(Lesson::STATUS_CANCELLED, Lesson::VALID_STATUSES);
self::assertCount(3, Lesson::VALID_STATUSES);
}
public function testConstructorDefaults(): void
{
$lesson = new Lesson(slotId: 1, studentId: 2, instructorId: 3);
self::assertSame(Lesson::STATUS_PENDING, $lesson->status);
self::assertNull($lesson->offeringId);
self::assertSame(Lesson::RECURRENCE_SINGLE, $lesson->recurrence);
self::assertNull($lesson->seriesId);
self::assertNull($lesson->paymentId);
self::assertNull($lesson->notes);
self::assertNull($lesson->id);
}
public function testRecurrenceConstants(): void
{
self::assertContains(Lesson::RECURRENCE_SINGLE, Lesson::VALID_RECURRENCES);
self::assertContains(Lesson::RECURRENCE_WEEKLY, Lesson::VALID_RECURRENCES);
}
public function testFromRowMapsCorrectly(): void
{
$row = (object) [
'id' => '99',
'slot_id' => '10',
'offering_id' => '7',
'student_id' => '20',
'instructor_id' => '30',
'recurrence' => Lesson::RECURRENCE_WEEKLY,
'series_id' => '99',
'status' => 'confirmed',
'payment_id' => null,
'notes' => 'Bring your guitar.',
];
$lesson = Lesson::fromRow($row);
self::assertSame(99, $lesson->id);
self::assertSame(7, $lesson->offeringId);
self::assertSame(Lesson::RECURRENCE_WEEKLY, $lesson->recurrence);
self::assertSame(99, $lesson->seriesId);
self::assertNull($lesson->paymentId);
self::assertSame('confirmed', $lesson->status);
}
public function testToArrayContainsExpectedKeys(): void
{
$lesson = new Lesson(slotId: 1, studentId: 2, instructorId: 3, notes: 'Note', id: 5);
$arr = $lesson->toArray();
foreach (['id', 'slot_id', 'offering_id', 'student_id', 'instructor_id', 'recurrence', 'series_id', 'status', 'payment_id', 'notes'] as $key) {
self::assertArrayHasKey($key, $arr);
}
}
}