Demo follow-ups: editable policy name, one-page signup, group classes in upcoming lessons, deletion cleanup
CI / Tests (PHP 8.1) (pull_request) Successful in 1m0s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m0s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 3m8s
CI / Build Plugin Zip (pull_request) Skipped
CI / PHPStan (pull_request) Successful in 2m49s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m44s

Five items from the latest demo pass:

- A policy's title can be edited from the Policies screen. Only the title
  moves; the slug is what the gates resolve policies by, so a rename can
  never detach a policy from acceptances already recorded against it.
- Signup is one page again. The studio's registration questions move from
  a second step behind "Next" onto the main form, in an "About you" panel
  above the students being added, and that panel also asks an adult
  student for their birth year (the same us_birth_year meta a child's
  uses). register.js disables and hides the whole panel for a pure
  guardian, since the questions describe a student.
- The password is re-scored on submit, not only as it is typed. zxcvbn's
  dictionary arrives after page load, so a password typed straight away
  was never scored at all and the first the student heard of it was the
  server rejecting the whole form.
- Group-class sessions appear alongside lessons wherever upcoming lessons
  are listed: the [us_scheduler] panel (students and instructors) and the
  admin student detail page. GroupClass\SessionSchedule derives them from
  Offering::sessionWindows(), the same derivation the billing scan uses.
  They carry kind = 'group_class' and no Cancel action - a session is one
  date in a term, not a booked slot.
- Deleting a user releases what the account was holding: each upcoming
  lesson is cancelled, its slot freed for rebooking, its pending payment
  voided, and active class enrolments cancelled. Past lessons and paid
  history are left alone.

