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
6namespace Tests\Controllers\InterOp;
7
8use App\Models\Beatmapset;
9use App\Models\Log;
10use App\Models\Notification;
11use App\Models\User;
12use Tests\TestCase;
13
14class BeatmapsetsControllerTest extends TestCase
15{
16 public function testBroadcastNew()
17 {
18 $beatmapset = Beatmapset::factory()->create(['user_id' => User::factory()]);
19 $follower = User::factory()->create();
20 $follower->follows()->create([
21 'subtype' => 'mapping',
22 'notifiable' => $beatmapset->user,
23 ]);
24 $notificationCount = Notification::count();
25 $followerNotificationCount = $follower->userNotifications()->count();
26
27 $url = route('interop.beatmapsets.broadcast-new', ['beatmapset' => $beatmapset, 'timestamp' => time()]);
28
29 $this
30 ->withInterOpHeader($url)
31 ->post($url)
32 ->assertSuccessful();
33
34 $this->assertSame($notificationCount + 1, Notification::count());
35 $this->assertSame($followerNotificationCount + 1, $follower->userNotifications()->count());
36 }
37
38 public function testBroadcastRevive()
39 {
40 $beatmapset = Beatmapset::factory()->create(['user_id' => User::factory()]);
41 $follower = User::factory()->create();
42 $follower->follows()->create([
43 'subtype' => 'mapping',
44 'notifiable' => $beatmapset->user,
45 ]);
46 $notificationCount = Notification::count();
47 $followerNotificationCount = $follower->userNotifications()->count();
48
49 $url = route('interop.beatmapsets.broadcast-revive', ['beatmapset' => $beatmapset, 'timestamp' => time()]);
50
51 $this
52 ->withInterOpHeader($url)
53 ->post($url)
54 ->assertSuccessful();
55
56 $this->assertSame($notificationCount + 1, Notification::count());
57 $this->assertSame($followerNotificationCount + 1, $follower->userNotifications()->count());
58 }
59
60 public function testDestroy()
61 {
62 $beatmapset = Beatmapset::factory()->create([
63 'approved' => Beatmapset::STATES['pending'],
64 'user_id' => User::factory(),
65 ]);
66
67 $banchoBotUser = User::factory()->create();
68 config_set('osu.legacy.bancho_bot_user_id', $banchoBotUser->getKey());
69
70 $url = route('interop.beatmapsets.destroy', [
71 'beatmapset' => $beatmapset->getKey(),
72 'timestamp' => time(),
73 ]);
74
75 $this
76 ->withInterOpHeader($url)
77 ->delete($url)
78 ->assertStatus(204);
79
80 $this->assertSame(Log::orderBy('log_time', 'desc')->first()->user_id, $banchoBotUser->getKey());
81 }
82}