Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions tests/BeatmapsetDisqualifyNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ public function testNotificationSentIfWatching()

$this->runFakeQueue();

Event::assertDispatched(NewPrivateNotificationEvent::class, function (NewPrivateNotificationEvent $event) {
return $event->notification->name === Notification::BEATMAPSET_DISQUALIFY
&& $this->inReceivers($this->user, $event);
});
Event::assertDispatched(NewPrivateNotificationEvent::class, fn (NewPrivateNotificationEvent $event) =>
$event->notification->name === Notification::BEATMAPSET_DISQUALIFY && $this->receiversInclude($event, $this->user));
}

/**
Expand All @@ -84,19 +82,16 @@ public function testNotificationSentWithPushNotificationDeliveryOption($pushEnab

$this->runFakeQueue();

Event::assertDispatched(NewPrivateNotificationEvent::class, function (NewPrivateNotificationEvent $event) {
return $event->notification->name === Notification::BEATMAPSET_DISQUALIFY
&& $this->inReceivers($this->user, $event);
});
Event::assertDispatched(NewPrivateNotificationEvent::class, fn (NewPrivateNotificationEvent $event) =>
$event->notification->name === Notification::BEATMAPSET_DISQUALIFY && $this->receiversInclude($event, $this->user));
} else {
// We want to assert the job was queued but because there should be no receivers, there won't be a notification generated.
Queue::assertPushed(BeatmapsetDisqualify::class);

$this->runFakeQueue();

Event::assertNotDispatched(NewPrivateNotificationEvent::class, function (NewPrivateNotificationEvent $event) {
return $event->notification->name === Notification::BEATMAPSET_DISQUALIFY;
});
Event::assertNotDispatched(NewPrivateNotificationEvent::class, fn (NewPrivateNotificationEvent $event) =>
$event->notification->name === Notification::BEATMAPSET_DISQUALIFY);
}
}

Expand All @@ -110,10 +105,8 @@ public function testNotificationSentIfNotificationOptionsEnabled()

$this->runFakeQueue();

Event::assertDispatched(NewPrivateNotificationEvent::class, function (NewPrivateNotificationEvent $event) {
return $event->notification->name === Notification::BEATMAPSET_DISQUALIFY
&& $this->inReceivers($this->user, $event);
});
Event::assertDispatched(NewPrivateNotificationEvent::class, fn (NewPrivateNotificationEvent $event) =>
$event->notification->name === Notification::BEATMAPSET_DISQUALIFY && $this->receiversInclude($event, $this->user));
}

public function testNotificationNotSentIfNotificationOptionsNotEnabled()
Expand Down
12 changes: 3 additions & 9 deletions tests/Libraries/BeatmapsetDiscussion/DiscussionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,15 @@ public function testWatchersGetNotification()

Queue::assertPushed(
BeatmapsetDiscussionPostNew::class,
fn (BeatmapsetDiscussionPostNew $job) => (
$this->inReceivers($watcher, $job)
&& !$this->inReceivers($user, $job)
)
fn (BeatmapsetDiscussionPostNew $job) => $this->receiversInclude($job, $watcher, $user)
);

$this->runFakeQueue();

// TODO: this should probably be changed to asserting "if job queued, then event is broadcast to receivers with option set"
Event::assertDispatched(
NewPrivateNotificationEvent::class,
fn (NewPrivateNotificationEvent $event) => (
$this->inReceivers($watcher, $event)
&& !$this->inReceivers($user, $event)
)
fn (NewPrivateNotificationEvent $event) => $this->receiversInclude($event, $watcher, $user)
);
}

Expand Down Expand Up @@ -275,7 +269,7 @@ public function testProblemOnQualifiedBeatmapsetModesNotification(string $mode,
if ($expectsNotification) {
Event::assertDispatched(
NewPrivateNotificationEvent::class,
fn (NewPrivateNotificationEvent $event) => $this->inReceivers($watcher, $event)
fn (NewPrivateNotificationEvent $event) => $this->receiversInclude($event, $watcher)
);
} else {
Event::assertNotDispatched(NewPrivateNotificationEvent::class);
Expand Down
197 changes: 97 additions & 100 deletions tests/Libraries/BeatmapsetDiscussion/ReplyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
use App\Models\BeatmapDiscussion;
use App\Models\BeatmapDiscussionPost;
use App\Models\Beatmapset;
use App\Models\Notification;
use App\Models\User;
use App\Models\UserNotificationOption;
use Event;
use PHPUnit\Framework\Attributes\DataProvider;
use Queue;
use Tests\TestCase;

Expand All @@ -29,10 +32,84 @@ class ReplyTest extends TestCase

private User $mapper;

public function testWatchersGetNotification()
public static function dataProviderForReopeningProblemDoesNotDisqualifyOrResetNominations(): array
{
return [
['bng', 'pending'],
['bng', 'qualified'],
['bng_limited', 'pending'],
['bng_limited', 'qualified'],
[null, 'pending'],
[null, 'qualified'],
];
}

public static function dataProviderForReplyQueuesNotificationToStarter(): array
{
return [
['praise', false],
['problem', true],
['suggestion', true],
];
}

public static function dataProviderForResolveDiscussionByStarter(): array
{
return [
['praise', false],
['problem', true],
['suggestion', true],
];
}

public static function dataProviderForResolveDiscussionByMapper(): array
{
return [
['pending', true],
['qualified', false],
];
}

public static function dataProviderForResolveDiscussionByOtherUsers(): array
{
return [
['bng', false],
['bng_limited', false],
['gmt', true],
['nat', true],
[null, false],
];
}

public static function dataProviderForUserGroups(): array
{
return [
['admin'],
['bng'],
['bng_limited'],
['gmt'],
['nat'],
[null],
];
}

public static function dataProviderForWatchersGetNotification(): array
{
return [
[true],
[false],
];
}

#[DataProvider('dataProviderForWatchersGetNotification')]
public function testWatchersGetNotification(bool $push)
{
$user = User::factory()->create()->markSessionVerified();
$watcher = User::factory()->create();
$watcher->notificationOptions()->create([
'name' => UserNotificationOption::BEATMAPSET_MODDING,
'details' => ['push' => $push],
]);
$discussion = BeatmapDiscussion::factory()
->general()
->for($this->beatmapsetFactory())
Expand All @@ -44,27 +121,24 @@ public function testWatchersGetNotification()

Queue::assertPushed(
BeatmapsetDiscussionPostNew::class,
fn (BeatmapsetDiscussionPostNew $job) => (
$this->inReceivers($watcher, $job)
&& !$this->inReceivers($user, $job)
)
fn (BeatmapsetDiscussionPostNew $job) => $this->receiversInclude($job, [$this->mapper, $watcher], $user)
);

$this->runFakeQueue();

// TODO: this should probably be changed to asserting "if job queued, then event is broadcast to receivers with option set"
$includes = $push
? ['excludes' => $user, 'includes' => [$this->mapper, $watcher]]
: ['excludes' => [$watcher, $user], 'includes' => $this->mapper];

Event::assertDispatched(
NewPrivateNotificationEvent::class,
fn (NewPrivateNotificationEvent $event) => (
$this->inReceivers($watcher, $event)
&& !$this->inReceivers($user, $event)
)
fn (NewPrivateNotificationEvent $event) =>
$event->notification->name === Notification::BEATMAPSET_DISCUSSION_POST_NEW
&& $this->receiversInclude($event, ...$includes)
);
}

/**
* @dataProvider replyQueuesNotificationDataProviderToStarter
*/
#[DataProvider('dataProviderForReplyQueuesNotificationToStarter')]
public function testReplyQueuesNotificationToStarter(string $messageType, bool $includeStarter)
{
$user = User::factory()->create()->markSessionVerified();
Expand All @@ -82,15 +156,13 @@ public function testReplyQueuesNotificationToStarter(string $messageType, bool $
BeatmapsetDiscussionPostNew::class,
fn (BeatmapsetDiscussionPostNew $job) => (
$includeStarter
? $this->inReceivers($starter, $job)
: !$this->inReceivers($starter, $job)
? $this->receiversInclude($job, $starter)
: $this->receiversInclude($job, excludes: $starter)
)
);
}

