Add lesson booking registration flow (offering, questions, policies)
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

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>
This commit is contained in:
2026-06-07 11:25:30 -03:00
parent d0dddd9075
commit 6d163e5d0e
15 changed files with 649 additions and 68 deletions
+34 -2
View File
@@ -34,19 +34,43 @@ class BookingRepositoryTest extends TestCase
Mockery::on(static function (array $data): bool {
return $data['slot_id'] === 10
&& $data['student_id'] === 5
&& $data['offering_id'] === 7
&& $data['recurrence'] === Lesson::RECURRENCE_SINGLE
&& $data['status'] === Lesson::STATUS_PENDING;
}),
['%d', '%d', '%d', '%s', '%s', '%s']
['%d', '%d', '%d', '%d', '%s', '%d', '%s', '%d', '%s', '%s']
);
$this->db->insert_id = 77;
$lesson = new Lesson(slotId: 10, studentId: 5, instructorId: 3);
$lesson = new Lesson(slotId: 10, studentId: 5, instructorId: 3, offeringId: 7);
$result = $this->repo->insert($lesson);
self::assertSame(77, $result);
}
public function testInsertSeriesSharesSeriesIdAcrossSlots(): void
{
Functions\when('current_time')->justReturn('2026-04-01 12:00:00');
$ids = [40, 41, 42];
$this->db->shouldReceive('insert')
->times(3)
->andReturnUsing(function () use (&$ids): void {
$this->db->insert_id = array_shift($ids);
});
// The first lesson is back-filled with its own id as the series id.
$this->db->shouldReceive('update')
->once()
->with('wp_us_lessons', ['series_id' => 40], ['id' => 40], ['%d'], ['%d']);
$template = new Lesson(slotId: 0, studentId: 5, instructorId: 3, offeringId: 7);
$result = $this->repo->insertSeries($template, [100, 101, 102]);
self::assertSame([40, 41, 42], $result);
}
public function testFindByIdReturnsNullWhenNotFound(): void
{
$this->db->shouldReceive('prepare')->andReturn('SELECT ...');
@@ -60,9 +84,13 @@ class BookingRepositoryTest extends TestCase
$row = (object) [
'id' => '15',
'slot_id' => '10',
'offering_id' => null,
'student_id' => '5',
'instructor_id' => '3',
'recurrence' => Lesson::RECURRENCE_SINGLE,
'series_id' => null,
'status' => 'pending',
'payment_id' => null,
'notes' => null,
];
@@ -109,9 +137,13 @@ class BookingRepositoryTest extends TestCase
$row = (object) [
'id' => '1',
'slot_id' => '2',
'offering_id' => null,
'student_id' => '5',
'instructor_id' => '3',
'recurrence' => Lesson::RECURRENCE_SINGLE,
'series_id' => null,
'status' => 'pending',
'payment_id' => null,
'notes' => null,
];
+22 -11
View File
@@ -28,41 +28,52 @@ class LessonTest extends TestCase
$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(10, $lesson->slotId);
self::assertSame(20, $lesson->studentId);
self::assertSame(30, $lesson->instructorId);
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);
self::assertSame('Bring your guitar.', $lesson->notes);
}
public function testToArrayContainsExpectedKeys(): void
{
$lesson = new Lesson(1, 2, 3, Lesson::STATUS_PENDING, 'Note', 5);
$lesson = new Lesson(slotId: 1, studentId: 2, instructorId: 3, notes: 'Note', id: 5);
$arr = $lesson->toArray();
self::assertArrayHasKey('id', $arr);
self::assertArrayHasKey('slot_id', $arr);
self::assertArrayHasKey('student_id', $arr);
self::assertArrayHasKey('instructor_id', $arr);
self::assertArrayHasKey('status', $arr);
self::assertArrayHasKey('notes', $arr);
foreach (['id', 'slot_id', 'offering_id', 'student_id', 'instructor_id', 'recurrence', 'series_id', 'status', 'payment_id', 'notes'] as $key) {
self::assertArrayHasKey($key, $arr);
}
}
}