-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2a294b
commit 0053bf6
Showing
9 changed files
with
248 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Faq; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends Factory<Faq> | ||
*/ | ||
class FaqFactory extends Factory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
"question" => fake()->sentence(), | ||
"answer" => fake()->realText(), | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\Models\Faq; | ||
use App\Models\User; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Str; | ||
use Tests\TestCase; | ||
|
||
class FaqTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->user = User::factory()->create(); | ||
$this->actingAs($this->user); | ||
} | ||
|
||
public function testFaqCanBeCreated(): void | ||
{ | ||
$this->assertDatabaseCount("faqs", 0); | ||
|
||
$this->post("/dashboard/faqs", [ | ||
"question" => "Example question ?", | ||
"answer" => "Content of the wiki", | ||
])->assertSessionHasNoErrors(); | ||
|
||
$this->assertDatabaseCount("faqs", 1); | ||
} | ||
|
||
public function testFaqCanBeUpdated(): void | ||
{ | ||
$faq = Faq::factory()->create(); | ||
|
||
$this->assertDatabaseMissing("faqs", [ | ||
"question" => "Example question ?", | ||
"answer" => "Content of the wiki", | ||
]); | ||
|
||
$this->patch("/dashboard/faqs/{$faq->id}", [ | ||
"question" => "Example question ?", | ||
"answer" => "Content of the wiki", | ||
])->assertSessionHasNoErrors(); | ||
|
||
$this->assertDatabaseHas("faqs", [ | ||
"question" => "Example question ?", | ||
"answer" => "Content of the wiki", | ||
]); | ||
} | ||
|
||
public function testSemesterCannotBeCreatedWithInvalidData(): void | ||
{ | ||
$this->post("/dashboard/faqs", [ | ||
"question" => Str::random(256), | ||
])->assertSessionHasErrors([ | ||
"question", | ||
]); | ||
|
||
$this->assertDatabaseCount("faqs", 0); | ||
} | ||
|
||
public function testFaqCanBeDeleted(): void | ||
{ | ||
$faq = Faq::factory()->create(); | ||
$this->assertDatabaseCount("faqs", 1); | ||
|
||
$this->delete("/dashboard/faqs/$faq->id"); | ||
$this->assertDatabaseCount("faqs", 0); | ||
|
||
} | ||
} |