tests: Add tests for Bookmark and Category controllers

This commit is contained in:
Ben Johnson
2020-02-28 20:31:14 -05:00
parent 57212ca263
commit e80eef5ae1
4 changed files with 119 additions and 131 deletions
@@ -0,0 +1,69 @@
<?php
namespace Tests\Feature\Http\Controllers;
use App\Models\Bookmark;
use App\Models\User;
use GroupsTableSeeder;
use Tests\TestCase;
/**
* @see \App\Http\Controllers\BookmarkController
*/
class BookmarkControllerTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->seed(GroupsTableSeeder::class);
}
/** @test */
public function destroy_returns_an_ok_response()
{
$user = factory(User::class)->create();
$bookmark = factory(Bookmark::class)->create([
'user_id' => $user->id,
]);
$response = $this->actingAs($user)->delete(route('bookmarks.destroy', ['id' => $bookmark->torrent_id]));
$response->assertRedirect(route('torrent', ['id' => $bookmark->torrent_id]))
->assertSessionHas('success', 'Torrent Has Been Unbookmarked Successfully!');
}
/** @test */
public function index_returns_an_ok_response()
{
$user = factory(User::class)->create();
factory(Bookmark::class)->create([
'user_id' => $user->id,
]);
$response = $this->actingAs($user)->get(route('bookmarks.index', ['username' => $user->username]));
$response->assertOk()
->assertViewIs('user.bookmarks')
->assertViewHas('user')
->assertViewHas('personal_freeleech')
->assertViewHas('bookmarks')
->assertViewHas('route');
}
/** @test */
public function store_returns_an_ok_response()
{
$user = factory(User::class)->create();
$bookmark = factory(Bookmark::class)->make([
'user_id' => $user->id,
]);
$this->actingAs($user)->post(route('bookmarks.store', ['id' => $bookmark->torrent_id]))
->assertRedirect(route('torrent', ['id' => $bookmark->torrent_id]))
->assertSessionHas('success', 'Torrent Has Been Bookmarked Successfully!');
}
}
@@ -0,0 +1,50 @@
<?php
namespace Tests\Feature\Http\Controllers;
use App\Models\Category;
use App\Models\User;
use GroupsTableSeeder;
use Tests\TestCase;
/**
* @see \App\Http\Controllers\CategoryController
*/
class CategoryControllerTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->seed(GroupsTableSeeder::class);
}
/** @test */
public function index_returns_an_ok_response()
{
$user = factory(User::class)->create();
$response = $this->actingAs($user)->get(route('categories.index'));
$response->assertOk()
->assertViewIs('category.index')
->assertViewHas('categories');
}
/** @test */
public function show_returns_an_ok_response()
{
$category = factory(Category::class)->create();
$user = factory(User::class)->create();
$response = $this->actingAs($user)->get(route('categories.show', ['id' => $category->id]));
$response->assertOk()
->assertViewIs('category.show')
->assertViewHas('torrents')
->assertViewHas('user')
->assertViewHas('category')
->assertViewHas('personal_freeleech');
}
}
@@ -1,75 +0,0 @@
<?php
namespace Tests\Feature\Http\Controllers;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
/**
* @see \App\Http\Controllers\BookmarkController
*/
class BookmarkControllerTest extends TestCase
{
use RefreshDatabase;
/**
* @test
*/
public function destroy_returns_an_ok_response()
{
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
$bookmark = factory(\App\Models\Bookmark::class)->create();
$user = factory(\App\Models\User::class)->create();
$response = $this->actingAs($user)->delete(route('bookmarks.destroy', ['id' => $bookmark->id]));
$response->assertRedirect(withSuccess('Torrent Has Been Unbookmarked Successfully!'));
$this->assertDeleted($bookmarks);
// TODO: perform additional assertions
}
/**
* @test
*/
public function index_returns_an_ok_response()
{
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
$bookmark = factory(\App\Models\Bookmark::class)->create();
$user = factory(\App\Models\User::class)->create();
$response = $this->actingAs($user)->get(route('bookmarks.index', ['username' => $bookmark->username]));
$response->assertOk();
$response->assertViewIs('user.bookmarks');
$response->assertViewHas('user');
$response->assertViewHas('personal_freeleech');
$response->assertViewHas('bookmarks');
$response->assertViewHas('route');
// TODO: perform additional assertions
}
/**
* @test
*/
public function store_returns_an_ok_response()
{
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
$bookmark = factory(\App\Models\Bookmark::class)->create();
$user = factory(\App\Models\User::class)->create();
$response = $this->actingAs($user)->post(route('bookmarks.store', ['id' => $bookmark->id]), [
// TODO: send request data
]);
$response->assertRedirect(withErrors('Torrent has already been bookmarked.'));
// TODO: perform additional assertions
}
// test cases...
}
@@ -1,56 +0,0 @@
<?php
namespace Tests\Feature\Http\Controllers;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
/**
* @see \App\Http\Controllers\CategoryController
*/
class CategoryControllerTest extends TestCase
{
use RefreshDatabase;
/**
* @test
*/
public function index_returns_an_ok_response()
{
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
$user = factory(\App\Models\User::class)->create();
$response = $this->actingAs($user)->get(route('categories.index'));
$response->assertOk();
$response->assertViewIs('category.index');
$response->assertViewHas('categories');
// TODO: perform additional assertions
}
/**
* @test
*/
public function show_returns_an_ok_response()
{
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');
$category = factory(\App\Models\Category::class)->create();
$user = factory(\App\Models\User::class)->create();
$response = $this->actingAs($user)->get(route('categories.show', ['id' => $category->id]));
$response->assertOk();
$response->assertViewIs('category.show');
$response->assertViewHas('torrents');
$response->assertViewHas('user');
$response->assertViewHas('category');
$response->assertViewHas('personal_freeleech');
// TODO: perform additional assertions
}
// test cases...
}