/**
* @dataProvider userGroupsDataProvider
*/
#[DataProvider('dataProviderForUserGroups')]
public function testReplyResolvedDiscussion(?string $group)
{
$user = User::factory()->withGroup($group)->create()->markSessionVerified();
Expand All @@ -109,9 +181,7 @@ public function testReplyResolvedDiscussion(?string $group)
$this->assertTrue($discussion->fresh()->resolved);
}

/**
* @dataProvider userGroupsDataProvider
*/
#[DataProvider('dataProviderForUserGroups')]
public function testReplyUnresolvedDiscussion(?string $group)
{
$user = User::factory()->withGroup($group)->create()->markSessionVerified();
Expand All @@ -130,9 +200,7 @@ public function testReplyUnresolvedDiscussion(?string $group)
$this->assertFalse($discussion->fresh()->resolved);
}

/**
* @dataProvider resolveDiscussionByStarterDataProvider
*/
#[DataProvider('dataProviderForResolveDiscussionByStarter')]
public function testResolveDiscussionByStarter(string $messageType, bool $expected)
{
$user = User::factory()->create()->markSessionVerified();
Expand All @@ -155,9 +223,7 @@ public function testResolveDiscussionByStarter(string $messageType, bool $expect
$this->assertCount(1, $this->getSystemPosts($posts, $discussion));
}

/**
* @dataProvider resolveDiscussionByMapperDataProvider
*/
#[DataProvider('dataProviderForResolveDiscussionByMapper')]
public function testResolveDiscussionByMapper(string $state, bool $expected)
{
$starter = User::factory()->create();
Expand All @@ -179,9 +245,7 @@ public function testResolveDiscussionByMapper(string $state, bool $expected)
$this->assertCount(1, $this->getSystemPosts($posts, $discussion));
}

/**
* @dataProvider resolveDiscussionByMapperDataProvider
*/
#[DataProvider('dataProviderForResolveDiscussionByMapper')]
public function testResolveDiscussionByGuestMapper(string $state, bool $expected)
{
$user = User::factory()->create()->markSessionVerified();
Expand All @@ -206,9 +270,7 @@ public function testResolveDiscussionByGuestMapper(string $state, bool $expected
$this->assertCount(1, $this->getSystemPosts($posts, $discussion));
}

/**
* @dataProvider resolveDiscussionByOtherUsersDataProvider
*/
#[DataProvider('dataProviderForResolveDiscussionByOtherUsers')]
public function testResolveDiscussionByOtherUsers(?string $group, bool $expected)
{
$user = User::factory()->withGroup($group)->create()->markSessionVerified();
Expand All @@ -230,9 +292,7 @@ public function testResolveDiscussionByOtherUsers(?string $group, bool $expected
$this->assertCount(1, $this->getSystemPosts($posts, $discussion));
}

/**
* @dataProvider reopeningProblemDoesNotDisqualifyOrResetNominationsDataProvider
*/
#[DataProvider('dataProviderForReopeningProblemDoesNotDisqualifyOrResetNominations')]
public function testReopeningProblemDoesNotDisqualifyOrResetNominations(?string $group, string $state)
{
$user = User::factory()->withGroup($group)->create()->markSessionVerified();
Expand Down Expand Up @@ -300,9 +360,7 @@ public function testReopenResolvedDiscussionByStarter()
$this->assertCount(1, $this->getSystemPosts($posts, $discussion));
}

/**
* @dataProvider userGroupsDataProvider
*/
#[DataProvider('dataProviderForUserGroups')]
public function testReplyToMapperNoteByOtherUsers(?string $group)
{
$user = User::factory()->withGroup($group)->create()->markSessionVerified();
Expand Down Expand Up @@ -341,67 +399,6 @@ public function testRequestingSameResolveStateDoesNotChangeResovled()
$this->assertFalse($discussion->fresh()->resolved);
}

public static function reopeningProblemDoesNotDisqualifyOrResetNominationsDataProvider()
{
return [
['bng', 'pending'],
['bng', 'qualified'],
['bng_limited', 'pending'],
['bng_limited', 'qualified'],
[null, 'pending'],
[null, 'qualified'],
];
}

public static function replyQueuesNotificationDataProviderToStarter()
{
return [
['praise', false],
['problem', true],
['suggestion', true],
];
}

public static function resolveDiscussionByStarterDataProvider()
{
return [
['praise', false],
['problem', true],
['suggestion', true],
];
}

public static function resolveDiscussionByMapperDataProvider()
{
return [
['pending', true],
['qualified', false],
];
}

public static function resolveDiscussionByOtherUsersDataProvider()
{
return [
['bng', false],
['bng_limited', false],
['gmt', true],
['nat', true],
[null, false],
];
}

public static function userGroupsDataProvider()
{
return [
['admin'],
['bng'],
['bng_limited'],
['gmt'],
['nat'],
[null],
];
}

protected function setUp(): void
{
parent::setUp();
Expand Down
Loading