Tests: composer test (851), composer lint, composer cs all pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
2026-07-30 11:45:04 -03:00
co-authored by Claude Opus 5
parent 258468093b
commit cb347ffca0
33 changed files with 1419 additions and 291 deletions
@@ -0,0 +1,197 @@
<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Tests\Unit\GroupClass;
use Mockery;
use Unsupervised\Schedular\GroupClass\Enrollment;
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
use Unsupervised\Schedular\GroupClass\SessionSchedule;
use Unsupervised\Schedular\Offering\Offering;
use Unsupervised\Schedular\Offering\OfferingRepository;
use Unsupervised\Schedular\Tests\Unit\TestCase;
class SessionScheduleTest extends TestCase
{
private EnrollmentRepository&Mockery\MockInterface $enrollments;
private OfferingRepository&Mockery\MockInterface $offerings;
private SessionSchedule $schedule;
protected function setUp(): void
{
parent::setUp();
$this->enrollments = Mockery::mock(EnrollmentRepository::class);
$this->offerings = Mockery::mock(OfferingRepository::class);
$this->schedule = new SessionSchedule($this->enrollments, $this->offerings);
}
/** A three-week Tuesday class at 16:00, one hour long. */
private function choir(int $id = 8, string $title = 'Choir'): Offering
{
return new Offering(
instructorId: 3,
kind: Offering::KIND_GROUP_CLASS,
title: $title,
durationMinutes: 60,
termStart: '2026-09-08',
termEnd: '2026-09-22',
classTime: '16:00:00',
id: $id,
);
}
public function testAStudentsEnrolmentBecomesOneRowPerRemainingSession(): void
{
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([
new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, id: 40),
]);
$this->offerings->shouldReceive('findById')->with(8)->andReturn($this->choir());
$rows = $this->schedule->upcomingForStudent(5, '2026-09-01 00:00:00');
self::assertCount(3, $rows);
self::assertSame(
['2026-09-08 16:00:00', '2026-09-15 16:00:00', '2026-09-22 16:00:00'],
array_column($rows, 'start_dt')
);
self::assertSame('2026-09-08 17:00:00', $rows[0]['end_dt']);
self::assertSame('Choir', $rows[0]['offering_title']);
self::assertSame(40, $rows[0]['enrollment_id']);
self::assertSame(3, $rows[0]['instructor_id']);
self::assertSame(60, $rows[0]['duration_minutes']);
}
public function testSessionsThatHaveAlreadyStartedAreLeftOut(): void
{
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([
new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, id: 40),
]);
$this->offerings->shouldReceive('findById')->with(8)->andReturn($this->choir());
// Mid-term: the first two dates are gone, the last is still to come.
$rows = $this->schedule->upcomingForStudent(5, '2026-09-16 09:00:00');
self::assertSame(['2026-09-22 16:00:00'], array_column($rows, 'start_dt'));
}
public function testAWithdrawnEnrolmentContributesNothing(): void
{
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([
new Enrollment(
offeringId: 8,
studentId: 5,
instructorId: 3,
status: Enrollment::STATUS_CANCELLED,
id: 40,
),
]);
$this->offerings->shouldNotReceive('findById');
self::assertSame([], $this->schedule->upcomingForStudent(5, '2026-09-01 00:00:00'));
}
/**
* "Completed" is a billing state, not a calendar one — the class may still
* have dates left to run, so its sessions stay on the list.
*/
public function testACompletedEnrolmentStillListsItsRemainingSessions(): void
{
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([
new Enrollment(
offeringId: 8,
studentId: 5,
instructorId: 3,
status: Enrollment::STATUS_COMPLETED,
id: 40,
),
]);
$this->offerings->shouldReceive('findById')->with(8)->andReturn($this->choir());
$rows = $this->schedule->upcomingForStudent(5, '2026-09-01 00:00:00');
self::assertCount(3, $rows);
self::assertSame(Enrollment::STATUS_COMPLETED, $rows[0]['status']);
}
/**
* A class with no time set has no derivable sessions, so it is left out of a
* dated list rather than shown at a time nobody chose.
*/
public function testAClassWithoutAScheduleYieldsNoRows(): void
{
$undated = new Offering(
instructorId: 3,
kind: Offering::KIND_GROUP_CLASS,
title: 'Choir',
durationMinutes: 60,
termStart: '2026-09-08',
id: 8,
);
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([
new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, id: 40),
]);
$this->offerings->shouldReceive('findById')->with(8)->andReturn($undated);
self::assertSame([], $this->schedule->upcomingForStudent(5, '2026-09-01 00:00:00'));
}
public function testADeletedOfferingIsSkippedRatherThanFatal(): void
{
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([
new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, id: 40),
]);
$this->offerings->shouldReceive('findById')->with(8)->andReturn(null);
self::assertSame([], $this->schedule->upcomingForStudent(5, '2026-09-01 00:00:00'));
}
public function testTwoEnrolmentsAreInterleavedByDate(): void
{
$band = new Offering(
instructorId: 3,
kind: Offering::KIND_GROUP_CLASS,
title: 'Band',
durationMinutes: 45,
termStart: '2026-09-10',
termEnd: '2026-09-10',
classTime: '09:00:00',
id: 9,
);
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([
new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, id: 40),
new Enrollment(offeringId: 9, studentId: 5, instructorId: 3, id: 41),
]);
$this->offerings->shouldReceive('findById')->with(8)->andReturn($this->choir());
$this->offerings->shouldReceive('findById')->with(9)->andReturn($band);
$rows = $this->schedule->upcomingForStudent(5, '2026-09-01 00:00:00');
self::assertSame(
['Choir', 'Band', 'Choir', 'Choir'],
array_column($rows, 'offering_title')
);
}
/**
* An instructor's list is built from the classes they teach, not from who
* has signed up: a class with no enrolments yet is still on their schedule.
*/
public function testAnInstructorSeesEachSessionOfTheirActiveClassesOnce(): void
{
$this->offerings->shouldReceive('findAll')
->once()
->with(3, Offering::KIND_GROUP_CLASS, true)
->andReturn([$this->choir()]);
$this->enrollments->shouldNotReceive('findByStudent');
$rows = $this->schedule->upcomingForInstructor(3, '2026-09-01 00:00:00');
self::assertCount(3, $rows);
self::assertSame(0, $rows[0]['enrollment_id']);
self::assertSame(3, $rows[0]['instructor_id']);
self::assertSame('Choir', $rows[0]['offering_title']);
}
}