seed(RoleSeeder::class); $this->organisation = Organisation::factory()->create(); $this->orgAdmin = User::factory()->create(); $this->organisation->users()->attach($this->orgAdmin, ['role' => 'org_admin']); $this->event = Event::factory()->create([ 'organisation_id' => $this->organisation->id, ]); $this->crowdType = CrowdType::factory()->systemType('VOLUNTEER')->create([ 'organisation_id' => $this->organisation->id, ]); } public function test_approving_person_sends_approved_email(): void { Mail::fake(); $person = Person::factory()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->crowdType->id, 'status' => 'pending', 'email' => 'volunteer@test.nl', ]); Sanctum::actingAs($this->orgAdmin); $response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve"); $response->assertOk(); Mail::assertQueued(RegistrationApprovedMail::class, function ($mail) { return $mail->hasTo('volunteer@test.nl'); }); } public function test_rejecting_person_sends_rejected_email_with_reason(): void { Mail::fake(); $person = Person::factory()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->crowdType->id, 'status' => 'pending', 'email' => 'volunteer@test.nl', ]); Sanctum::actingAs($this->orgAdmin); $response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/reject", [ 'reason' => 'Geen beschikbaarheid op de juiste momenten.', ]); $response->assertOk(); $this->assertDatabaseHas('persons', [ 'id' => $person->id, 'status' => 'rejected', ]); Mail::assertQueued(RegistrationRejectedMail::class, function ($mail) { return $mail->hasTo('volunteer@test.nl') && $mail->reason === 'Geen beschikbaarheid op de juiste momenten.'; }); } public function test_rejecting_person_sends_rejected_email_without_reason(): void { Mail::fake(); $person = Person::factory()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->crowdType->id, 'status' => 'pending', 'email' => 'volunteer@test.nl', ]); Sanctum::actingAs($this->orgAdmin); $response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/reject"); $response->assertOk(); Mail::assertQueued(RegistrationRejectedMail::class, function ($mail) { return $mail->hasTo('volunteer@test.nl') && $mail->reason === null; }); } public function test_unauthenticated_cannot_approve(): void { $person = Person::factory()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->crowdType->id, 'status' => 'pending', ]); $response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve"); $response->assertStatus(401); } public function test_outsider_cannot_approve(): void { $outsider = User::factory()->create(); $otherOrg = Organisation::factory()->create(); $otherOrg->users()->attach($outsider, ['role' => 'org_admin']); $person = Person::factory()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->crowdType->id, 'status' => 'pending', ]); Sanctum::actingAs($outsider); $response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve"); $response->assertStatus(403); } }