clean tests & other things
This commit is contained in:
@@ -13,21 +13,12 @@ class MemosTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected $user;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->actingAs($user = factory(User::class)->create(), 'api');
|
||||
// $this->user = factory(User::class)->create();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_unauthenticated_user_should_redirect_to_login()
|
||||
{
|
||||
$response = $this->post('/api/memos', $this->data());
|
||||
|
||||
$this->assertGuest($guard = null);
|
||||
$response->assertRedirect('/login');
|
||||
$this->assertCount(0, Memo::all());
|
||||
}
|
||||
@@ -61,6 +52,7 @@ class MemosTest extends TestCase
|
||||
/** @test */
|
||||
public function memo_name_are_required()
|
||||
{
|
||||
$this->actingAs($user = factory(\App\User::class)->create(), 'api');
|
||||
$response = $this->post('/api/memos', array_merge($this->data(), ['name' => '']));
|
||||
|
||||
$response->assertSessionHasErrors('name');
|
||||
@@ -70,6 +62,7 @@ class MemosTest extends TestCase
|
||||
/** @test */
|
||||
public function memo_are_required()
|
||||
{
|
||||
$this->actingAs($user = factory(\App\User::class)->create(), 'api');
|
||||
$response = $this->post('/api/memos', array_merge($this->data(), ['memo' => '']));
|
||||
|
||||
$response->assertSessionHasErrors('memo');
|
||||
@@ -122,6 +115,7 @@ class MemosTest extends TestCase
|
||||
/** @test */
|
||||
public function only_the_owner_can_patch_the_memo()
|
||||
{
|
||||
$this->actingAs($user = factory(User::class)->create(), 'api');
|
||||
$memo = factory(Memo::class)->create();
|
||||
|
||||
$anotherUser = factory(User::class)->create();
|
||||
@@ -150,6 +144,7 @@ class MemosTest extends TestCase
|
||||
/** @test */
|
||||
public function only_the_owner_can_delete_the_memo()
|
||||
{
|
||||
$this->actingAs($user = factory(User::class)->create(), 'api');
|
||||
$memo = factory(Memo::class)->create();
|
||||
|
||||
$anotherUser = factory(User::class)->create();
|
||||
@@ -162,7 +157,7 @@ class MemosTest extends TestCase
|
||||
/** @test */
|
||||
public function a_list_of_memos_can_be_fetched_for_the_authenticated_user()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$this->actingAs($user = factory(User::class)->create(), 'api');
|
||||
$anotherUser = factory(User::class)->create();
|
||||
|
||||
$memo = factory(Memo::class)->create(['user_id' => $user->id]);
|
||||
@@ -185,18 +180,16 @@ class MemosTest extends TestCase
|
||||
/** @test */
|
||||
public function only_the_users_memos_can_be_retrieved()
|
||||
{
|
||||
$this->actingAs($user = factory(User::class)->create(), 'api');
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$memo = factory(Memo::class)->create(['user_id' => $user->id]);
|
||||
|
||||
$anotherUser = factory(User::class)->create();
|
||||
|
||||
$this->actingAs($anotherUser = factory(User::class)->create(), 'api');
|
||||
$response = $this->get('/api/memos/' . $memo->id );
|
||||
|
||||
$response->assertStatus(Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
// /** @test */
|
||||
// public function user_can_add_tag_to_memo()
|
||||
// {
|
||||
// //$this->withoutExceptionHandling();
|
||||
@@ -224,7 +217,7 @@ class MemosTest extends TestCase
|
||||
// );
|
||||
// }
|
||||
|
||||
/** @test */
|
||||
// /** @test */
|
||||
// public function user_can_remove_tag_to_memo()
|
||||
// {
|
||||
// //$this->withoutExceptionHandling();
|
||||
|
||||
@@ -59,4 +59,15 @@ class UserAuthTest extends TestCase
|
||||
|
||||
$this->assertCount(1, User::all());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_admin_can_fetch_all_users()
|
||||
{
|
||||
$this->actingAs($user = factory(User::class)->create(['role' => 2]), 'api');
|
||||
$anotherUser = factory(User::class)->create();
|
||||
|
||||
$response = $this->get('/api/users')->assertStatus(Response::HTTP_OK);
|
||||
|
||||
$this->assertCount(2, User::all());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user