diff --git a/src/Api/Controller/ListPostReactionsController.php b/src/Api/Controller/ListPostReactionsController.php
index f38962f..f8996a4 100644
--- a/src/Api/Controller/ListPostReactionsController.php
+++ b/src/Api/Controller/ListPostReactionsController.php
@@ -26,9 +26,9 @@ class ListPostReactionsController extends AbstractListController
{
public $serializer = PostReactionSerializer::class;
- public $include = ['reaction'];
+ public $include = ['reaction', 'user'];
- public $optionalInclude = ['user', 'post'];
+ public $optionalInclude = ['post'];
/**
* @var PostRepository
diff --git a/tests/integration/api/ListPostReactionsTest.php b/tests/integration/api/ListPostReactionsTest.php
new file mode 100644
index 0000000..a38ed6f
--- /dev/null
+++ b/tests/integration/api/ListPostReactionsTest.php
@@ -0,0 +1,114 @@
+extension('fof-reactions');
+
+ $this->prepareDatabase([
+ 'users' => [
+ $this->normalUser(),
+ ['id' => 3, 'username' => 'Acme', 'email' => 'acme@machine.local', 'is_email_confirmed' => 1],
+ ['id' => 4, 'username' => 'Acme2', 'email' => 'acme2@machine.local', 'is_email_confirmed' => 1],
+ ['id' => 5, 'username' => 'Acme3', 'email' => 'acme3@machine.local', 'is_email_confirmed' => 1],
+ ['id' => 6, 'username' => 'Acme4', 'email' => 'acme4@machine.local', 'is_email_confirmed' => 1],
+ ],
+ 'discussions' => [
+ ['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 2],
+ ],
+ 'posts' => [
+ ['id' => 1, 'number' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'something
'],
+ ['id' => 3, 'number' => 2, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 2, 'type' => 'comment', 'content' => 'something
'],
+ ['id' => 5, 'number' => 3, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 3, 'type' => 'discussionRenamed', 'content' => 'something
'],
+ ['id' => 6, 'number' => 4, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 1, 'type' => 'comment', 'content' => 'something
'],
+ ['id' => 6, 'number' => 4, 'discussion_id' => 1, 'created_at' => Carbon::now(), 'user_id' => 5, 'type' => 'comment', 'content' => 'something
'],
+ ],
+ 'post_reactions' => [
+ ['id' => 1, 'post_id' => 1, 'reaction_id' => 1, 'user_id' => 2],
+ ['id' => 2, 'post_id' => 1, 'reaction_id' => 1, 'user_id' => 3],
+ ['id' => 3, 'post_id' => 1, 'reaction_id' => 2, 'user_id' => 4],
+ ['id' => 4, 'post_id' => 1, 'reaction_id' => 4, 'user_id' => 5],
+ ['id' => 5, 'post_id' => 1, 'reaction_id' => null, 'user_id' => 6],
+ ],
+ 'post_anonymous_reactions' => [
+ ['id' => 1, 'post_id' => 1, 'reaction_id' => 1, 'guest_id' => '1234567'],
+ ['id' => 2, 'post_id' => 1, 'reaction_id' => 1, 'guest_id' => 'abfdb'],
+ ['id' => 3, 'post_id' => 1, 'reaction_id' => 1, 'guest_id' => '123098'],
+ ['id' => 4, 'post_id' => 1, 'reaction_id' => 1, 'guest_id' => 'gd'],
+ ['id' => 5, 'post_id' => 1, 'reaction_id' => null, 'guest_id' => 'gsadasdd'],
+ ],
+ ]);
+ }
+
+ /**
+ * @test
+ */
+ public function guest_can_see_reactions_on_a_post_when_guest_reacting_is_off()
+ {
+ $response = $this->send(
+ $this->request('GET', '/api/posts/1/reactions', [
+ ])
+ );
+
+ $this->assertEquals(200, $response->getStatusCode());
+
+ $response = json_decode($response->getBody()->getContents(), true);
+
+ $this->assertEquals(4, count($response['data']));
+
+ $this->assertEquals(1, $response['data'][0]['attributes']['reactionId']);
+ $this->assertEquals(1, $response['data'][1]['attributes']['reactionId']);
+ $this->assertEquals(2, $response['data'][2]['attributes']['reactionId']);
+ $this->assertEquals(4, $response['data'][3]['attributes']['reactionId']);
+
+ $this->assertEquals(2, $response['data'][0]['attributes']['userId']);
+ $this->assertEquals(3, $response['data'][1]['attributes']['userId']);
+ $this->assertEquals(4, $response['data'][2]['attributes']['userId']);
+ $this->assertEquals(5, $response['data'][3]['attributes']['userId']);
+
+ $this->assertEquals(1, $response['data'][0]['attributes']['postId']);
+ $this->assertEquals(1, $response['data'][1]['attributes']['postId']);
+ $this->assertEquals(1, $response['data'][2]['attributes']['postId']);
+ $this->assertEquals(1, $response['data'][3]['attributes']['postId']);
+
+ $this->assertEquals('reactions', $response['data'][0]['relationships']['reaction']['data']['type']);
+ $this->assertEquals('reactions', $response['data'][1]['relationships']['reaction']['data']['type']);
+ $this->assertEquals('reactions', $response['data'][2]['relationships']['reaction']['data']['type']);
+ $this->assertEquals('reactions', $response['data'][3]['relationships']['reaction']['data']['type']);
+
+ $this->assertEquals('users', $response['data'][0]['relationships']['user']['data']['type']);
+ $this->assertEquals('users', $response['data'][1]['relationships']['user']['data']['type']);
+ $this->assertEquals('users', $response['data'][2]['relationships']['user']['data']['type']);
+ $this->assertEquals('users', $response['data'][3]['relationships']['user']['data']['type']);
+ }
+
+ /**
+ * @test
+ */
+ public function guest_can_see_reactions_on_a_post_when_guest_reacting_is_on()
+ {
+ $this->setting('fof-reactions.anonymousReactions', true);
+
+ $response = $this->send(
+ $this->request('GET', '/api/posts/1/reactions', [
+ ])
+ );
+
+ $this->assertEquals(200, $response->getStatusCode());
+
+ $response = json_decode($response->getBody()->getContents(), true);
+
+ $this->assertEquals(8, count($response['data']));
+ }
+}