Skip to content

Commit

Permalink
enable testing, test forum actor relation
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Jan 31, 2024
1 parent 1c2ba6f commit 91b75e8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
run:
uses: flarum/framework/.github/workflows/[email protected]
with:
enable_backend_testing: false
enable_backend_testing: true
enable_phpstan: true
php_versions: '["8.0", "8.1", "8.2", "8.3"]'

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
vendor
composer.lock
.phpunit.result.cache
5 changes: 5 additions & 0 deletions src/FollowState.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class FollowState extends AbstractModel

protected $fillable = ['user_id', 'followed_user_id', 'subscription', 'updated_at'];

protected $casts = [
'created_at' => 'datetime',
'updated_at' => 'datetime',
];

/**
* Get the follow user subscription state for the given User.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/SaveFollowedToDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function handle(Saving $event)
/**
* @param User $user
*
* @return BelongsToMany
* @return BelongsToMany<User>
*/
protected function followedUsers(User $user): BelongsToMany
{
Expand Down
55 changes: 55 additions & 0 deletions tests/integration/api/ForumRelationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace IanM\FollowUsers\Tests\integration\api;

use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;

class ForumRelationTest extends TestCase
{
use RetrievesAuthorizedUsers;

public function setUp(): void
{
parent::setUp();

$this->extension('ianm-follow-users');

$this->prepareDatabase([
'users' => [
$this->normalUser(),
],
]);
}

/**
* @test
*/
public function forum_actor_contains_followed_user_relations()
{
$response = $this->send(
$this->request(
'GET',
'/api',
[
'authenticatedAs' => 2,
]
)
);

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

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

$this->assertArrayHasKey('actor', $json['data']['relationships']);

$included = $json['included'];

$actorIndex = array_search('users', array_column($included, 'type'));
$actor = $included[$actorIndex];

$this->assertEquals(2, $actor['id']);
$this->assertArrayHasKey('followedUsers', $actor['relationships']);
$this->assertArrayHasKey('data', $actor['relationships']['followedUsers']);
}
}

0 comments on commit 91b75e8

Please sign in to comment.