retrofairie/tests/Feature/CategoryTest.php
2025-02-23 21:14:39 -08:00

70 lines
2 KiB
PHP

<?php
use App\Http\Controllers\CategoryController;
use App\Models\Category;
use App\Models\User;
covers(CategoryController::class);
test('guests can view category index', function () {
$response = $this->get(route('categories.index'));
$response->assertOk();
});
test('logged in users can view category index', function () {
$user = User::factory()->create();
$response = $this->actingAs($user)->get(route('categories.index'));
$response->assertOk();
});
test('categories.index request contains categories', function () {
$response = $this->get(route('categories.index'));
$response->assertViewHas('categories', Category::all());
expect($response['categories'])
->toBeEloquentCollection()
->toContainOnlyInstancesOf(Category::class);
});
test('categories.index request contains trashedCategories', function () {
$response = $this->get(route('categories.index'));
$response
->assertViewHas('trashedCategories', Category::onlyTrashed()->get());
expect($response['categories'])
->toBeEloquentCollection()
->toContainOnlyInstancesOf(Category::class);
});
test('guests can view categories', function () {
$category = Category::factory()->create();
$response = $this->get(route('categories.show', $category));
$response->assertOk();
});
test('logged in users can view categories', function () {
$user = User::factory()->create();
$category = Category::factory()->create();
$response = $this
->actingAs($user)
->get(route('categories.show', $category));
$response->assertOk();
});
test('categories.show contains the category', function () {
$category = Category::factory()->create();
$response = $this->get(route('categories.show', $category));
$response->assertViewHas('category', $category);
});
test('categories.show can show trashed categories', function () {
$category = Category::factory()->trashed()->create();
$response = $this->get(route('categories.show', $category));
$response->assertViewHas('category', $category);
});