Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoguenet committed Mar 10, 2024
1 parent cd4c87f commit 85ee5a1
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
41 changes: 40 additions & 1 deletion tests/Http/Admin/EditNudgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,43 @@

declare(strict_types=1);

it('can edit a nudge')->todo();
use App\Models\User;
use App\Models\Nudge;

use Illuminate\Support\Str;
use function Pest\Laravel\actingAs;

it('can edit a nudge', function () {
$admin = User::factory()->admin()->create();
$nudge = Nudge::factory()->create();

$title = Str::random();
$slug = Str::slug($title);
$content = Str::random();
$code = Str::random();

actingAs($admin)
->put(route('admin.nudges.update', $nudge), [
'title' => $title,
'content' => $content,
'code' => $code,
])
->assertRedirect();

$nudge->refresh();

expect($nudge->title)->toBe($title);
expect($nudge->slug)->toBe($slug);
expect($nudge->content)->toBe($content);
expect($nudge->code)->toBe($code);
});

it('can not edit a nudge', function () {
$admin = User::factory()->admin()->create();
$nudge = Nudge::factory()->create();

actingAs($admin)
->put(route('admin.nudges.update', $nudge))
->assertRedirect()
->assertSessionHasErrors();
});
46 changes: 45 additions & 1 deletion tests/Http/Nudge/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,48 @@

declare(strict_types=1);

it('can create a nudge')->todo();
use App\Models\Nudge;
use App\Models\User;

use Illuminate\Support\Str;
use function Pest\Laravel\actingAs;
use function Pest\Laravel\assertDatabaseCount;

it('can create a nudge', function () {
$user = User::factory()->create();

$title = Str::random();
$slug = Str::slug($title);
$content = Str::random();
$code = Str::random();

actingAs($user)
->post(route('nudges.store'), [
'title' => $title,
'content' => $content,
'code' => $code,
])
->assertRedirect();

assertDatabaseCount('nudges', 1);

$nudge = Nudge::first();

expect($nudge->title)->toBe($title);
expect($nudge->slug)->toBe($slug);
expect($nudge->content)->toBe($content);
expect($nudge->code)->toBe($code);
expect($nudge->validated)->toBeFalse;
expect($nudge->user_id)->toBe($user->id);
});

it('can not create a nudge', function () {
$user = User::factory()->create();

actingAs($user)
->post(route('nudges.store'))
->assertRedirect()
->assertSessionHasErrors();

assertDatabaseCount('nudges', 0);
});
2 changes: 0 additions & 2 deletions tests/Http/Nudge/OrderByTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

it('can search')->todo();

it('can see nudges displayed and sorted properly', function () {
// test('can see posts sorted by title', function (string $direction) {
// $posts = Post::factory(3)
Expand Down

0 comments on commit 85ee5a1

Please sign in to comment.