Files
unsupervised-scheduler/tests/Unit/GroupClass/GroupAccessTest.php
T
thatguygriffandClaude Opus 4.8 a281935811
CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.1) (pull_request) Successful in 49s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m49s
CI / Coding Standards (pull_request) Successful in 2m55s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m40s
CI / Build Plugin Zip (pull_request) Skipped
Add invite-only group classes
Group classes can now be marked invite-only (us_offerings.access_mode).
Invite-only classes are hidden from the public catalog and reachable only
when the instructor lets someone in via one of three paths, managed from
My Lessons -> My Group Classes:

- Add students directly: enrols them now with a pending payment.
- Make available: grants registered students access to self-enrol through
  the normal paid flow (multi-select, emailed a notice).
- Invite by email: tokenised registration invite tied to the class for a
  non-account address; after they register the class becomes enrollable.
  Reuses an existing pending invite instead of sending a second link.

New us_group_access table records grants; GET /offerings merges granted
invite-only classes for the caller; enrolment requires a grant
(403 invite_required) and flips it to enrolled on success.

composer test (487), composer lint, composer cs all pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-23 13:51:02 -03:00

71 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Tests\Unit\GroupClass;
use Unsupervised\Schedular\GroupClass\GroupAccess;
use Unsupervised\Schedular\Tests\Unit\TestCase;
class GroupAccessTest extends TestCase
{
public function testDefaultsToInvitedStatusAndNullStudent(): void
{
$access = new GroupAccess(offeringId: 8);
self::assertSame(GroupAccess::STATUS_INVITED, $access->status);
self::assertNull($access->studentId);
self::assertSame('', $access->email);
}
public function testFromRowMapsColumns(): void
{
$row = (object) [
'id' => '3',
'offering_id' => '8',
'student_id' => '5',
'email' => '[email protected]',
'invite_id' => '9',
'status' => GroupAccess::STATUS_ENROLLED,
'invited_by' => '2',
];
$access = GroupAccess::fromRow($row);
self::assertSame(3, $access->id);
self::assertSame(8, $access->offeringId);
self::assertSame(5, $access->studentId);
self::assertSame('[email protected]', $access->email);
self::assertSame(9, $access->inviteId);
self::assertSame(GroupAccess::STATUS_ENROLLED, $access->status);
self::assertSame(2, $access->invitedBy);
}
public function testFromRowCastsNullStudentAndInvite(): void
{
$row = (object) [
'id' => '3',
'offering_id' => '8',
'student_id' => null,
'email' => '[email protected]',
'invite_id' => null,
'status' => GroupAccess::STATUS_INVITED,
'invited_by' => null,
];
$access = GroupAccess::fromRow($row);
self::assertNull($access->studentId);
self::assertNull($access->inviteId);
self::assertNull($access->invitedBy);
}
public function testToArrayContainsExpectedKeys(): void
{
$arr = (new GroupAccess(offeringId: 8, studentId: 5, id: 3))->toArray();
foreach (['id', 'offering_id', 'student_id', 'email', 'invite_id', 'status', 'invited_by'] as $key) {
self::assertArrayHasKey($key, $arr);
}
}
}