Add lecturer cleanup job and update profile update functionality

- 🧹 Introduce `lecturers:cleanup` command to delete lecturers without associated courses or events, merging their items into "Einundzwanzig."
- ⚙️ Add `update` method to `UserController` for handling profile updates, allowing name changes while restricting role modifications.
- 🌐 Register `PATCH /api/user` route for profile updates and update related API tests.
- 🧪 Add feature and console tests for `lecturers:cleanup`, covering dry-run, forced deletion, and edge cases.
This commit is contained in:
HolgerHatGarKeineNode
2026-06-16 14:40:40 +02:00
parent c3028b8260
commit 29628b41e9
5 changed files with 199 additions and 3 deletions
+30
View File
@@ -225,6 +225,36 @@ it('denies /api/user without a token', function () {
$this->getJson('/api/user')->assertUnauthorized();
});
it('updates the token owner display name', function () {
$user = User::factory()->create(['name' => 'Old Name']);
Sanctum::actingAs($user);
$this->patchJson('/api/user', ['name' => 'Satoshi'])
->assertOk()
->assertJsonPath('name', 'Satoshi');
expect($user->fresh()->name)->toBe('Satoshi');
});
it('does not let the user change roles via the profile update', function () {
$user = User::factory()->create(['is_lecturer' => false]);
Sanctum::actingAs($user);
$this->patchJson('/api/user', ['name' => 'Satoshi', 'is_lecturer' => true])
->assertOk();
expect((bool) $user->fresh()->is_lecturer)->toBeFalse();
});
it('rejects an empty display name', function () {
$user = User::factory()->create();
Sanctum::actingAs($user);
$this->patchJson('/api/user', ['name' => ''])
->assertUnprocessable()
->assertJsonValidationErrors('name');
});
it('revokes the requesting token on mobile logout', function () {
$user = User::factory()->create();
$plainTextToken = $user->createToken('Pixel 10')->plainTextToken;