Notify instructors on new bookings and enrolments
CI / Coding Standards (pull_request) Successful in 27s
CI / Tests (PHP 8.1) (pull_request) Successful in 37s
CI / No Debug Code (pull_request) Successful in 9s
CI / Tests (PHP 8.3) (pull_request) Successful in 36s
CI / Tests (PHP 8.5) (pull_request) Successful in 40s
CI / Tests (PHP 8.2) (pull_request) Successful in 42s
CI / Static Analysis (pull_request) Successful in 48s
CI / Build Plugin Zip (pull_request) Skipped
CI / Coding Standards (pull_request) Successful in 27s
CI / Tests (PHP 8.1) (pull_request) Successful in 37s
CI / No Debug Code (pull_request) Successful in 9s
CI / Tests (PHP 8.3) (pull_request) Successful in 36s
CI / Tests (PHP 8.5) (pull_request) Successful in 40s
CI / Tests (PHP 8.2) (pull_request) Successful in 42s
CI / Static Analysis (pull_request) Successful in 48s
CI / Build Plugin Zip (pull_request) Skipped
Add an opt-in, per-instructor email notice sent when someone books one of their lessons or enrols in one of their group classes. Off by default and set from My Availability → Notifications; covers both the student/guardian REST flows and the studio's wp-admin "book/add for a student" forms. The opt-in check lives in InstructorNotificationMailer so no booking path can drift on who is mailed; lessons fire from LessonBooker::settle (the one step both booking paths reach), enrolments from EnrollmentEndpoint::enroll and GroupClassController::addDirect. The notice is a courtesy and never fails a booking or enrolment that otherwise succeeded. Co-authored-by: anthropic/claude-opus-4-8
This commit is contained in:
co-authored by
anthropic/claude-opus-4-8
parent
56fc0bd57d
commit
12765d8f13
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular\Tests\Unit\Auth;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use Unsupervised\Schedular\Auth\InstructorNotificationPref;
|
||||
use Unsupervised\Schedular\Tests\Unit\TestCase;
|
||||
|
||||
class InstructorNotificationPrefTest extends TestCase
|
||||
{
|
||||
public function testDefaultsOffWhenTheMetaIsUnset(): void
|
||||
{
|
||||
// Absent meta reads as an empty string, which is not the opt-in value.
|
||||
Functions\when('get_user_meta')->justReturn('');
|
||||
|
||||
self::assertFalse((new InstructorNotificationPref())->wants(7));
|
||||
}
|
||||
|
||||
public function testReadsAStoredOptIn(): void
|
||||
{
|
||||
Functions\when('get_user_meta')->alias(
|
||||
static fn (int $id, string $key): string => 7 === $id && InstructorNotificationPref::META_NOTIFY === $key ? '1' : ''
|
||||
);
|
||||
|
||||
self::assertTrue((new InstructorNotificationPref())->wants(7));
|
||||
}
|
||||
|
||||
public function testAStoredNoReadsAsOff(): void
|
||||
{
|
||||
Functions\when('get_user_meta')->justReturn('0');
|
||||
|
||||
self::assertFalse((new InstructorNotificationPref())->wants(7));
|
||||
}
|
||||
|
||||
public function testNobodyWantsNothing(): void
|
||||
{
|
||||
// A zero id is not a user; it must never read as opted-in.
|
||||
Functions\expect('get_user_meta')->never();
|
||||
|
||||
self::assertFalse((new InstructorNotificationPref())->wants(0));
|
||||
}
|
||||
|
||||
public function testSetStoresTheChoiceAsAStringBoolean(): void
|
||||
{
|
||||
Functions\expect('update_user_meta')->once()->with(7, InstructorNotificationPref::META_NOTIFY, '1')->andReturn(true);
|
||||
|
||||
(new InstructorNotificationPref())->set(7, true);
|
||||
}
|
||||
|
||||
public function testSetStoresADeliberateNoRatherThanDeleting(): void
|
||||
{
|
||||
Functions\expect('update_user_meta')->once()->with(7, InstructorNotificationPref::META_NOTIFY, '0')->andReturn(true);
|
||||
|
||||
(new InstructorNotificationPref())->set(7, false);
|
||||
}
|
||||
|
||||
public function testSetIgnoresANonUser(): void
|
||||
{
|
||||
Functions\expect('update_user_meta')->never();
|
||||
|
||||
(new InstructorNotificationPref())->set(0, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user