Skip to content

Commit

Permalink
Adds TagsController@destroy test
Browse files Browse the repository at this point in the history
  • Loading branch information
syropian committed Mar 10, 2024
1 parent ad37e2d commit c14a5b1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/Feature/Controllers/TagsController/DestroyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

use App\Models\Tag;

it('redirects guests to the login page')
->delete('/tags/1')
->assertRedirect('/login');

it('deletes a tag', function () {
$this->login();

$tag = Tag::factory()->create(['name' => 'TypeScript', 'user_id' => auth()->id()]);

$this
->delete(route('tags.destroy', $tag))
->assertRedirect(route('dashboard.show'));

$this->assertDatabaseMissing('tags', ['id' => $tag->id]);
});

it('automatically scopes the bound tag in the request to the authenticated user', function () {
$tag = Tag::factory()->create();

$this->login();

$this
->delete(route('tags.destroy', $tag))
->assertNotFound();

$this->assertDatabaseHas('tags', ['id' => $tag->id]);
});

0 comments on commit c14a5b1

Please sign in to comment.