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]>
138 lines
5.6 KiB
PHP
138 lines
5.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Tests\Unit\Auth;
|
|
|
|
use Brain\Monkey\Actions;
|
|
use Mockery;
|
|
use Unsupervised\Schedular\Auth\DeletedUserCleanup;
|
|
use Unsupervised\Schedular\Availability\AvailabilityRepository;
|
|
use Unsupervised\Schedular\Booking\BookingRepository;
|
|
use Unsupervised\Schedular\Booking\Lesson;
|
|
use Unsupervised\Schedular\GroupClass\Enrollment;
|
|
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
|
|
use Unsupervised\Schedular\Payment\PaymentService;
|
|
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
|
|
|
class DeletedUserCleanupTest extends TestCase
|
|
{
|
|
private BookingRepository&Mockery\MockInterface $bookings;
|
|
private AvailabilityRepository&Mockery\MockInterface $availability;
|
|
private EnrollmentRepository&Mockery\MockInterface $enrollments;
|
|
private PaymentService&Mockery\MockInterface $payments;
|
|
private DeletedUserCleanup $cleanup;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->bookings = Mockery::mock(BookingRepository::class);
|
|
$this->availability = Mockery::mock(AvailabilityRepository::class);
|
|
$this->enrollments = Mockery::mock(EnrollmentRepository::class);
|
|
$this->payments = Mockery::mock(PaymentService::class);
|
|
|
|
$this->cleanup = new DeletedUserCleanup(
|
|
$this->bookings,
|
|
$this->availability,
|
|
$this->enrollments,
|
|
$this->payments
|
|
);
|
|
}
|
|
|
|
public function testHooksBothSingleSiteAndNetworkDeletion(): void
|
|
{
|
|
Actions\expectAdded('delete_user')->once();
|
|
Actions\expectAdded('wpmu_delete_user')->once();
|
|
|
|
$this->cleanup->register();
|
|
}
|
|
|
|
public function testEachUpcomingLessonIsCancelledItsSlotFreedAndItsPendingPaymentVoided(): void
|
|
{
|
|
$this->bookings->shouldReceive('findUpcomingForStudent')->with(5)->andReturn([
|
|
new Lesson(slotId: 7, studentId: 5, instructorId: 3, status: Lesson::STATUS_PENDING, paymentId: 40, id: 12),
|
|
new Lesson(slotId: 8, studentId: 5, instructorId: 3, status: Lesson::STATUS_CONFIRMED, paymentId: null, id: 13),
|
|
]);
|
|
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([]);
|
|
|
|
$this->bookings->shouldReceive('updateStatus')->once()->with(12, Lesson::STATUS_CANCELLED)->andReturn(true);
|
|
$this->bookings->shouldReceive('updateStatus')->once()->with(13, Lesson::STATUS_CANCELLED)->andReturn(true);
|
|
|
|
// The point of the whole exercise: the times go back on sale.
|
|
$this->availability->shouldReceive('release')->once()->with(7)->andReturn(true);
|
|
$this->availability->shouldReceive('release')->once()->with(8)->andReturn(true);
|
|
|
|
$this->payments->shouldReceive('voidPending')->once()->with(40);
|
|
$this->payments->shouldReceive('voidPending')->once()->with(null);
|
|
|
|
$this->cleanup->releaseBookings(5);
|
|
}
|
|
|
|
/**
|
|
* A paid lesson is not credited back. The credit could only ever be spent on
|
|
* the account being deleted, so writing one would be book-keeping nobody can
|
|
* act on — a refund is the studio's call to make and record.
|
|
*/
|
|
public function testNoCreditIsIssuedForAPaidLesson(): void
|
|
{
|
|
$this->bookings->shouldReceive('findUpcomingForStudent')->with(5)->andReturn([
|
|
new Lesson(slotId: 7, studentId: 5, instructorId: 3, status: Lesson::STATUS_CONFIRMED, paymentId: 40, id: 12),
|
|
]);
|
|
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([]);
|
|
|
|
$this->bookings->shouldReceive('updateStatus')->andReturn(true);
|
|
$this->availability->shouldReceive('release')->andReturn(true);
|
|
$this->payments->shouldReceive('voidPending');
|
|
|
|
$this->payments->shouldNotReceive('creditForCancelledLesson');
|
|
|
|
$this->cleanup->releaseBookings(5);
|
|
}
|
|
|
|
public function testActiveEnrolmentsAreCancelledAndTheirPendingPaymentsVoided(): void
|
|
{
|
|
$this->bookings->shouldReceive('findUpcomingForStudent')->with(5)->andReturn([]);
|
|
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([
|
|
new Enrollment(offeringId: 8, studentId: 5, instructorId: 3, paymentId: 41, id: 40),
|
|
new Enrollment(
|
|
offeringId: 9,
|
|
studentId: 5,
|
|
instructorId: 3,
|
|
status: Enrollment::STATUS_CANCELLED,
|
|
paymentId: 42,
|
|
id: 41,
|
|
),
|
|
]);
|
|
|
|
// Only the active one: a withdrawn enrolment is already holding nothing.
|
|
$this->enrollments->shouldReceive('updateStatus')->once()->with(40, Enrollment::STATUS_CANCELLED)->andReturn(true);
|
|
$this->payments->shouldReceive('voidPending')->once()->with(41);
|
|
|
|
$this->cleanup->releaseBookings(5);
|
|
}
|
|
|
|
/**
|
|
* Past lessons happened and may have been paid for, so they stay exactly as
|
|
* they are — `findUpcomingForStudent` is what draws that line.
|
|
*/
|
|
public function testNothingHappensWhenTheAccountHasNothingBookedAhead(): void
|
|
{
|
|
$this->bookings->shouldReceive('findUpcomingForStudent')->with(5)->andReturn([]);
|
|
$this->enrollments->shouldReceive('findByStudent')->with(5)->andReturn([]);
|
|
|
|
$this->bookings->shouldNotReceive('updateStatus');
|
|
$this->availability->shouldNotReceive('release');
|
|
$this->enrollments->shouldNotReceive('updateStatus');
|
|
|
|
$this->cleanup->releaseBookings(5);
|
|
}
|
|
|
|
public function testAnInvalidUserIdIsIgnored(): void
|
|
{
|
|
$this->bookings->shouldNotReceive('findUpcomingForStudent');
|
|
$this->enrollments->shouldNotReceive('findByStudent');
|
|
|
|
$this->cleanup->releaseBookings(0);
|
|
}
|
|
}
|