Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 9 additions & 5 deletions app/Http/Controllers/WikisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ class WikisController extends Controller
{
public function getWikisOwnedByCurrentUser(Request $request): \Illuminate\Http\Response
{
return response(
$request->user()
->managesWikis()
->get()
);
$wikis = $request->user()->managesWikis()->get();

return response(
[
"wikis" => $wikis,
"count" => count($wikis),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could argue that this is useless.

"limit" => config('wbstack.wiki_max_per_user')
]
);
}
}
34 changes: 34 additions & 0 deletions tests/Routes/Wiki/MineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,44 @@

use Tests\Routes\Traits\OptionsRequestAllowed;
use Tests\TestCase;
use App\User;
use Illuminate\Support\Facades\Config;
use App\Wiki;
use App\WikiManager;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class MineTest extends TestCase
{
protected $route = 'wiki/mine';

use OptionsRequestAllowed;
use DatabaseTransactions;

public function testMineDefault()
{
Config::set('wbstack.wiki_max_per_user', false);

$user = User::factory()->create(['verified' => true]);
$this->actingAs($user, 'api')
->json('POST', $this->route, [])
->assertStatus(200)
->assertJsonFragment([ "wikis" => [], "count" => 0, "limit" => false]);
}

public function testMineWithWikis()
{
Config::set('wbstack.wiki_max_per_user', 1);

$user = User::factory()->create(['verified' => true]);
$wiki = Wiki::factory()->create();
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);

$content = $this->actingAs($user, 'api')
->json('POST', $this->route, [])
->assertStatus(200)
->assertJson([ "wikis" => [], "count" => 1, "limit" => 1])->getContent();


$this->assertEquals( $wiki->id, json_decode($content)->wikis[0]->id );
}
}