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
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:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular\Tests\Unit\Registration;
|
||||
|
||||
use Mockery;
|
||||
use Unsupervised\Schedular\Policy\AcceptanceRepository;
|
||||
use Unsupervised\Schedular\Policy\Policy;
|
||||
use Unsupervised\Schedular\Policy\PolicyAcceptance;
|
||||
use Unsupervised\Schedular\Policy\PolicyRepository;
|
||||
use Unsupervised\Schedular\Policy\PolicyVersion;
|
||||
use Unsupervised\Schedular\Policy\PolicyVersionRepository;
|
||||
use Unsupervised\Schedular\Registration\Answer;
|
||||
use Unsupervised\Schedular\Registration\AnswerRepository;
|
||||
use Unsupervised\Schedular\Registration\Question;
|
||||
use Unsupervised\Schedular\Registration\QuestionRepository;
|
||||
use Unsupervised\Schedular\Registration\RegistrationGate;
|
||||
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
||||
|
||||
class RegistrationGateTest extends TestCase
|
||||
{
|
||||
private QuestionRepository $questions;
|
||||
private AnswerRepository $answers;
|
||||
private PolicyRepository $policies;
|
||||
private PolicyVersionRepository $versions;
|
||||
private AcceptanceRepository $acceptances;
|
||||
private RegistrationGate $gate;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->questions = Mockery::mock(QuestionRepository::class);
|
||||
$this->answers = Mockery::mock(AnswerRepository::class);
|
||||
$this->policies = Mockery::mock(PolicyRepository::class);
|
||||
$this->versions = Mockery::mock(PolicyVersionRepository::class);
|
||||
$this->acceptances = Mockery::mock(AcceptanceRepository::class);
|
||||
|
||||
$this->gate = new RegistrationGate(
|
||||
$this->questions,
|
||||
$this->answers,
|
||||
$this->policies,
|
||||
$this->versions,
|
||||
$this->acceptances
|
||||
);
|
||||
}
|
||||
|
||||
private function requiredQuestion(): Question
|
||||
{
|
||||
return new Question(offeringId: 7, label: 'Level?', isRequired: true, id: 3);
|
||||
}
|
||||
|
||||
private function bookingPolicy(): Policy
|
||||
{
|
||||
return new Policy('Cancellation', 'cancellation', currentVersionId: 9, acceptanceScope: Policy::SCOPE_BOOKING, id: 1);
|
||||
}
|
||||
|
||||
public function testValidatePassesWhenAnswersAndPoliciesProvided(): void
|
||||
{
|
||||
$this->questions->shouldReceive('findByOffering')->with(7, true)->andReturn([$this->requiredQuestion()]);
|
||||
$this->policies->shouldReceive('findForScope')->with(Policy::SCOPE_BOOKING)->andReturn([$this->bookingPolicy()]);
|
||||
$this->versions->shouldReceive('findById')->with(9)->andReturn(new PolicyVersion(1, 1, 'body', PolicyVersion::STATUS_PUBLISHED, null, 9));
|
||||
|
||||
self::assertNull($this->gate->validate(7, [3 => 'Beginner'], [9]));
|
||||
}
|
||||
|
||||
public function testValidateFailsWhenRequiredQuestionUnanswered(): void
|
||||
{
|
||||
$this->questions->shouldReceive('findByOffering')->with(7, true)->andReturn([$this->requiredQuestion()]);
|
||||
|
||||
$result = $this->gate->validate(7, [3 => ' '], [9]);
|
||||
|
||||
self::assertInstanceOf(\WP_Error::class, $result);
|
||||
self::assertSame('missing_answer', $result->get_error_code());
|
||||
}
|
||||
|
||||
public function testValidateFailsWhenPolicyNotAccepted(): void
|
||||
{
|
||||
$this->questions->shouldReceive('findByOffering')->with(7, true)->andReturn([$this->requiredQuestion()]);
|
||||
$this->policies->shouldReceive('findForScope')->with(Policy::SCOPE_BOOKING)->andReturn([$this->bookingPolicy()]);
|
||||
$this->versions->shouldReceive('findById')->with(9)->andReturn(new PolicyVersion(1, 1, 'body', PolicyVersion::STATUS_PUBLISHED, null, 9));
|
||||
|
||||
$result = $this->gate->validate(7, [3 => 'Beginner'], []);
|
||||
|
||||
self::assertInstanceOf(\WP_Error::class, $result);
|
||||
self::assertSame('policy_required', $result->get_error_code());
|
||||
}
|
||||
|
||||
public function testRecordPersistsAnswersAndAcceptances(): void
|
||||
{
|
||||
$this->questions->shouldReceive('findByOffering')->with(7, true)->andReturn([$this->requiredQuestion()]);
|
||||
$this->policies->shouldReceive('findForScope')->with(Policy::SCOPE_BOOKING)->andReturn([$this->bookingPolicy()]);
|
||||
$this->versions->shouldReceive('findById')->with(9)->andReturn(new PolicyVersion(1, 1, 'body', PolicyVersion::STATUS_PUBLISHED, null, 9));
|
||||
|
||||
$this->answers->shouldReceive('insert')
|
||||
->once()
|
||||
->with(Mockery::on(static fn (Answer $a): bool => $a->questionId === 3 && $a->registrationId === 50 && $a->answerValue === 'Beginner'));
|
||||
|
||||
$this->acceptances->shouldReceive('insert')
|
||||
->once()
|
||||
->with(Mockery::on(static fn (PolicyAcceptance $a): bool => $a->policyVersionId === 9 && $a->registrationType === PolicyAcceptance::REG_LESSON && $a->registrationId === 50));
|
||||
|
||||
$this->gate->record(PolicyAcceptance::REG_LESSON, 50, 5, 7, [3 => 'Beginner'], [9], '203.0.113.7');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user