Skip to content

Commit

Permalink
test: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideIadeluca committed Jan 24, 2025
1 parent d2c299e commit ba53bf0
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/integration/notifications/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function notification_sent_when_new_discussion_in_followed_tag()
$this->assertEquals(1, count($response['data']));
$this->assertEquals('newDiscussionInTag', $response['data'][0]['attributes']['contentType']);
$this->assertEquals(1, User::query()->find($notificationRecipient)->notifications()->count());
$this->assertEquals(1, Notification::query()->count());
$this->assertEquals(1, Notification::query()->first()->from_user_id);
$this->assertEquals(2, Notification::query()->first()->user_id);
}
Expand Down Expand Up @@ -199,6 +200,7 @@ public function notification_sent_when_new_discussion_in_lurked_tag()
$this->assertEquals(1, count($response['data']));
$this->assertEquals('newDiscussionInTag', $response['data'][0]['attributes']['contentType']);
$this->assertEquals(1, User::query()->find($notificationRecipient)->notifications()->count());
$this->assertEquals(1, Notification::query()->count());
$this->assertEquals(1, Notification::query()->first()->from_user_id);
$this->assertEquals(2, Notification::query()->first()->user_id);
}
Expand Down Expand Up @@ -255,6 +257,7 @@ public function notification_sent_when_new_post_in_lurked_tag()
$this->assertEquals(1, count($response['data']));
$this->assertEquals('newPostInTag', $response['data'][0]['attributes']['contentType']);
$this->assertEquals(1, User::query()->find($notificationRecipient)->notifications()->count());
$this->assertEquals(1, Notification::query()->count());
$this->assertEquals(1, Notification::query()->first()->from_user_id);
$this->assertEquals(2, Notification::query()->first()->user_id);
}
Expand Down Expand Up @@ -350,4 +353,92 @@ public function no_notification_sent_when_new_user_mention_in_ignored_tag()
$this->assertEquals(0, Notification::query()->count());

}

/**
* @test
*/
public function notification_sent_when_discussion_retagged_to_accessible_tag()
{
$response = $this->send(
$this->request('PATCH', '/api/discussions/1', [
'authenticatedAs' => 1,
'json' => [
'data' => [
'attributes' => [],
'relationships' => [
'tags' => [
'data' => [
['type' => 'tags', 'id' => 2]
]
]
]
],
],
])
);

$this->assertEquals(200, $response->getStatusCode());

$notificationRecipient = 2;

$response = $this->send(
$this->request('GET', '/api/notifications', [
'authenticatedAs' => $notificationRecipient,
])
);

$this->assertEquals(200, $response->getStatusCode());

$response = json_decode($response->getBody(), true);

$this->assertEquals(1, count($response['data']));
$this->assertEquals('newDiscussionTag', $response['data'][0]['attributes']['contentType']);

$this->assertEquals(1, User::query()->find($notificationRecipient)->notifications()->count());
$this->assertEquals(1, Notification::query()->count());
$this->assertEquals(1, Notification::query()->first()->from_user_id);
$this->assertEquals(2, Notification::query()->first()->user_id);
}

/**
* @test
*/
public function no_notification_sent_when_discussion_retagged_to_restricted_tag()
{
$response = $this->send(
$this->request('PATCH', '/api/discussions/1', [
'authenticatedAs' => 1,
'json' => [
'data' => [
'attributes' => [],
'relationships' => [
'tags' => [
'data' => [
['type' => 'tags', 'id' => 4]
]
]
]
],
],
])
);

$this->assertEquals(200, $response->getStatusCode());

$notificationRecipient = 2;

$response = $this->send(
$this->request('GET', '/api/notifications', [
'authenticatedAs' => $notificationRecipient,
])
);

$this->assertEquals(200, $response->getStatusCode());

$response = json_decode($response->getBody(), true);

$this->assertEquals(0, count($response['data']));
$this->assertEquals(0, User::query()->find($notificationRecipient)->notifications()->count());
$this->assertEquals(0, Notification::query()->count());
}
}

0 comments on commit ba53bf0

Please sign in to comment.