1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6declare(strict_types=1);
7
8namespace Tests\Controllers;
9
10use App\Models\User;
11use App\Models\UserGroupEvent;
12use Tests\TestCase;
13
14class GroupHistoryControllerTest extends TestCase
15{
16 public function testIndexExcludesHiddenEventsWhenGuest(): void
17 {
18 $event = UserGroupEvent::factory()->create(['hidden' => true]);
19
20 $response = $this
21 ->getJson(route('group-history.index'))
22 ->assertOk()
23 ->json();
24
25 $responseEventIds = collect($response['events'])->pluck('id');
26 $this->assertNotContains($event->getKey(), $responseEventIds);
27 }
28
29 public function testIndexExcludesHiddenEventsWhenNotInGroup(): void
30 {
31 $event = UserGroupEvent::factory()->create(['hidden' => true]);
32 $user = User::factory()->create();
33
34 $response = $this
35 ->actingAsVerified($user)
36 ->getJson(route('group-history.index'))
37 ->assertOk()
38 ->json();
39
40 $responseEventIds = collect($response['events'])->pluck('id');
41 $this->assertNotContains($event->getKey(), $responseEventIds);
42 }
43
44 public function testIndexIncludesHiddenEventsWhenInGroup(): void
45 {
46 $event = UserGroupEvent::factory()->create(['hidden' => true]);
47 $user = User::factory()->withGroup($event->group->identifier)->create();
48
49 $response = $this
50 ->actingAsVerified($user)
51 ->getJson(route('group-history.index'))
52 ->assertOk()
53 ->json();
54
55 $responseEventIds = collect($response['events'])->pluck('id');
56 $this->assertContains($event->getKey(), $responseEventIds);
57 }
58
59 public function textIndexListsEvents(): void
60 {
61 $event = UserGroupEvent::factory()->create();
62
63 $response = $this
64 ->getJson(route('group-history.index'))
65 ->assertOk()
66 ->json();
67
68 $responseEventIds = collect($response['events'])->pluck('id');
69 $this->assertContains($event->getKey(), $responseEventIds);
70 }
71}