CI / Tests (PHP 8.1) (pull_request) Successful in 6m39s
CI / Tests (PHP 8.2) (pull_request) Successful in 57s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m59s
CI / Tests (PHP 8.5) (pull_request) Successful in 3m31s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards & Static Analysis (pull_request) Successful in 3m28s
CI / Build Plugin Zip (pull_request) Skipped
Two related gaps, closed together because the second is created by the first. A private lesson could only be booked by the student or their guardian, so a booking taken over the phone had no way in — where group classes have had "Add students directly" all along. "Book a lesson for a student" is now a panel on Scheduler and My Lessons: student, open time, lesson type, with weekly term reservations and a no-charge option for make-up lessons. The booking core is extracted to Booking\LessonBooker and shared with POST /bookings, so the two paths cannot drift on offering rules, slot claiming, or billing. That leaves a registration with no intake answers and no policy acceptances, because nobody was at a keyboard to give them — already true of every directly added group-class student. Ticking the boxes on a student's behalf would be an audit trail that says something untrue, so instead the answers are collected another way and recorded afterwards, from a lesson's or an enrolment's detail page. Every recording must say how it was collected, which is stamped on each row along with who typed it and shown in a new "How it was given" column: a policy ticked online and one transcribed from paper must never look alike. Only staff-made registrations qualify (us_lessons.booked_by, us_group_enrollments.enrolled_by) — one the student made already holds their own answers. Only what is still missing can be recorded, re-checked at write time, so a stale or double-posted form cannot duplicate or overwrite. No IP is stored for a transcription, and accepted_by stays the student while recorded_by names the staff member. Intake is now generic over Registration\IntakeSubject, which Lesson and Enrollment both implement; LessonDetail became Registration\IntakeAudit and is shared by both detail views rather than duplicated. Closes #182 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfHt6CyJHz6KkA4RuaS7WK
187 lines
7.7 KiB
PHP
187 lines
7.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Registration;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use Mockery;
|
|
use Unsupervised\Schedular\Booking\Lesson;
|
|
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\IntakeAudit;
|
|
use Unsupervised\Schedular\Registration\IntakeProvenance;
|
|
use Unsupervised\Schedular\Registration\AnswerRepository;
|
|
use Unsupervised\Schedular\Registration\Question;
|
|
use Unsupervised\Schedular\Registration\QuestionRepository;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class IntakeAuditTest extends TestCase
|
|
{
|
|
private AnswerRepository&Mockery\MockInterface $answers;
|
|
private QuestionRepository&Mockery\MockInterface $questions;
|
|
private AcceptanceRepository&Mockery\MockInterface $acceptances;
|
|
private PolicyRepository&Mockery\MockInterface $policies;
|
|
private PolicyVersionRepository&Mockery\MockInterface $versions;
|
|
private IntakeAudit $detail;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->answers = Mockery::mock(AnswerRepository::class);
|
|
$this->questions = Mockery::mock(QuestionRepository::class);
|
|
$this->acceptances = Mockery::mock(AcceptanceRepository::class);
|
|
$this->policies = Mockery::mock(PolicyRepository::class);
|
|
$this->versions = Mockery::mock(PolicyVersionRepository::class);
|
|
|
|
$this->detail = new IntakeAudit(
|
|
$this->answers,
|
|
$this->questions,
|
|
$this->acceptances,
|
|
$this->policies,
|
|
$this->versions
|
|
);
|
|
}
|
|
|
|
public function testAnswersPairEachAnswerWithItsQuestionLabel(): void
|
|
{
|
|
$this->answers->shouldReceive('findByRegistration')->once()->with(Answer::REG_LESSON, 7)->andReturn([
|
|
new Answer(questionId: 2, registrationType: Answer::REG_LESSON, registrationId: 7, studentId: 5, answerValue: 'Beginner'),
|
|
new Answer(questionId: 9, registrationType: Answer::REG_LESSON, registrationId: 7, studentId: 5, answerValue: null),
|
|
]);
|
|
|
|
$this->questions->shouldReceive('findById')->with(2)->andReturn(new Question(offeringId: 1, label: 'Skill level', id: 2));
|
|
$this->questions->shouldReceive('findById')->with(9)->andReturn(null);
|
|
|
|
self::assertSame(
|
|
[
|
|
['question' => 'Skill level', 'answer' => 'Beginner', 'source' => 'Given online when booking'],
|
|
['question' => '#9', 'answer' => '—', 'source' => 'Given online when booking'],
|
|
],
|
|
$this->detail->answers($this->lesson(7))
|
|
);
|
|
}
|
|
|
|
public function testAcceptancesResolvePolicyTitleVersionAndAuditTrail(): void
|
|
{
|
|
$this->acceptances->shouldReceive('findByRegistration')->once()->with(PolicyAcceptance::REG_LESSON, 7)->andReturn([
|
|
new PolicyAcceptance(
|
|
policyVersionId: 4,
|
|
studentId: 5,
|
|
registrationType: PolicyAcceptance::REG_LESSON,
|
|
registrationId: 7,
|
|
ipAddress: '1.2.3.4',
|
|
acceptedAt: '2026-07-01 10:00:00'
|
|
),
|
|
]);
|
|
|
|
$this->versions->shouldReceive('findById')->with(4)->andReturn(new PolicyVersion(policyId: 3, versionNumber: 2, id: 4));
|
|
$this->policies->shouldReceive('findById')->with(3)->andReturn(new Policy(title: 'Cancellation', slug: 'cancellation', id: 3));
|
|
|
|
self::assertSame(
|
|
[
|
|
[
|
|
'policy' => 'Cancellation',
|
|
'version' => 'v2',
|
|
'accepted_at' => '2026-07-01 10:00:00',
|
|
'ip' => '1.2.3.4',
|
|
'source' => 'Given online when booking',
|
|
],
|
|
],
|
|
$this->detail->acceptances($this->lesson(7))
|
|
);
|
|
}
|
|
|
|
public function testACollectedElsewhereAnswerNamesItsSourceAndWhoRecordedIt(): void
|
|
{
|
|
$user = Mockery::mock(\WP_User::class);
|
|
$user->ID = 7;
|
|
$user->first_name = 'Jane';
|
|
$user->last_name = 'Doe';
|
|
$user->nickname = 'jane';
|
|
$user->display_name = 'jane';
|
|
Functions\when('get_userdata')->justReturn($user);
|
|
|
|
$this->answers->shouldReceive('findByRegistration')->once()->with(Answer::REG_LESSON, 7)->andReturn([
|
|
new Answer(
|
|
questionId: 2,
|
|
registrationType: Answer::REG_LESSON,
|
|
registrationId: 7,
|
|
studentId: 5,
|
|
answerValue: 'Nut allergy',
|
|
collectedVia: IntakeProvenance::VIA_PAPER,
|
|
collectedNote: 'Filed in the studio binder',
|
|
recordedBy: 7
|
|
),
|
|
]);
|
|
$this->questions->shouldReceive('findById')->with(2)->andReturn(new Question(offeringId: 1, label: 'Allergies', id: 2));
|
|
|
|
self::assertSame(
|
|
[[
|
|
'question' => 'Allergies',
|
|
'answer' => 'Nut allergy',
|
|
'source' => 'On a signed paper form — Filed in the studio binder — recorded by Jane Doe',
|
|
]],
|
|
$this->detail->answers($this->lesson(7))
|
|
);
|
|
}
|
|
|
|
public function testSeriesOccurrenceReadsTheAnchorsAnswersAndAcceptances(): void
|
|
{
|
|
// Occurrence #12 of a weekly reservation anchored on lesson 7: the intake
|
|
// and the agreement were recorded once, against the anchor.
|
|
$occurrence = $this->lesson(12, seriesId: 7);
|
|
|
|
$this->answers->shouldReceive('findByRegistration')->once()->with(Answer::REG_LESSON, 7)->andReturn([
|
|
new Answer(questionId: 2, registrationType: Answer::REG_LESSON, registrationId: 7, studentId: 5, answerValue: 'Beginner'),
|
|
]);
|
|
$this->questions->shouldReceive('findById')->with(2)->andReturn(new Question(offeringId: 1, label: 'Skill level', id: 2));
|
|
|
|
$this->acceptances->shouldReceive('findByRegistration')->once()->with(PolicyAcceptance::REG_LESSON, 7)->andReturn([
|
|
new PolicyAcceptance(
|
|
policyVersionId: 4,
|
|
studentId: 5,
|
|
registrationType: PolicyAcceptance::REG_LESSON,
|
|
registrationId: 7,
|
|
ipAddress: '1.2.3.4',
|
|
acceptedAt: '2026-07-01 10:00:00'
|
|
),
|
|
]);
|
|
$this->versions->shouldReceive('findById')->with(4)->andReturn(new PolicyVersion(policyId: 3, versionNumber: 2, id: 4));
|
|
$this->policies->shouldReceive('findById')->with(3)->andReturn(new Policy(title: 'Cancellation', slug: 'cancellation', id: 3));
|
|
|
|
self::assertSame(
|
|
[['question' => 'Skill level', 'answer' => 'Beginner', 'source' => 'Given online when booking']],
|
|
$this->detail->answers($occurrence)
|
|
);
|
|
self::assertSame(
|
|
[[
|
|
'policy' => 'Cancellation',
|
|
'version' => 'v2',
|
|
'accepted_at' => '2026-07-01 10:00:00',
|
|
'ip' => '1.2.3.4',
|
|
'source' => 'Given online when booking',
|
|
]],
|
|
$this->detail->acceptances($occurrence)
|
|
);
|
|
}
|
|
|
|
private function lesson(int $id, ?int $seriesId = null): Lesson
|
|
{
|
|
return new Lesson(
|
|
slotId: 1,
|
|
studentId: 5,
|
|
instructorId: 9,
|
|
offeringId: 1,
|
|
recurrence: null === $seriesId ? Lesson::RECURRENCE_SINGLE : Lesson::RECURRENCE_WEEKLY,
|
|
seriesId: $seriesId,
|
|
id: $id
|
|
);
|
|
}
|
|
}
|