<commit_before><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace Tests\Controllers\InterOp;

use App\Libraries\MorphMap;
use App\Models\Beatmapset;
use App\Models\Log;
use App\Models\Notification;
use App\Models\User;
use Tests\TestCase;

class BeatmapsetsControllerTest extends TestCase
{
    public function testBroadcastNew()
    {
        $user = User::factory()->create();
        $beatmapset = Beatmapset::factory()->create(['user_id' => $user]);
        $follower = User::factory()->create();
        $follower->follows()->create([
            'subtype' => 'mapping',
            'notifiable_type' => MorphMap::getType($user),
            'notifiable_id' => $user->getKey(),
        ]);
        $notificationCount = Notification::count();
        $followerNotificationCount = $follower->userNotifications()->count();

        $url = route('interop.beatmapsets.broadcast-new', ['beatmapset' => $beatmapset, 'timestamp' => time()]);

        $this
            ->withInterOpHeader($url)
            ->post($url)
            ->assertSuccessful();

        $this->assertSame($notificationCount + 1, Notification::count());
        $this->assertSame($followerNotificationCount + 1, $follower->userNotifications()->count());
    }

    public function testBroadcastRevive()
    {
        $user = User::factory()->create();
        $beatmapset = Beatmapset::factory()->create(['user_id' => $user]);
        $follower = User::factory()->create();
        $follower->follows()->create([
            'subtype' => 'mapping',
            'notifiable_type' => MorphMap::getType($user),
            'notifiable_id' => $user->getKey(),
        ]);
        $notificationCount = Notification::count();
        $followerNotificationCount = $follower->userNotifications()->count();

        $url = route('interop.beatmapsets.broadcast-revive', ['beatmapset' => $beatmapset, 'timestamp' => time()]);

        $this
            ->withInterOpHeader($url)
            ->post($url)
            ->assertSuccessful();

        $this->assertSame($notificationCount + 1, Notification::count());
        $this->assertSame($followerNotificationCount + 1, $follower->userNotifications()->count());
    }

    public function testDestroy()
    {
        $owner = User::factory()->create();
        $beatmapset = Beatmapset::factory()->create([
            'approved' => Beatmapset::STATES['pending'],
            'user_id' => $owner,
        ]);

        $banchoBotUser = User::factory()->create([
            'user_id' => config('osu.legacy.bancho_bot_user_id'),
        ]);

        $url = route('interop.beatmapsets.destroy', [<commit_msg>Simplify assignment<commit_after><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace Tests\Controllers\InterOp;

use App\Libraries\MorphMap;
use App\Models\Beatmapset;
use App\Models\Log;
use App\Models\Notification;
use App\Models\User;
use Tests\TestCase;

class BeatmapsetsControllerTest extends TestCase
{
    public function testBroadcastNew()
    {
        $user = User::factory()->create();
        $beatmapset = Beatmapset::factory()->create(['user_id' => $user]);
        $follower = User::factory()->create();
        $follower->follows()->create([
            'subtype' => 'mapping',
            'notifiable' => $user,
        ]);
        $notificationCount = Notification::count();
        $followerNotificationCount = $follower->userNotifications()->count();

        $url = route('interop.beatmapsets.broadcast-new', ['beatmapset' => $beatmapset, 'timestamp' => time()]);

        $this
            ->withInterOpHeader($url)
            ->post($url)
            ->assertSuccessful();

        $this->assertSame($notificationCount + 1, Notification::count());
        $this->assertSame($followerNotificationCount + 1, $follower->userNotifications()->count());
    }

    public function testBroadcastRevive()
    {
        $user = User::factory()->create();
        $beatmapset = Beatmapset::factory()->create(['user_id' => $user]);
        $follower = User::factory()->create();
        $follower->follows()->create([
            'subtype' => 'mapping',
            'notifiable' => $user,
        ]);
        $notificationCount = Notification::count();
        $followerNotificationCount = $follower->userNotifications()->count();

        $url = route('interop.beatmapsets.broadcast-revive', ['beatmapset' => $beatmapset, 'timestamp' => time()]);

        $this
            ->withInterOpHeader($url)
            ->post($url)
            ->assertSuccessful();

        $this->assertSame($notificationCount + 1, Notification::count());
        $this->assertSame($followerNotificationCount + 1, $follower->userNotifications()->count());
    }

    public function testDestroy()
    {
        $owner = User::factory()->create();
        $beatmapset = Beatmapset::factory()->create([
            'approved' => Beatmapset::STATES['pending'],
            'user_id' => $owner,
        ]);

        $banchoBotUser = User::factory()->create([
            'user_id' => config('osu.legacy.bancho_bot_user_id'),
        ]);

        $url = route('interop.beatmapsets.destroy', [
{'fraction_non_alphanumeric': 0.1680327868852459, 'fraction_numerical': 0.0022354694485842027, 'mean_word_length': 2.930453879941435, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5040924', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1490, 'n_words': 271}