Skip to content

Commit

Permalink
Test a post requiring valid data
Browse files Browse the repository at this point in the history
  • Loading branch information
unclexo committed Dec 14, 2022
1 parent 01ea641 commit ac801e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/Http/Requests/PostRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function authorize()
public function rules()
{
return [
'title' => '',
'description' => ''
'title' => ['required', 'string'],
'description' => ['required', 'min:10'],
];
}
}
23 changes: 23 additions & 0 deletions tests/Feature/PostModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,27 @@ public function users_can_view_their_own_posts()
->assertSee($post->title)
->assertSee($post->description);
}

/** @test */
public function a_post_requires_valid_data()
{
$this->actingAs(User::factory()->create());

$attributes = Post::factory()->raw([
'title' => '',
'description' => '',
]);

$this->post(route('posts.store'), $attributes)
->assertSessionHasErrors(['title', 'description']);


$attributes2 = Post::factory()->raw([
'title' => 12345,
'description' => 'hello',
]);

$this->post(route('posts.store'), $attributes2)
->assertSessionHasErrors(['title', 'description']);
}
}

0 comments on commit ac801e2

Please sign in to comment.